Commit Graph

482 Commits

Author SHA1 Message Date
George Karpenkov f702afcb3e [analyzer] Dump unique identifiers for statements in exploded graph
Differential Revision: https://reviews.llvm.org/D51823

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342310 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-15 02:02:09 +00:00
George Karpenkov e4d256f38d [analyzer] Skip printing duplicate nodes, even if nodes have multiple predecessors/successors
Still generate a node, but leave the redundant field empty.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@342308 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-15 02:01:26 +00:00
George Karpenkov 3f0bc9eab1 [analyzer] Skip printing trivial nodes in exploded graph
A node is considered to be trivial if it only has one successor, one
predecessor, and a state equal to the predecessor.
Can drastically (> 2x) reduce the size of the generated exploded
graph.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341616 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-07 00:42:32 +00:00
George Karpenkov cb712aff1f [analyzer] [NFC] Move dumping program point into a separate function
Differential Revision: https://reviews.llvm.org/D51666

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341603 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-06 23:08:27 +00:00
George Karpenkov 960d25b4d9 [analyzer] Dump stable identifiers for exploded nodes
Differential Revision: https://reviews.llvm.org/D51667

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341602 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-06 23:08:07 +00:00
George Karpenkov cc7b7584b5 [analyzer] Dump a reproducible, deterministic ID of program state to exploded graph
Differential Revision: https://reviews.llvm.org/D51395

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341600 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-06 23:07:26 +00:00
Artem Dergachev 2483f1c915 [CFG] [analyzer] Disable argument construction contexts for variadic functions.
The analyzer doesn't make use of them anyway and they seem to have
pretty weird AST from time to time, so let's just skip them for now.

Fixes a crash reported as pr37769.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340977 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-29 22:05:35 +00:00
George Karpenkov faff2291a9 [analyzer] Move analyzer-eagerly-assume to AnalyzerOptions, enable by default
Differential Revision: https://reviews.llvm.org/D51251

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340963 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-29 20:29:17 +00:00
Artem Dergachev 035a4f5180 [analyzer] Add support for constructors of arguments.
Once CFG-side support for argument construction contexts landed in r338436,
the analyzer could make use of them to evaluate argument constructors properly.

When evaluated as calls, constructors of arguments now use the variable region
of the parameter as their target. The corresponding stack frame does not yet
exist when the parameter is constructed, and this stack frame is created
eagerly.

Construction of functions whose body is unavailable and of virtual functions
is not yet supported. Part of the reason is the analyzer doesn't consistently
use canonical declarations o identify the function in these cases, and every
re-declaration or potential override comes with its own set of parameter
declarations. Also it is less important because if the function is not
inlined, there's usually no benefit in inlining the argument constructor.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339745 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-15 00:33:55 +00:00
Stephen Kelly d7b659b592 Port getLocStart -> getBeginLoc
Reviewers: teemperor!

Subscribers: jholewinski, whisperity, jfb, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339385 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-09 21:08:08 +00:00
Artem Dergachev 40dbd95111 [analyzer] Fix eliding the same destructor twice due to buggy default arguments.
Because of incomplete support for CXXDefaultArgExpr, we cannot yet commit to
asserting that the same destructor won't be elided twice.

Suppress the assertion failure for now. Proper support is still an open problem.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338441 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 21:17:40 +00:00
Artem Dergachev 9612e11233 [CFG] [analyzer] NFC: Enumerate construction context layer kinds.
This is a refactoring patch; no functional change intended.

The common part of ConstructionContextLayer and ConstructedObjectKey is
factored out into a new structure, ConstructionContextItem.

Various sub-kinds of ConstructionContextItem are enumerated in order to
provide richer information about construction contexts.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338439 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 21:12:42 +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 3ad62f50a0 [analyzer] Make checkEndFunction() give access to the return statement.
Differential Revision: https://reviews.llvm.org/D49387

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337215 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-16 20:47:45 +00:00
Artem Dergachev bd011d17e2 [analyzer] Remove redundant ';'.
Fixes a compiler warning. No functionan change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335808 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-28 02:33:16 +00:00
Artem Dergachev 9d345ab5b4 [analyzer] Add support for pre-C++17 copy elision.
r335795 adds copy elision information to CFG. This commit allows static analyzer
to elide elidable copy constructors by constructing the objects that were
previously subject to elidable copy directly in the target region of the copy.

The chain of elided constructors may potentially be indefinitely long. This
only happens when the object is being returned from a function which in turn is
returned from another function, etc.

NRVO is not supported yet.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335800 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-28 00:30:18 +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
Leonard Chan 84dd23f357 [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals
This diff includes the logic for setting the precision bits for each primary fixed point type in the target info and logic for initializing a fixed point literal.

Fixed point literals are declared using the suffixes

```
hr: short _Fract
uhr: unsigned short _Fract
r: _Fract
ur: unsigned _Fract
lr: long _Fract
ulr: unsigned long _Fract
hk: short _Accum
uhk: unsigned short _Accum
k: _Accum
uk: unsigned _Accum
```
Errors are also thrown for illegal literal values

```
unsigned short _Accum u_short_accum = 256.0uhk;   // expected-error{{the integral part of this literal is too large for this unsigned _Accum type}}
```

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@335148 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-20 17:19:40 +00:00
Artem Dergachev 0d16135638 [analyzer] Track class member initializer constructors path-sensitively.
The reasoning behind this change is similar to the previous commit, r334681.
Because members are already in scope when construction occurs, we are not
suffering from liveness problems, but we still want to figure out if the object
was constructed with construction context, because in this case we'll be able
to avoid trivial copy, which we don't always model perfectly. It'd also have
more importance when copy elision is implemented.

This also gets rid of the old CFG look-behind mechanism.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334682 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-14 01:40:49 +00:00
Artem Dergachev 43ed70876c [analyzer] NFC: Merge code for finding and tracking construction target.
When analyzing C++ code, a common operation in the analyzer is to discover
target region for object construction by looking at CFG metadata ("construction
contexts"), and then track the region path-sensitively until object construction
is resolved, where the amount of information, again, depends on construction
context.

Scan construction context only once for both purposes.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334678 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-14 01:20:12 +00:00
Artem Dergachev a4a9c5d1fd [analyzer] NFC: Track all constructed objects in a single state trait.
ExprEngine already maintains three internal program state traits to track
path-sensitive information related to object construction: pointer returned by
operator new, and pointer to temporary object for two different purposes - for
destruction and for lifetime extension. We'll need to add 2-3 more in a few
follow-up commits.

Merge these traits into one because they all essentially serve one purpose and
work similarly.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333719 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-01 01:59:48 +00:00
Artem Dergachev 55659af029 [analyzer] Remove untested code in evalLoad.
No functional change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331565 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-04 23:01:10 +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
Artem Dergachev 1433b05edb [analyzer] Fix operator delete[] array-type-sub-expression handling.
Avoid crash when the sub-expression of operator delete[] is of array type.

This is not the same as simply using a delete[] syntax.

We're still not properly calling destructors in this case in the analyzer.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331014 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-27 02:16:03 +00:00
Artem Dergachev addfb0519a [analyzer] When we fail to evaluate a pointer cast, escape the pointer.
If a pointer cast fails (evaluates to an UnknownVal, i.e. not implemented in the
analyzer) and such cast is in fact the last use of the pointer, the pointer
symbol is no longer referenced by the program state and a leak is
(mis-)diagnosed.

"Escape" the pointer upon a failed cast, i.e. inform the checker that we can no
longer reliably track it.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@330380 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-19 23:24:32 +00:00
George Karpenkov d05cde1c10 [analyzer] Better pretty-printing of regions in exploded graph
Differential Revision: https://reviews.llvm.org/D45010

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328835 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-29 22:07:58 +00:00
Artem Dergachev 71e8b54df4 [analyzer] Remove an assertion that doesn't hold in C++17.
Function return values can be constructed directly in variables or passed
directly into return statements, without even an elidable copy in between.
This is how the C++17 mandatory copy elision AST behaves. The behavior we'll
have in such cases is the "old" behavior that we've had before we've
implemented destructor inlining and proper lifetime extension support.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328253 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-22 21:54:48 +00:00
George Karpenkov ed2defa004 [analyzer] Fix the assertion failure when static globals are used in lambda by reference
Also use the opportunity to clean up the code and remove unnecessary duplication.

rdar://37625895

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327926 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-20 00:20:58 +00:00
Pavel Labath 5f4ef08259 StaticAnalyzer: fix compiler warning. NFC
My compiler (clang-3.8) complains that the RCC variable is unused.
That's not really true, as it's checked by the if-declaration, but it's
also kinda true, because we don't need to declaration if we only check
it in the if statement.

In reality, all this means that the dyn_cast<> can be replaced by isa<>,
so that's what I do here.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327491 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-14 10:16:40 +00:00
Artem Dergachev b2dc2834ca [analyzer] NFC: Move the code for setting temp object lifetime into method.
Differential Revision: https://reviews.llvm.org/D44129


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327347 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-12 23:27:52 +00:00
Artem Dergachev 3e76d34afa [CFG] [analyzer] Add construction context to C++ return-by-value call elements.
This patch adds a new CFGStmt sub-class, CFGCXXRecordTypedCall, which replaces
the regular CFGStmt for the respective CallExpr whenever the CFG has additional
information to provide regarding the lifetime of the returned value.

This additional call site information is represented by a ConstructionContext
(which was previously used for CFGConstructor elements) that provides references
to CXXBindTemporaryExpr and MaterializeTemporaryExpr that surround the call.

This corresponds to the common C++ calling convention solution of providing
the target address for constructing the return value as an auxiliary implicit
argument during function call.

One of the use cases for such extra context at the call site would be to perform
any sort of inter-procedural analysis over the CFG that involves functions
returning objects by value. In this case the elidable constructor at the return
site would construct the object explained by the context at the call site, and
its lifetime would also be managed by the caller, not the callee.

The extra context would also be useful for properly handling the return-value
temporary at the call site, even if the callee is not being analyzed
inter-procedurally.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327343 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-12 23:12:40 +00:00
Maxim Ostapenko 359fc2a1d2 [analyzer] Add scope information to CFG
This patch adds two new CFG elements CFGScopeBegin and CFGScopeEnd that indicate
when a local scope begins and ends respectively. We use first VarDecl declared
in a scope to uniquely identify it and add CFGScopeBegin and CFGScopeEnd elements
into corresponding basic blocks.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327258 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-12 12:26:15 +00:00
George Burgess IV 333877a411 Fix an unused variable warning; NFC
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326980 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-08 02:15:12 +00:00
George Karpenkov b16500ae70 [analyzer] Don't crash with assertion failure on structured bindings
Proper modeling still remains to be done.
Note that BindingDecl#getHoldingVar() is almost always null, and this
should probably be handled by dealing with DecompositionDecl beforehand.

rdar://36852163

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326951 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-07 22:20:35 +00:00
Eugene Zelenko 297f9200b2 [StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326519 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-02 00:54:51 +00:00
Ilya Biryukov c476211d8b Resubmit [analyzer] Support for naive cross translation unit analysis
Originally submitted as r326323 and r326324.
Reverted in r326432.

Reverting the commit was a mistake.
The breakage was due to invalid build files in our internal buildsystem,
CMakeLists did not have any cyclic dependencies.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326439 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-01 14:54:16 +00:00
Ilya Biryukov 8525a325f5 Revert "[analyzer] Support for naive cross translation unit analysis"
Also revert "[analyzer] Fix a compiler warning"
This reverts commits r326323 and r326324.

Reason: the commits introduced a cyclic dependency in the build graph.
This happens to work with cmake, but breaks out internal integrate.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326432 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-01 12:43:39 +00:00
Gabor Horvath 5b8b6afcd1 [analyzer] Support for naive cross translation unit analysis
The aim of this patch is to be minimal to enable incremental development of
the feature on the top of the tree. This patch should be an NFC when the
feature is turned off. It is turned off by default and still considered as
experimental.

Technical details are available in the EuroLLVM Talk: 
http://llvm.org/devmtg/2017-03//2017/02/20/accepted-sessions.html#7

Note that the initial prototype was done by A. Sidorin et al.: http://lists.llvm.org/pipermail/cfe-dev/2015-October/045730.html

Contributions to the measurements and the new version of the code: Peter Szecsi, Zoltan Gera, Daniel Krupp, Kareem Khazem.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326323 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-28 13:23:10 +00:00
Artem Dergachev 0dacdd09c3 [analyzer] Track temporaries without construction contexts for destruction.
Sometimes it is not known at compile time which temporary objects will be
constructed, eg. 'x ? A() : B()' or 'C() || D()'. In this case we track which
temporary was constructed to know how to properly call the destructor.

Once the construction context for temporaries was introduced, we moved the
tracking code to the code that investigates the construction context.

Bring back the old mechanism because construction contexts are not always
available yet - eg. in the case where a temporary is constructed without a
constructor expression, eg. returned from a function by value. The mechanism
should still go away eventually.

Additionally, fix a bug in the temporary cleanup code for the case when
construction contexts are not available, which could lead to temporaries
staying in the program state and increasing memory consumption.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326246 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27 21:02:58 +00:00
Artem Dergachev b4b42d6821 [analyzer] Introduce correct lifetime extension behavior in simple cases.
This patch uses the reference to MaterializeTemporaryExpr stored in the
construction context since r326014 in order to model that expression correctly.

When modeling MaterializeTemporaryExpr, instead of copying the raw memory
contents from the sub-expression's rvalue to a completely new temporary region,
that we conjure up for the lack of better options, we now have the better
option to recall the region into which the object was originally constructed
and declare that region to be the value of the expression, which is semantically
correct.

This only works when the construction context is available, which is worked on
independently.

The temporary region's liveness (in the sense of removeDeadBindings) is extended
until the MaterializeTemporaryExpr is resolved, in order to keep the store
bindings around, because it wouldn't be referenced from anywhere else in the
program state.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326236 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-27 19:47:49 +00:00
Artem Dergachev 015d21eba5 [analyzer] Suppress temporary destructors for temporary arrays.
Array destructors, like constructors, need to be called for each element of the
array separately. We do not have any mechanisms to do this in the analyzer,
so for now all we do is evaluate a single constructor or destructor
conservatively and give up. It automatically causes the necessary invalidation
and pointer escape for the whole array, because this is how RegionStore works.

Implement this conservative behavior for temporary destructors. This fixes the
crash on the provided test.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325286 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-15 19:34:19 +00:00
Artem Dergachev f337a76051 [analyzer] Compute the correct this-region for temporary destructors.
Inline them if possible - a separate flag is added to control this.
The whole thing is under the cfg-temporary-dtors flag, off by default so far.

Temporary destructors are called at the end of full-expression. If the
temporary is lifetime-extended, automatic destructors kick in instead,
which are not addressed in this patch, and normally already work well
modulo the overally broken support for lifetime extension.

The patch operates by attaching the this-region to the CXXBindTemporaryExpr in
the program state, and then recalling it during destruction that was triggered
by that CXXBindTemporaryExpr. It has become possible because
CXXBindTemporaryExpr is part of the construction context since r325210.

Differential revision: https://reviews.llvm.org/D43104


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325282 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-15 19:17:44 +00:00
Artem Dergachev 6b4c160f3b [analyzer] Decide on inlining destructors via EvalCallOptions.
EvalCallOptions were introduced in r324018 for allowing various parts of
ExprEngine to notify the inlining mechanism, while preparing for evaluating a
function call, of possible difficulties with evaluating the call that they
foresee. Then mayInlineCall() would still be a single place for making the
decision.

Use that mechanism for destructors as well - pass the necessary flags from the
CFG-element-specific destructor handlers.

Part of this patch accidentally leaked into r324018, which led into a change in
tests; this change is reverted now, because even though the change looked
correct, the underlying behavior wasn't. Both of these commits were not intended
to introduce any function changes otherwise.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@325209 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-15 02:51:58 +00:00
Artem Dergachev ac633fb5c4 [analyzer] Add missing pre-post-statement callbacks for OffsetOfExpr.
This expression may or may not be evaluated in compile time, so tracking the
result symbol is of potential interest. However, run-time offsetof is not yet
supported by the analyzer, so for now this callback is only there to assist
future implementation.

Patch by Henry Wong!

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324790 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-10 00:55:49 +00:00
Artem Dergachev a39a1f8aa0 [CFG] Add extra context to C++ constructor statement elements.
This patch adds a new CFGStmt sub-class, CFGConstructor, which replaces
the regular CFGStmt with CXXConstructExpr in it whenever the CFG has additional
information to provide regarding what sort of object is being constructed.

It is useful for figuring out what memory is initialized in client of the
CFG such as the Static Analyzer, which do not operate by recursive AST
traversal, but instead rely on the CFG to provide all the information when they
need it. Otherwise, the statement that triggers the construction and defines
what memory is being initialized would normally occur after the
construct-expression, and the client would need to peek to the next CFG element
or use statement parent map to understand the necessary facts about
the construct-expression.

As a proof of concept, CFGConstructors are added for new-expressions
and the respective test cases are provided to demonstrate how it works.

For now, the only additional data contained in the CFGConstructor element is
the "trigger statement", such as new-expression, which is the parent of the
constructor. It will be significantly expanded in later commits. The additional
data is organized as an auxiliary structure - the "construction context",
which is allocated separately from the CFGElement.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324668 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-08 22:58:15 +00:00
Artem Dergachev 0b84c86812 [analyzer] Self-debug: Dump the core's internal state traits to the egraph.
It is useful for debugging problems with C++ operator new() or temporaries.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324663 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-08 22:32:38 +00:00
Artem Dergachev bf0d414987 [analyzer] Self-debug: Dump environment frame-by-frame.
It makes it easier to discriminate between values of similar expressions
in different stack frames.

It also makes the separate backtrace section in ExplodedGraph dumps redundant.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324660 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-08 22:24:38 +00:00
Artem Dergachev cd369d49a2 [analyzer] Fix transitions in check::PreStmt<MemberExpr> checker callback.
No in-tree checkers use this callback so far, hence no tests. But better fix
this now than remember to fix this when the checkers actually appear.

Patch by Henry Wong!

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324053 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-02 02:23:37 +00:00
George Karpenkov 63f1a46002 [analyzer] Expose exploration strategy through analyzer options.
Differential Revision: https://reviews.llvm.org/D42774

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@324049 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-02 02:01:55 +00:00
Artem Dergachev fdba1f2ef6 [analyzer] operator new: Fix callback order for CXXNewExpr.
PreStmt<CXXNewExpr> was never called.

Additionally, under c++-allocator-inlining=true, PostStmt<CXXNewExpr> was
called twice when the allocator was inlined: once after evaluating the
new-expression itself, once after evaluating the allocator call which, for the
lack of better options, uses the new-expression as the call site.

This patch fixes both problems.

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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@322797 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-18 00:53:50 +00:00