aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer
AgeCommit message (Collapse)Author
2013-04-03[analyzer] make peelOffOuterExpr in BugReporterVisitors recursively peel off ↵Anna Zaks
select Exprs git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178685 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[analyzer] Properly handle the ternary operator in trackNullOrUndefValueAnna Zaks
1) Look for the node where the condition expression is live when checking if it is constrained to true or false. 2) Fix a bug in ProgramState::isNull, which was masking the problem. When the expression is not a symbol (,which is the case when it is Unknown) return unconstrained value, instead of value constrained to “false”! (Thankfully other callers of isNull have not been effected by the bug.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178684 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[analyzer] Fix typo.Anna Zaks
Thanks Jordan! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178683 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-03[analyzer] Better model for copying of array fields in implicit copy ctors.Jordan Rose
- Find the correct region to represent the first array element when constructing a CXXConstructorCall. - If the array is trivial, model the copy with a primitive load/store. - Don't warn about the "uninitialized" subscript in the AST -- we don't use the helper variable that Sema provides. <rdar://problem/13091608> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178602 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02Silencing warnings in MSVC due to duplicate identifiers.Aaron Ballman
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178591 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] Moving cplusplus.NewDelete to alpha.* for now.Anton Yartsev
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178529 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] Teach invalidateRegions that regions within LazyCompoundVal need ↵Anna Zaks
to be invalidated Refactor invalidateRegions to take SVals instead of Regions as input and teach RegionStore about processing LazyCompoundVal as a top-level “escaping” value. This addresses several false positives that get triggered by the NewDelete checker, but the underlying issue is reproducible with other checkers as well (for example, MallocChecker). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178518 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] For now, don't inline [cd]tors of C++ containers.Jordan Rose
This is a heuristic to make up for the fact that the analyzer doesn't model C++ containers very well. One example is modeling that 'std::distance(I, E) == 0' implies 'I == E'. In the future, it would be nice to model this explicitly, but for now it just results in a lot of false positives. The actual heuristic checks if the base type has a member named 'begin' or 'iterator'. If so, we treat the constructors and destructors of that type as opaque, rather than inlining them. This is intended to drastically reduce the number of false positives reported with experimental destructor support turned on. We can tweak the heuristic in the future, but we'd rather err on the side of false negatives for now. <rdar://problem/13497258> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178516 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] Cache whether a function is generally inlineable.Jordan Rose
Certain properties of a function can determine ahead of time whether or not the function is inlineable, such as its kind, its signature, or its location. We can cache this value in the FunctionSummaries map to avoid rechecking these static properties for every call. Note that the analyzer may still decide not to inline a specific call to a function because of the particular dynamic properties of the call along the current path. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178515 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] Use inline storage in the FunctionSummary DenseMap.Jordan Rose
The summaries lasted for the lifetime of the map anyway; no reason to include an extra allocation. Also, use SmallBitVector instead of BitVector to track the visited basic blocks -- most functions will have less than 64 basic blocks -- and use bitfields for the other fields to reduce the size of the structure. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178514 91177308-0d34-0410-b5e6-96231b3b80d8
2013-04-02[analyzer] Allow suppressing diagnostics reported within the 'std' namespaceJordan Rose
This is controlled by the 'suppress-c++-stdlib' analyzer-config flag. It is currently off by default. This is more suppression than we'd like to do, since obviously there can be user-caused issues within 'std', but it gives us the option to wield a large hammer to suppress false positives the user likely can't work around. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178513 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-30[analyzer] Restructure ExprEngine::VisitCXXNewExpr to do a bit less work.Jordan Rose
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178402 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-30[analyzer] Handle caching out while evaluating a C++ new expression.Jordan Rose
Evaluating a C++ new expression now includes generating an intermediate ExplodedNode, and this node could very well represent a previously- reachable state in the ExplodedGraph. If so, we can short-circuit the rest of the evaluation. Caught by the assertion a few lines later. <rdar://problem/13510065> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178401 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-29[analyzer] Address Jordan’s review of r178309 - do not register an extra ↵Anna Zaks
visitor for nil receiver We can check if the receiver is nil in the node that corresponds to the StmtPoint of the message send. At that point, the receiver is guaranteed to be live. We will find at least one unreclaimed node due to my previous commit (look for StmtPoint instead of PostStmt) and the fact that the nil receiver nodes are tagged. + a couple of extra tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178381 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-29[analyzer] Look for a StmtPoint node instead of PostStmt in ↵Anna Zaks
trackNullOrUndefValue. trackNullOrUndefValue tries to find the first node that matches the statement it is tracking. Since we collect PostStmt nodes (in node reclamation), none of those might be on the current path, so relax the search to look for any StmtPoint. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178380 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-29Add static analyzer support for conditionally executing static initializers.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178318 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-29Add configuration plumbing to enable static initializer branching in the CFG ↵Ted Kremenek
for the analyzer. This setting still isn't enabled yet in the analyzer. This is just prep work. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178317 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28[analyzer] Document existence of ConstPointerEscape.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178311 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28[analyzer] Add support for escape of const pointers and use it to allow ↵Anna Zaks
“newed” pointers to escape Add a new callback that notifies checkers when a const pointer escapes. Currently, this only works for const pointers passed as a top level parameter into a function. We need to differentiate the const pointers escape from regular escape since the content pointed by const pointer will not change; if it’s a file handle, a file cannot be closed; but delete is allowed on const pointers. This should suppress several false positives reported by the NewDelete checker on llvm codebase. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178310 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28[analyzer] Apply the suppression rules to the nil receiver only if the value ↵Anna Zaks
participates in the computation of the nil we warn about. We should only suppress a bug report if the IDCed or null returned nil value is directly related to the value we are warning about. This was not the case for nil receivers - we would suppress a bug report that had an IDCed nil receiver on the path regardless of how it’s related to the warning. 1) Thread EnableNullFPSuppression parameter through the visitors to differentiate between tracking the value which is directly responsible for the bug and other values that visitors are tracking (ex: general tracking of nil receivers). 2) in trackNullOrUndef specifically address the case when a value of the message send is nil due to the receiver being nil. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178309 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28Use early return in printing logic. Minor cleanup.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178264 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28Fix order of initialization warning.Eric Christopher
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178255 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28[analyzer] These implements unix.MismatchedDeallocatorChecker checker.Anton Yartsev
+ Improved display names for allocators and deallocators The checker checks if a deallocation function matches allocation one. ('free' for 'malloc', 'delete' for 'new' etc.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178250 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-28[analyzer] For now assume all standard global 'operator new' functions ↵Anton Yartsev
allocate memory in heap. + Improved test coverage for cplusplus.NewDelete checker. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178244 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-27[analyzer] Use evalBind for C++ new of scalar types.Jordan Rose
These types will not have a CXXConstructExpr to do the initialization for them. Previously we just used a simple call to ProgramState::bindLoc, but that doesn't trigger proper checker callbacks (like pointer escape). Found by Anton Yartsev. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178160 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-27[analyzer] Cleanup: only get the PostStmt when we need the underlying Stmt + ↵Anna Zaks
comment git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178153 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-27[analyzer] Ensure that the node NilReceiverBRVisitor is looking for is not ↵Anna Zaks
reclaimed The visitor should look for the PreStmt node as the receiver is nil in the PreStmt and this is the node. Also, tag the nil receiver nodes with a special tag for consistency. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178152 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-26[analyzer] Make sure IDC works for ‘NSContainer value/key is nil’ checks.Anna Zaks
Register the nil tracking visitors with the region and refactor trackNullOrUndefValue a bit. Also adds the cast and paren stripping before checking if the value is an OpaqueValueExpr or ExprWithCleanups. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178093 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-26[analyzer] Change inlining policy to inline small functions when reanalyzing ↵Anna Zaks
ObjC methods as top level. This allows us to better reason about(inline) small wrapper functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178063 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-26[analyzer] micro optimization as per Jordan’s feedback on r177905.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178062 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-25[analyzer] Set concrete offset bindings to UnknownVal when processing ↵Anna Zaks
symbolic offset binding, even if no bindings are present. This addresses an undefined value false positive from concreteOffsetBindingIsInvalidatedBySymbolicOffsetAssignment. Fixes PR14877; radar://12991168. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177905 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-25[analyzer] Adds cplusplus.NewDelete checker that check for memory leaks, ↵Anton Yartsev
double free, and use-after-free problems of memory managed by new/delete. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177849 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-24[analyzer] Teach ConstraintManager to ignore NonLoc <> NonLoc comparisons.Jordan Rose
These aren't generated by default, but they are needed when either side of the comparison is tainted. Should fix our internal buildbot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177846 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Teach constraint managers about unsigned comparisons.Jordan Rose
In C, comparisons between signed and unsigned numbers are always done in unsigned-space. Thus, we should know that "i >= 0U" is always true, even if 'i' is signed. Similarly, "u >= 0" is also always true, even though '0' is signed. Part of <rdar://problem/13239003> (false positives related to std::vector) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177806 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Loc-Loc operations (subtraction or comparison) produce a NonLoc.Jordan Rose
For two concrete locations, we were producing another concrete location and then casting it to an integer. We should just create a nonloc::ConcreteInt to begin with. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177805 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Also transform "a < b" to "(b - a) > 0" in the constraint manager.Jordan Rose
We can support the full range of comparison operations between two locations by canonicalizing them as subtraction, as in the previous commit. This won't work (well) if either location includes an offset, or (again) if the comparisons are not consistent about which region comes first. <rdar://problem/13239003> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177803 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23Add reverseComparisonOp and negateComparisonOp to BinaryOperator.Jordan Rose
...and adopt them in the analyzer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177802 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Translate "a != b" to "(b - a) != 0" in the constraint manager.Jordan Rose
Canonicalizing these two forms allows us to better model containers like std::vector, which use "m_start != m_finish" to implement empty() but "m_finish - m_start" to implement size(). The analyzer should have a consistent interpretation of these two symbolic expressions, even though it's not properly reasoning about either one yet. The other unfortunate thing is that while the size() expression will only ever be written "m_finish - m_start", the comparison may be written "m_finish == m_start" or "m_start == m_finish". Right now the analyzer does not attempt to canonicalize those two expressions, since it doesn't know which length expression to pick. Doing this correctly will probably require implementing unary minus as a new SymExpr kind (<rdar://problem/12351075>). For now, the analyzer inverts the order of arguments in the comparison to build the subtraction, on the assumption that "begin() != end()" is written more often than "end() != begin()". This is purely speculation. <rdar://problem/13239003> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177801 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Use SymExprs to represent '<loc> - <loc>' and '<loc> == <loc>'.Jordan Rose
We just treat this as opaque symbols, but even that allows us to handle simple cases where the same condition is tested twice. This is very common in the STL, which means that any project using the STL gets spurious errors. Part of <rdar://problem/13239003>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177800 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Warn when a nil key or value are passed to NSMutableDictionary ↵Anna Zaks
and ensure it works with subscripting. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177789 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Correct the stale comment.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177788 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-22Revert "[analyzer] Break cycles (optionally) when trimming an ExplodedGraph."Jordan Rose
The algorithm used here was ridiculously slow when a potential back-edge pointed to a node that already had a lot of successors. The previous commit makes this feature unnecessary anyway. This reverts r177468 / f4cf6b10f863b9bc716a09b2b2a8c497dcc6aa9b. Conflicts: lib/StaticAnalyzer/Core/BugReporter.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177765 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-22[analyzer] Use a forward BFS instead of a reverse BFS to find shortest paths.Jordan Rose
For a given bug equivalence class, we'd like to emit the report with the shortest path. So far to do this we've been trimming the ExplodedGraph to only contain relevant nodes, then doing a reverse BFS (starting at all the error nodes) to find the shortest paths from the root. However, this is fairly expensive when we are suppressing many bug reports in the same equivalence class. r177468-9 tried to solve this problem by breaking cycles during graph trimming, then updating the BFS priorities after each suppressed report instead of recomputing the whole thing. However, breaking cycles is not a cheap operation because an analysis graph minus cycles is still a DAG, not a tree. This fix changes the algorithm to do a single forward BFS (starting from the root) and to use that to choose the report with the shortest path by looking at the error nodes with the lowest BFS priorities. This was Anna's idea, and has the added advantage of requiring no update step: we can just pick the error node with the next lowest priority to produce the next bug report. <rdar://problem/13474689> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177764 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-22[analyzer] Fix ExprEngine::ViewGraph to handle C++ initializers.Jordan Rose
Debugging aid only, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177762 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-21[analyzer] Print return values from debug.DumpCalls checker.Jordan Rose
Debug utility only, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177649 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[analyzer] Appease buildbots: include template arguments in base class ref.Jordan Rose
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177583 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[analyzer] Don't invalidate globals when there's no call involved.Jordan Rose
This fixes some mistaken condition logic in RegionStore that caused global variables to be invalidated when /any/ region was invalidated, rather than only as part of opaque function calls. This was only being used by CStringChecker, and so users will now see that strcpy() and friends do not invalidate global variables. Also, add a test case we don't handle properly: explicitly-assigned global variables aren't being invalidated by opaque calls. This is being tracked by <rdar://problem/13464044>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177572 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[analyzer] Track malloc'd memory into struct fields.Jordan Rose
Due to improper modelling of copy constructors (specifically, their const reference arguments), we were producing spurious leak warnings for allocated memory stored in structs. In order to silence this, we decided to consider storing into a struct to be the same as escaping. However, the previous commit has fixed this issue and we can now properly distinguish leaked memory that happens to be in a struct from a buffer that escapes within a struct wrapper. Originally applied in r161511, reverted in r174468. <rdar://problem/12945937> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177571 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[analyzer] Invalidate regions indirectly accessible through const pointers.Jordan Rose
In this case, the value of 'x' may be changed after the call to indirectAccess: struct Wrapper { int *ptr; }; void indirectAccess(const Wrapper &w); void test() { int x = 42; Wrapper w = { x }; clang_analyzer_eval(x == 42); // TRUE indirectAccess(w); clang_analyzer_eval(x == 42); // UNKNOWN } This is important for modelling return-by-value objects in C++, to show that the contents of the struct are escaping in the return copy-constructor. <rdar://problem/13239826> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177570 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-20[analyzer] Remove strip of ElementRegion in CallEvent::invalidateRegions.Jordan Rose
This is a bit of old code trying to deal with the fact that functions that take pointers often use them to access an entire array via pointer arithmetic. However, RegionStore already conservatively assumes you can use pointer arithmetic to access any part of a region. Some day we may want to go back to handling this specifically for calls, but we can do that in the future. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177569 91177308-0d34-0410-b5e6-96231b3b80d8