Commit Graph

267 Commits

Author SHA1 Message Date
Reka Kovacs fa5373bdfb [analyzer] InnerPointerChecker: improve warning messages and notes.
Differential Revision: https://reviews.llvm.org/D49570

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339489 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-10 23:56:57 +00:00
Reka Kovacs 4f8b5a9f29 [analyzer] InnerPointerChecker: fix displayed checker name.
For InnerPointerChecker to function properly, both the checker itself
and parts of MallocChecker that handle relevant use-after-free problems
need to be turned on. So far, the latter part has been developed within
MallocChecker's NewDelete sub-checker, often causing warnings to appear
under that name. This patch defines a new CheckKind within MallocChecker
for the inner pointer checking functionality, so that the correct name
is displayed in warnings and in the ExplodedGraph.

Tested on clang-tidy.

Differential Review: https://reviews.llvm.org/D50211

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339067 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-06 22:03:42 +00:00
Reka Kovacs bdd41df411 [analyzer] Detect pointers escaped after ReturnStmt execution in MallocChecker.
Objects local to a function are destroyed right after the statement returning
(part of) them is executed in the analyzer. This patch enables MallocChecker to
warn in these cases.

Differential Revision: https://reviews.llvm.org/D49361

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338780 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-02 23:02:08 +00:00
Fangrui Song abdbb605f2 Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338291 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 19:24:48 +00:00
Reka Kovacs c4f64d0f6e [analyzer] Add support for more invalidating functions in InnerPointerChecker.
According to the standard, pointers referring to the elements of a
`basic_string` may be invalidated if they are used as an argument to
any standard library function taking a reference to non-const
`basic_string` as an argument. This patch makes InnerPointerChecker warn
for these cases.

Differential Revision: https://reviews.llvm.org/D49656

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338259 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 15:43:45 +00:00
Reka Kovacs b400322f6c [analyzer] Rename DanglingInternalBufferChecker to InnerPointerChecker.
Differential Revision: https://reviews.llvm.org/D49553

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337559 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-20 15:14:49 +00:00
Reka Kovacs 77c4e2380a [analyzer] Fix memory sanitizer error in MallocChecker.
StringRef's data() returns a string that may be non-null-terminated.
Switch to using StringRefs from const char pointers in visitor notes
to avoid problems.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337474 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-19 17:43:09 +00:00
Reka Kovacs 9934e6ea14 [analyzer] Fix disappearing notes in DanglingInternalBufferChecker tests
Correct a mistake of the exact same kind I am writing this checker for.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337466 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-19 15:44:46 +00:00
Reka Kovacs aa1e260245 [analyzer] Add support for more basic_string API in
DanglingInternalBufferChecker.

A pointer referring to the elements of a basic_string may be invalidated
by calling a non-const member function, except operator[], at, front,
back, begin, rbegin, end, and rend. The checker now warns if the pointer
is used after such operations.

Differential Revision: https://reviews.llvm.org/D49360

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337463 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-19 15:10:06 +00:00
Reka Kovacs ffbe9fa4c0 [analyzer] Highlight c_str() call in DanglingInternalBufferChecker.
Add a bug visitor to DanglingInternalBufferChecker that places a note
at the point where the dangling pointer was obtained. The visitor is
handed over to MallocChecker and attached to the report there.

Differential Revision: https://reviews.llvm.org/D48522

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336495 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-07 19:27:18 +00:00
Reka Kovacs a8cfadd9a9 [analyzer] Fix -Wcovered-switch-default warning in MallocChecker.
Remove unnecessary default case that caused buildbot failures.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336493 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-07 18:37:37 +00:00
Reka Kovacs 9f82dc375b [analyzer] Highlight container object destruction in MallocChecker.
Extend MallocBugVisitor to place a note at the point where objects with
AF_InternalBuffer allocation family are destroyed.

Differential Revision: https://reviews.llvm.org/D48521

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336489 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-07 17:22:45 +00:00
George Karpenkov 3387634751 [analyzer] [NFC] A convenient getter for getting a current stack frame
Differential Revision: https://reviews.llvm.org/D44756

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335701 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-27 01:51:55 +00:00
George Karpenkov d245644c76 [analyzer] Do not run visitors until the fixpoint, run only once.
In the current implementation, we run visitors until the fixed point is
reached.
That is, if a visitor adds another visitor, the currently processed path
is destroyed, all diagnostics is discarded, and it is regenerated again,
until it's no longer modified.
This pattern has a few negative implications:

 - This loop does not even guarantee to terminate.
   E.g. just imagine two visitors bouncing a diagnostics around.
 - Performance-wise, e.g. for sqlite3 all visitors are being re-run at
   least 10 times for some bugs.
   We have already seen a few reports where it leads to timeouts.
 - If we want to add more computationally intense visitors, this will
   become worse.
 - From architectural standpoint, the current layout requires copying
   visitors, which is conceptually wrong, and can be annoying (e.g. no
   unique_ptr on visitors allowed).

The proposed change is a much simpler architecture: the outer loop
processes nodes upwards, and whenever the visitor is added it only
processes current nodes and above, thus guaranteeing termination.

Differential Revision: https://reviews.llvm.org/D47856

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335666 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-26 21:12:08 +00:00
Reka Kovacs 694f835265 [analyzer] Add dangling internal buffer check.
This check will mark raw pointers to C++ standard library container internal
buffers 'released' when the objects themselves are destroyed. Such information
can be used by MallocChecker to warn about use-after-free problems.

In this first version, 'std::basic_string's are supported.

Differential Revision: https://reviews.llvm.org/D47135

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334348 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-09 13:03:49 +00:00
Adrian Prantl 647be32c60 Remove \brief commands from doxygen comments.
This is similar to the LLVM change https://reviews.llvm.org/D46290.

We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done

Differential Revision: https://reviews.llvm.org/D46320

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331834 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 01:00:01 +00:00
Artem Dergachev 4f25981ffc [analyzer] pr18953: Split C++ zero-initialization from default initialization.
The bindDefault() API of the ProgramState allows setting a default value
for reads from memory regions that were not preceded by writes.

It was used for implementing C++ zeroing constructors (i.e. default constructors
that boil down to setting all fields of the object to 0).

Because differences between zeroing consturctors and other forms of default
initialization have been piling up (in particular, zeroing constructors can be
called multiple times over the same object, probably even at the same offset,
requiring a careful and potentially slow cleanup of previous bindings in the
RegionStore), we split the API in two: bindDefaultInitial() for modeling
initial values and bindDefaultZero() for modeling zeroing constructors.

This fixes a few assertion failures from which the investigation originated.

The imperfect protection from both inability of the RegionStore to support
binding extents and lack of information in ASTRecordLayout has been loosened
because it's, well, imperfect, and it is unclear if it fixing more than it
was breaking.

Differential Revision: https://reviews.llvm.org/D46368


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331561 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-04 21:56:51 +00:00
Joel E. Denny 2c7723b2b6 [Attr] [NFC] Revert accidental change from r327405
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329005 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-02 19:43:34 +00:00
Artem Dergachev 39157efec1 [analyzer] Suppress more MallocChecker positives in smart pointer destructors.
r326249 wasn't quite enough because we often run out of inlining stack depth
limit and for that reason fail to see the atomics we're looking for.

Add a more straightforward false positive suppression that is based on the name
of the class. I.e. if we're releasing a pointer in a destructor of a "something
shared/intrusive/reference/counting something ptr/pointer something", then any
use-after-free or double-free that occurs later would likely be a false
positive.

rdar://problem/38013606

Differential Revision: https://reviews.llvm.org/D44281


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328066 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 00:49:47 +00:00
Joel E. Denny f4ca1ac809 Reland "[Attr] Fix parameter indexing for several attributes"
Relands r326602 (reverted in r326862) with new test and fix for
PR36620.

Differential Revision: https://reviews.llvm.org/D43248

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327405 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-13 14:51:22 +00:00
Nico Weber c67f146e7f Revert r326602, it caused PR36620.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326862 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-07 02:22:41 +00:00
Joel E. Denny aafdf02711 [Attr] Fix parameter indexing for several attributes
The patch fixes a number of bugs related to parameter indexing in
attributes:

* Parameter indices in some attributes (argument_with_type_tag,
  pointer_with_type_tag, nonnull, ownership_takes, ownership_holds,
  and ownership_returns) are specified in source as one-origin
  including any C++ implicit this parameter, were stored as
  zero-origin excluding any this parameter, and were erroneously
  printing (-ast-print) and confusingly dumping (-ast-dump) as the
  stored values.

* For alloc_size, the C++ implicit this parameter was not subtracted
  correctly in Sema, leading to assert failures or to silent failures
  of __builtin_object_size to compute a value.

* For argument_with_type_tag, pointer_with_type_tag, and
  ownership_returns, the C++ implicit this parameter was not added
  back to parameter indices in some diagnostics.

This patch fixes the above bugs and aims to prevent similar bugs in
the future by introducing careful mechanisms for handling parameter
indices in attributes.  ParamIdx stores a parameter index and is
designed to hide the stored encoding while providing accessors that
require each use (such as printing) to make explicit the encoding that
is needed.  Attribute declarations declare parameter index arguments
as [Variadic]ParamIdxArgument, which are exposed as ParamIdx[*].  This
patch rewrites all attribute arguments that are processed by
checkFunctionOrMethodParameterIndex in SemaDeclAttr.cpp to be declared
as [Variadic]ParamIdxArgument.  The only exception is xray_log_args's
argument, which is encoded as a count not an index.

Differential Revision: https://reviews.llvm.org/D43248

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326602 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-02 19:03:22 +00:00
Artem Dergachev fa5cf4d663 [analyzer] MallocChecker: Suppress false positives in shared pointers.
Throw away MallocChecker warnings that occur after releasing a pointer within a
destructor (or its callees) after performing C11 atomic fetch_add or fetch_sub
within that destructor (or its callees).

This is an indication that the destructor's class is likely a
reference-counting pointer. The analyzer is not able to understand that the
original reference count is usually large enough to avoid most use-after-frees.

Even when the smart pointer is a local variable, we still have these false
positives that this patch suppresses, because the analyzer doesn't currently
support atomics well enough.

Differential Revision: https://reviews.llvm.org/D43791


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326249 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27 21:19:33 +00:00
Artem Dergachev b881e2ba8c [analyzer] MallocChecker: Fix one more bug category.
Even though most of the inconsistencies in MallocChecker's bug categories were
fixed in r302016, one more was introduced in r301913 which was later missed.

Patch by Henry Wong!

Differential Revision: https://reviews.llvm.org/D43074


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324680 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-08 23:28:29 +00:00
Artem Dergachev 0e0ad4e27a [analyzer] operator new: Add a new checker callback, check::NewAllocator.
The callback runs after operator new() and before the construction and allows
the checker to access the casted return value of operator new() (in the
sense of r322780) which is not available in the PostCall callback for the
allocator call.

Update MallocChecker to use the new callback instead of PostStmt<CXXNewExpr>,
which gets called after the constructor.

Differential Revision: https://reviews.llvm.org/D41406
rdar://problem/12180598


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322787 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-17 23:46:13 +00:00
George Karpenkov b340ee9768 [analyzer] introduce getSVal(Stmt *) helper on ExplodedNode, make sure the helper is used consistently
In most cases using
`N->getState()->getSVal(E, N->getLocationContext())`
is ugly, verbose, and also opens up more surface area for bugs if an
inconsistent location context is used.

This patch introduces a helper on an exploded node, and ensures
consistent usage of either `ExplodedNode::getSVal` or
`CheckContext::getSVal` across the codebase.
As a result, a large number of redundant lines is removed.

Differential Revision: https://reviews.llvm.org/D42155

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322753 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-17 20:27:29 +00:00
Gabor Horvath d21e443eb0 [analyzer] Fix some check's output plist not containing the check name
Differential Revision: https://reviews.llvm.org/D41538


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321933 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-06 10:51:00 +00:00
Artem Dergachev d14025acfe [analyzer] Fix memory error bug category capitalization.
It was written as "Memory Error" in most places and as "Memory error" in a few
other places, however it is the latter that is more consistent with
other categories (such as "Logic error").

rdar://problem/31718115

Differential Revision: https://reviews.llvm.org/D32702


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302016 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-03 11:47:13 +00:00
Daniel Marjamaki 14c91c7c5b [analyzer] Detect bad free of function pointers
Differential Revision: https://reviews.llvm.org/D31650


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301913 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-02 11:46:12 +00:00
Leslie Zhai a530e823ed [analyzer] Teach the MallocChecker about Glib API for two arguments
Reviewers: zaks.anna, NoQ, danielmarjamaki

Reviewed By: zaks.anna, NoQ, danielmarjamaki

Subscribers: cfe-commits, kalev, pwithnall

Differential Revision: https://reviews.llvm.org/D30771


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301384 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-26 05:33:14 +00:00
Anna Zaks 49bcc8db44 [analyzer] Teach the MallocChecker about about Glib API
A patch by Leslie Zhai!

Differential Revision: https://reviews.llvm.org/D28348

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297323 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-09 00:01:01 +00:00
Anna Zaks 85570ac22c [analyzer] Add LocationContext as a parameter to checkRegionChanges
This patch adds LocationContext to checkRegionChanges and removes
wantsRegionChangeUpdate as it was unused.

A patch by Krzysztof Wiśniewski!

Differential Revision: https://reviews.llvm.org/D27090

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291869 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 00:50:57 +00:00
David Blaikie eeb7838f3e Migrate PathDiagnosticPiece to std::shared_ptr
Simplifies and makes explicit the memory ownership model rather than
implicitly passing/acquiring ownership.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291143 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-05 17:26:53 +00:00
Devin Coughlin b206e2ea77 [analyzer] Fix crash in MallocChecker.
Fix a crash in the MallocChecker when the extent size for the argument
to new[] is not known.

A patch by Abramo Bagnara and Dániel Krupp!

https://reviews.llvm.org/D27849

Differential Revision: https://reviews.llvm.org/D27849

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289970 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 18:41:40 +00:00
Artem Dergachev 7c595b6e32 [analyzer] Add another exception for Qt in MallocChecker
Treat pointers passed to QObject::connectImpl() as escaping.

rdar://problem/29550440

Differential Revision: https://reviews.llvm.org/D27717


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289939 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-16 12:21:55 +00:00
Devin Coughlin 79093a5be8 Revert "Revert "[analyzer] Make MallocChecker more robust against custom redeclarations""
This reverts commit r284340 to reapply r284335. The bot breakage was due to
an unrelated change in the polybench test suite.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284351 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-16 22:19:03 +00:00
Devin Coughlin e4dfcf62c0 Revert "[analyzer] Make MallocChecker more robust against custom redeclarations"
This reverts commit r284335.

It appears to be causing test-suite compile-time and execution-time
performance measurements to take longer than expected on several bots.
This is surprising, because r284335 is a static-analyzer-only change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284340 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-16 19:26:07 +00:00
Devin Coughlin 075094416b [analyzer] Make MallocChecker more robust against custom redeclarations
Add additional checking to MallocChecker to avoid crashing when memory
routines have unexpected numbers of arguments. You wouldn't expect to see much
of this in normal code (-Wincompatible-library-redeclaration warns on this),
but, for example, CMake tests can generate these.

This is PR30616.

rdar://problem/28631974

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284335 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-16 17:26:06 +00:00
Gabor Horvath 93cce01072 [analyzer] Calculate extent size for memory regions allocated by new expression.
ArrayBoundChecker did not detect out of bounds memory access errors in case an
array was allocated by the new expression. This patch resolves this issue.

Patch by Daniel Krupp!

Differential Revision: https://reviews.llvm.org/D24307



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281934 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-19 20:39:52 +00:00
Gabor Horvath 1779645f68 [analyzer] Small cleanups when checkers retrieving statements from exploded
nodes.

Differential Revision: https://reviews.llvm.org/D23550


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279037 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-18 07:54:50 +00:00
Mehdi Amini 2e23251d3e [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

Differential Revision: https://reviews.llvm.org/D20100

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275882 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-18 19:02:11 +00:00
David Majnemer ba5c7ce848 Use more ArrayRefs
No functional change is intended, just a small refactoring.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273647 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-24 04:05:48 +00:00
Benjamin Kramer 4ff480f17c Apply clang-tidy's misc-move-constructor-init throughout Clang.
No functionality change intended, maybe a tiny performance improvement.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270996 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 14:27:13 +00:00
Anna Zaks 3d5b3224ef [analyzer] Fix missed leak from MSVC specific allocation functions
Add the wide character strdup variants (wcsdup, _wcsdup) and the MSVC
version of alloca (_alloca) and other differently named function used
by the Malloc checker.

A patch by Alexander Riccio!

Differential Revision: http://reviews.llvm.org/D17688

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262894 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-08 01:21:51 +00:00
Artem Dergachev 3e7cbba83d [analyzer] Fix SVal/SymExpr/MemRegion class and enum names for consistency.
The purpose of these changes is to simplify introduction of definition files
for the three hierarchies.

1. For every sub-class C of these classes, its kind in the relevant enumeration
is changed to "CKind" (or C##Kind in preprocessor-ish terms), eg:

  MemRegionKind   -> MemRegionValKind
  RegionValueKind -> SymbolRegionValueKind
  CastSymbolKind  -> SymbolCastKind
  SymIntKind      -> SymIntExprKind

2. MemSpaceRegion used to be inconsistently used as both an abstract base and
a particular region. This region class is now an abstract base and no longer
occupies GenericMemSpaceRegionKind. Instead, a new class, CodeSpaceRegion,
is introduced for handling the unique use case for MemSpaceRegion as
"the generic memory space" (when it represents a memory space that holds all
executable code).

3. BEG_ prefixes in memory region kind ranges are renamed to BEGIN_ for
consisitency with symbol kind ranges.

4. FunctionTextRegion and BlockTextRegion are renamed to FunctionCodeRegion and
BlockCodeRegion, respectively. The term 'code' is less jargony than 'text' and
we already refer to BlockTextRegion as a 'code region' in BlockDataRegion.

Differential Revision: http://reviews.llvm.org/D16062


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257598 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-13 13:49:29 +00:00
Anna Zaks 72f508c0d8 [analyzer] Fix false warning about memory leak for QApplication::postEvent
According to Qt documentation Qt takes care of memory allocated for QEvent:
http://doc.qt.io/qt-4.8/qcoreapplication.html#postEvent

A patch by Evgeniy Dushistov!

Differential Revision: http://reviews.llvm.org/D14170

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256887 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-06 00:32:56 +00:00
Alexander Kornienko a68f403749 Refactor: Simplify boolean conditional return statements in lib/StaticAnalyzer/Checkers
Summary: Use clang-tidy to simplify boolean conditional return values

Reviewers: dcoughlin, krememek

Subscribers: krememek, cfe-commits

Patch by Richard Thomson!

Differential Revision: http://reviews.llvm.org/D10021


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256491 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-28 13:06:58 +00:00
Anna Zaks 8d7afec55e [analyzer] Assume escape is possible through system functions taking void*
The analyzer assumes that system functions will not free memory or modify the
arguments in other ways, so we assume that arguments do not escape when
those are called. However, this may lead to false positive leak errors. For
example, in code like this where the pointers added to the rb_tree are freed
later on:

		struct alarm_event *e = calloc(1, sizeof(*e));
<snip>

		rb_tree_insert_node(&alarm_tree, e);

Add a heuristic to assume that calls to system functions taking void*
arguments allow for pointer escape.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251449 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-27 20:19:45 +00:00
Devin Coughlin db0f9f00d2 [analyzer] Make realloc(ptr, 0) handling equivalent to malloc(0).
Currently realloc(ptr, 0) is treated as free() which seems to be not correct. C
standard (N1570) establishes equivalent behavior for malloc(0) and realloc(ptr,
0): "7.22.3 Memory management functions calloc, malloc, realloc: If the size of
the space requested is zero, the behavior is implementation-defined: either a
null pointer is  returned, or the behavior is as if the size were some nonzero
value, except that the returned pointer shall not be used to access an object."
The patch equalizes the processing of malloc(0) and realloc(ptr,0). The patch
also enables unix.Malloc checker to detect references to zero-allocated memory
returned by realloc(ptr,0) ("Use of zero-allocated memory" warning).

A patch by Антон Ярцев!

Differential Revision: http://reviews.llvm.org/D9040

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248336 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-22 22:47:14 +00:00
Devin Coughlin 440c44a96a [analyzer] Add generateErrorNode() APIs to CheckerContext.
The analyzer trims unnecessary nodes from the exploded graph before reporting
path diagnostics. However, in some cases it can trim all nodes (including the
error node), leading to an assertion failure (see
https://llvm.org/bugs/show_bug.cgi?id=24184).

This commit addresses the issue by adding two new APIs to CheckerContext to
explicitly create error nodes. Unless the client provides a custom tag, these
APIs tag the node with the checker's tag -- preventing it from being trimmed.
The generateErrorNode() method creates a sink error node, while
generateNonFatalErrorNode() creates an error node for a path that should
continue being explored.

The intent is that one of these two methods should be used whenever a checker
creates an error node.

This commit updates the checkers to use these APIs. These APIs
(unlike addTransition() and generateSink()) do not take an explicit Pred node.
This is because there are not any error nodes in the checkers that were created
with an explicit different than the default (the CheckerContext's Pred node).

It also changes generateSink() to require state and pred nodes (previously
these were optional) to reduce confusion.

Additionally, there were several cases where checkers did check whether a
generated node could be null; we now explicitly check for null in these places.

This commit also includes a test case written by Ying Yi as part of
http://reviews.llvm.org/D12163 (that patch originally addressed this issue but
was reverted because it introduced false positive regressions).

Differential Revision: http://reviews.llvm.org/D12780

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247859 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-16 22:03:05 +00:00