Commit Graph

1403 Commits

Author SHA1 Message Date
Ted Kremenek a85f38ba3a Rework ExprEngine::evalLoad and clients (e.g. VisitBinaryOperator) so that when we generate a new ExplodedNode
we use the same Expr* as the one being currently visited.  This is preparation for transitioning to having
ProgramPoints refer to CFGStmts.

This required a bit of trickery.  We wish to keep the old Expr* bindings in the Environment intact,
as plenty of logic relies on it and there is no reason to change it, but we sometimes want the Stmt* for
the ProgramPoint to be different than the Expr* being used for bindings.  This requires adding an extra
argument for some functions (e.g., evalLocation).  This looks a bit strange for some clients, but
it will look a lot cleaner when were start using CFGStmt* in the appropriate places.

As some fallout, the diagnostics arrows are a bit difference, since some of the node locations have changed.
I have audited these, and they look reasonable.

llvm-svn: 154214
2012-04-06 22:10:18 +00:00
Jordy Rose c0230d7a35 [analyzer] Check that the arguments to NSOrderedSet creation methods are valid ObjC objects.
Patch by Sean McBride!

llvm-svn: 154194
2012-04-06 19:06:01 +00:00
Patrick Beard acfbe9e1f2 Added a new attribute, objc_root_class, which informs the compiler when a root class is intentionally declared.
The warning this inhibits, -Wobjc-root-class, is opt-in for now. However, all clang unit tests that would trigger
the warning have been updated to use -Wno-objc-root-class. <rdar://problem/7446698>

llvm-svn: 154187
2012-04-06 18:12:22 +00:00
Anna Zaks e8628c5bc7 [analyzer]Fix false positive: pointer might escape through CG*WithData.
llvm-svn: 154156
2012-04-06 01:00:47 +00:00
Ted Kremenek 34ac1cf3cd Handle symbolicating a reference in an initializer expression that we don't understand.
llvm-svn: 154084
2012-04-05 05:56:31 +00:00
Ted Kremenek 00fa5968cb Teach ObjCContainersChecker that the array passed to CFArrayGetValueAtIndex might not be a symbolic value.
llvm-svn: 154083
2012-04-05 05:18:05 +00:00
Ted Kremenek 504957f413 Do not crash in the callgraph construction when encountering deleted function definitions. Fixes <rdar://problem/11178609>.
llvm-svn: 154081
2012-04-05 04:03:23 +00:00
David Blaikie 09ffc9b473 Enable warn_impcast_literal_float_to_integer by default.
This diagnostic seems to be production ready, it's just an oversight that it
wasn't turned on by default.

The test changes are a bit of a mixed bag. Some tests that seemed like they
clearly didn't need to use this behavior have been modified not to use it.
Others that I couldn't be sure about, I added the necessary expected-warnings
to.

It's possible the diagnostic message could be improved to make it clearer that
this warning can be suppressed by using a value that won't lose precision when
converted to the target type (but can still be a floating point literal, such
as "bool b = 1.0;").

llvm-svn: 154068
2012-04-05 00:16:44 +00:00
Ted Kremenek dc53f0094b Look through chains of 'x = y = z' when employing silencing heuristics in the DeadStoresChecker.
Fixes <rdar://problem/11185138>.

llvm-svn: 154040
2012-04-04 19:58:03 +00:00
Ted Kremenek 5a10f08b52 Include the "issue context" (e.g. function or method) where a static analyzer issue occurred in the plist output.
Fixes <rdar://problem/11004527>

llvm-svn: 154030
2012-04-04 18:11:35 +00:00
Anna Zaks cc24e45e27 [analyzer] Record the basic blocks covered by the analyzes run.
Store this info inside the function summary generated for all analyzed
functions. This is useful for coverage stats and can be helpful for
analyzer state space search strategies.

llvm-svn: 153923
2012-04-03 02:05:47 +00:00
Ted Kremenek b75f4e5e9b Fix another false positive in RegionStore involving doing loads from symbolic offsets. We still don't
properly reason about such accesses, but we shouldn't emit bogus "uninitialized value" warnings
either.  Fixes <rdar://problem/11127008>.

llvm-svn: 153913
2012-04-03 00:03:34 +00:00
Anna Zaks 90ab9bfa11 [analyzer]Malloc,RetainRelease: Allow pointer to escape via NSMapInsert.
Fixes a false positive (radar://11152419). The current solution of
adding the info into 3 places is quite ugly. Pending a generic pointer
escapes callback.

llvm-svn: 153731
2012-03-30 05:48:16 +00:00
Anna Zaks 7e3e06a837 [analyzer] Add a malloc cpp test file.
Includes a test from a reported false positive fixed in some earlier
commit.

llvm-svn: 153702
2012-03-29 23:26:54 +00:00
Anna Zaks 72eee39df7 [analyzer] Enable retry exhausted without inlining by default.
llvm-svn: 153591
2012-03-28 19:59:16 +00:00
Anna Zaks 5b3939fae6 [analyzer] Add an option to re-analyze a dead-end path without inlining.
The analyzer gives up path exploration under certain conditions. For
example, when the same basic block has been visited more than 4 times.
With inlining turned on, this could lead to decrease in code coverage.
Specifically, if we give up inside the inlined function, the rest of
parent's basic blocks will not get analyzed.

This commit introduces an option to enable re-run along the failed path,
in which we do not inline the last inlined call site. This is done by
enqueueing the node before the processing of the inlined call site
with a special policy encoded in the state. The policy tells us not to
inline the call site along the path.

This lead to ~10% increase in the number of paths analyzed. Even though
we expected a much greater coverage improvement. 

The option is turned off by default for now.

llvm-svn: 153534
2012-03-27 20:02:53 +00:00
Ted Kremenek e9a5bcf17e Change RetainCountChecker to eagerly "escape" retained objects when they are
assigned to a struct.  This is fallout from inlining results, which expose
far more patterns where people stuff CF objects into structs and pass them
around (and we can reason about it).  The problem is that we don't have
a general way to detect when values have escaped, so as an intermediate step
we need to eagerly prune out such tracking.

Fixes <rdar://problem/11104566>.

llvm-svn: 153489
2012-03-27 01:12:45 +00:00
Anna Zaks a651c4099d [analyzer] Malloc: Allow a pointer to escape through OSAtomicEnqueue.
llvm-svn: 153453
2012-03-26 18:18:39 +00:00
Ted Kremenek 161046edab Avoid applying retain/release effects twice in RetainCountChecker when a function call was inlined (i.e., we do not need to apply summaries in such cases).
llvm-svn: 153309
2012-03-23 06:26:56 +00:00
Ted Kremenek 30de950bba Fix static analyzer crash on code taking the address of a field. Fixes PR 11146.
llvm-svn: 153283
2012-03-22 21:42:31 +00:00
Ted Kremenek 40c13431aa "Teach" RetainCountChecker about dispatch_set_context, which can indirectly free its argument later. Fixes <rdar://problem/11059275>.
llvm-svn: 153244
2012-03-22 06:29:41 +00:00
Anna Zaks 9fe8098e29 [analyzer] Malloc: drop symbols captured by blocks.
llvm-svn: 153232
2012-03-22 00:57:20 +00:00
Anna Zaks fc2e153444 [analyzer] Malloc: Utter the name of the leaked variable.
Specifically, we use the last store of the leaked symbol in the leak diagnostic.
(No support for struct fields since the malloc checker doesn't track those
yet.)

+ Infrastructure to track the regions used in store evaluations.
This approach is more precise than iterating the store to
obtain the region bound to the symbol, which is used in RetainCount
checker. The region corresponds to what is uttered in the code in the
last store and we do not rely on the store implementation to support
this functionality.

llvm-svn: 153212
2012-03-21 19:45:08 +00:00
Anna Zaks d42e828720 [analyzer] Re-enable the test disabled by r152969.
(The fix was committed in r152982.)

llvm-svn: 153210
2012-03-21 19:44:57 +00:00
Ted Kremenek 230e015b90 Add test case for <rdar://problem/10553686>, which illustrates RetainCount checker working with inlined C++ template functions.
llvm-svn: 153069
2012-03-20 00:10:35 +00:00
Jordy Rose bf38f20e79 [analyzer] Mark a failed-realloc's result as an interesting symbol between the realloc call and the null check, so we get nicer path notes. Fixes a regression introduced by the diagnostic pruning added in r152361.
This is accomplished by calling markInteresting /during/ path diagnostic generation, and as such relies on deterministic ordering of BugReporterVisitors -- namely, that BugReporterVisitors are run in /reverse/ order from how they are added. (Right now that's a consequence of storing visitors in an ImmutableList, where new items are added to the front.) It's a little hacky, but it works for now.

I think this is the best we can do without storing the relation between the old and new symbols, and that would be a hit whether or not there ends up being an error.

llvm-svn: 153010
2012-03-18 07:43:35 +00:00
Jordy Rose 78373e505d [analyzer] Don't claim an object was returned with +1 retain count before counting autoreleases. Fixes PR10376.
(Also, 80-column violations.)

llvm-svn: 152976
2012-03-17 05:49:15 +00:00
Jordy Rose 914e81ad94 [analyzer] Add test case from PR10794 for using 'new' with Obj-C objects.
llvm-svn: 152975
2012-03-17 03:53:59 +00:00
Anna Zaks ce690f4b24 [analyzer] This test is breaking windows bots, make it darwin-specific.
(The plist output does not match the one we expect, specifically we do
not detect that the interesting symbol is returned by a call.)

llvm-svn: 152969
2012-03-17 01:53:32 +00:00
Anna Zaks a7f457a5ea [analyzer] Shorten the stack hint diagnostic.
Do not display the standard "Returning from 'foo'", when a stack hint is
available.

llvm-svn: 152964
2012-03-16 23:44:28 +00:00
Anna Zaks cba4f298c6 [analyzer] Create symbol-aware stack hints (building upon r152837).
The symbol-aware stack hint combines the checker-provided message
with the information about how the symbol was passed to the callee: as
a parameter or a return value.

For malloc, the generated messages look like this :
"Returning from 'foo'; released memory via 1st parameter"
"Returning from 'foo'; allocated memory via 1st parameter"
"Returning from 'foo'; allocated memory returned"
"Returning from 'foo'; reallocation of 1st parameter failed"


(We are yet to handle cases when the symbol is a field in a struct or
an array element.)

llvm-svn: 152962
2012-03-16 23:24:20 +00:00
Ted Kremenek b1279b5c47 Fix analyzer crash on analyzing 'catch' with no condition variable.
llvm-svn: 152900
2012-03-16 05:58:15 +00:00
Ted Kremenek c0d0d35117 Add test case for <rdar://problem/8808566>, which is now fixed by inlining support.
llvm-svn: 152894
2012-03-16 04:59:57 +00:00
Ted Kremenek d52efc8fd6 Include full plist output in FileCheck test.
llvm-svn: 152859
2012-03-15 22:14:09 +00:00
Ted Kremenek 1bdc2f41f9 Include full plist output in FileCheck test.
llvm-svn: 152858
2012-03-15 22:00:28 +00:00
Ted Kremenek 3a21f8bb3d Do not truncate expected plist output in FileCheck test.
llvm-svn: 152857
2012-03-15 21:55:38 +00:00
Anna Zaks 1ff57d57e8 [analyzer] Allow checkers to supply call stack diagnostic hints for the
BugVisitor DiagnosticPieces.

When checkers create a DiagnosticPieceEvent, they can supply an extra
string, which will be concatenated with the call exit message for every
call on the stack between the diagnostic event and the final bug report.
(This is a simple version, which could be/will be further enhanced.)

For example, this is used in Malloc checker to produce the ",
which allocated memory" in the following example:

static char *malloc_wrapper() { // 2. Entered call from 'use'
    return malloc(12);    // 3. Memory is allocated
}

void use() {
    char *v;
    v = malloc_wrapper(); // 1. Calling 'malloc_wrappers'
        // 4. Returning from 'malloc_wrapper', which allocated memory
}                         // 5. Memory is never released; potential
memory leak

llvm-svn: 152837
2012-03-15 21:13:02 +00:00
David Blaikie ebcbe4b6aa Reapply r152745 (reverted in 152765) now that compiler-rt is fixed.
Original commit message:

Provide -Wnull-conversion separately from -Wconversion.

Like GCC, provide a NULL conversion to non-pointer conversion as a separate
flag, on by default. GCC's flag is "conversion-null" which we provide for
cross compatibility, but in the interests of consistency (with
-Wint-conversion, -Wbool-conversion, etc) the canonical Clang flag is called
-Wnull-conversion.

Patch by Lubos Lunak.
Review feedback by myself, Chandler Carruth, and Chad Rosier.

llvm-svn: 152774
2012-03-15 04:50:32 +00:00
Chad Rosier 2860fbb747 Revert r152745 as it's breaking the internal buildbots.
Abbreviated commit message:
Provide -Wnull-conversion separately from -Wconversion.

llvm-svn: 152765
2012-03-15 01:00:38 +00:00
David Blaikie 1ce8dbb93f Provide -Wnull-conversion separately from -Wconversion.
Like GCC, provide a NULL conversion to non-pointer conversion as a separate
flag, on by default. GCC's flag is "conversion-null" which we provide for
cross compatibility, but in the interests of consistency (with
-Wint-conversion, -Wbool-conversion, etc) the canonical Clang flag is called
-Wnull-conversion.

Patch by Lubos Lunak.
Review feedback by myself, Chandler Carruth, and Chad Rosier.

llvm-svn: 152745
2012-03-14 22:28:22 +00:00
Anna Zaks d4e9059fe0 [analyzer] Diagnostics: Supply Caller information even if the bug occurs
in the callee.

llvm-svn: 152734
2012-03-14 18:58:28 +00:00
Erik Verbruggen 5923cbd27b [Analyser] Remove unnecessary recursive visits for ExprWithCleanups and
MaterializeTemporaryExpr.

llvm-svn: 152730
2012-03-14 18:01:43 +00:00
Anna Zaks 6e5b48a6b4 [analyzer] Call enter/exit diagnostic should refer to caller/callee,
respectively.

llvm-svn: 152676
2012-03-13 22:15:55 +00:00
Anna Zaks 943c680605 [analyzer] Change the order in which we analyze the functions under
inlining to be the reverse of their declaration.

This optimizes running time under inlining up to 20% since we do not
re-analyze the utility functions which are usually defined first in the
translation unit if they have already been analyzed while inlined into
the root functions.

llvm-svn: 152653
2012-03-13 19:32:19 +00:00
Anna Zaks 1418951405 [analyzer] Use recursive AST visitor to drive simple visitation order in
AnalysisConsumer.

As a result:
 - We now analyze the C++ methods which are defined within the
class body. These were completely skipped before.

- Ensure that AST checkers are called on functions in the
order they are defined in the Translation unit.

llvm-svn: 152650
2012-03-13 19:32:00 +00:00
Ted Kremenek 487cdbfdb0 [analyzer] Include inlining call stack depth in plist output.
llvm-svn: 152584
2012-03-12 22:10:57 +00:00
Ted Kremenek 8fdb59f979 [analyzer] fix regression in analyzer of NOT actually aborting on Stmts it doesn't understand. We registered
as aborted, but didn't treat such cases as sinks in the ExplodedGraph.

Along the way, add basic support for CXXCatchStmt, expanding the set of code we actually analyze (hopefully correctly).

Fixes: <rdar://problem/10892489>
llvm-svn: 152468
2012-03-10 01:34:17 +00:00
Ted Kremenek 33be12003f Teach RetainCountChecker about mixing method families with explicit annotations. Fixes <rdar://problem/10824732>.
llvm-svn: 152448
2012-03-09 23:34:08 +00:00
Ted Kremenek 1e809b4c4c [analyzer] Implement basic path diagnostic pruning based on "interesting" symbols and regions.
Essentially, a bug centers around a story for various symbols and regions.  We should only include
the path diagnostic events that relate to those symbols and regions.

The pruning is done by associating a set of interesting symbols and regions with a BugReporter, which
can be modified at BugReport creation or by BugReporterVisitors.

This patch reduces the diagnostics emitted in several of our test cases.  I've vetted these as
having desired behavior.  The only regression is a missing null check diagnostic for the return
value of realloc() in test/Analysis/malloc-plist.c.  This will require some investigation to fix,
and I have added a FIXME to the test case.

llvm-svn: 152361
2012-03-09 01:13:14 +00:00
Anna Zaks 0af3e06ff6 [analyzer] Rework inlining related command line options.
- Remove -analyzer-inline-call.
 - Add -analyzer-ipa=[none|inlining]
 - Add -analyzer-inlining-mode to allow experimentation for
different performance tuning methods.

llvm-svn: 152351
2012-03-08 23:16:35 +00:00