Commit Graph

1336 Commits

Author SHA1 Message Date
NAKAMURA Takumi 10cea170d2 clang/test/Analysis/stats.c: Fix up r151656.
llvm-svn: 151695
2012-02-29 02:04:39 +00:00
Anna Zaks 75de32322a [analyzer] Leaks should be uniqued by the allocation point in the
closest function context (RetainCountChecker).

llvm-svn: 151661
2012-02-28 22:39:22 +00:00
Anna Zaks 16f3831064 [analyzer] Retain release: drop the line number info from the leak
message.

llvm-svn: 151657
2012-02-28 21:49:08 +00:00
Anna Zaks b6e2854f68 [analyzer] Stats: Add the stats about remove dead bindings, correct the
test.

llvm-svn: 151656
2012-02-28 21:49:04 +00:00
Anna Zaks 6ca4fd5b88 [analyzer] Leaks should be uniqued by the allocation point in the
closest function context (Keychain API).

llvm-svn: 151613
2012-02-28 03:07:06 +00:00
Anna Zaks 06a77fc1b9 [analyzer] Fix Malloc False Positive (PR 12100)
When allocated buffer is passed to CF/NS..NoCopy functions, the
ownership is transfered unless the deallocator argument is set to
'kCFAllocatorNull'.

llvm-svn: 151608
2012-02-28 01:54:22 +00:00
Ted Kremenek 3bc5372fae [analyzer] teach analyzer about ObjC literals, thus trimming out a false positive with the malloc() checker involving
comparing literal addresses to nil.

Fixes <rdar://problem/10579586>

llvm-svn: 151602
2012-02-28 00:56:05 +00:00
Anna Zaks 43ffba2676 [analyzer] Leaks should be uniqued by the allocation point in the
closest function context. 

This prevents us from uniqueing all leaks from the same allocation
helper. radar://10932226

llvm-svn: 151592
2012-02-27 23:40:55 +00:00
Richard Trieu 9cd797aa3e Fix a test case that was added in r151570. The redirect of output was broken
so no testing was actually done.  Further, the commands produce no output.
The redirection has been fixed and the test has been disabled.

llvm-svn: 151591
2012-02-27 23:40:41 +00:00
Ted Kremenek 59b10db2bc After numerous requests, have Objective-C 'method declared here' notes mention the actual method. This looks better within an IDE, where text isn't always regurgitated in the presentation of a warning. Fixes radar 10914035.
llvm-svn: 151579
2012-02-27 22:55:11 +00:00
Anna Zaks b028654031 [analyzer] Add -analyzer-stats, which hooks up LLVM stats tracking.
As in http://llvm.org/docs/ProgrammersManual.html#Statistic

llvm-svn: 151570
2012-02-27 21:33:16 +00:00
Ted Kremenek ef31f376bb RetainCountChecker: don't adjust the retain count when analyzing a ReturnStmt unless we are in the top-level call frame. We can do more later, but this makes the checker self-consistent (and fixes a crash).
llvm-svn: 151426
2012-02-25 02:09:09 +00:00
Anna Zaks 7ac344a48a [analyzer] Malloc: reason about the ObjC messages and C++.
Assume none of the ObjC messages defined in system headers free memory,
except for the ones containing 'freeWhenDone' selector. Currently, just
assume that the region escapes to the messages with 'freeWhenDone'
(ideally, we want to treat it as 'free()').

For now, always assume that regions escape when passed to C++ methods.

llvm-svn: 151410
2012-02-24 23:56:53 +00:00
Anna Zaks 18de54b1a6 [analyzer] Run remove dead bindings before each call.
This ensures that we report the bugs associated with symbols going
out of scope in the correct function context.

llvm-svn: 151369
2012-02-24 16:49:46 +00:00
Anna Zaks cdf24a9a5e [analyzer] We were silently stopping exploring the path after
visiting 'return;' statement!

This most likely caused us to skip a bunch of code when analyzing with
inlining.

llvm-svn: 151368
2012-02-24 16:49:41 +00:00
Ted Kremenek 1bf3b04726 Make PathDiagnosticBuilder sensitive to varying LocationContexts, thus fixing a bug in the inlining diagnostics where the wrong location could be used.
llvm-svn: 151349
2012-02-24 07:12:52 +00:00
Ted Kremenek 29cebb377d Remove stray path in test file.
llvm-svn: 151347
2012-02-24 06:01:01 +00:00
Ted Kremenek 60a7820ffe Reapply r151317, but when computing the PathDiagnostic profile and size keep into account the nested structure. Also fix a problem with how
inlining impacted Plist diagnostics, and adjust some ranges in the Plist output due to richer information.

llvm-svn: 151346
2012-02-24 06:00:00 +00:00
Anna Zaks 4b062cb904 [analyzer] KeyChainAPI: unique the leaks by allocation site.
(Very similar to the previous change in malloc.)

llvm-svn: 151297
2012-02-23 22:53:29 +00:00
Fariborz Jahanian 86f8266b9f objective-c++: Type of an objc string literal is NSString, not 'id'.
// rdar://10907410

llvm-svn: 151296
2012-02-23 22:51:36 +00:00
Anna Zaks df901a4419 [analyzer] Malloc: unique leak reports by allocation site.
When we find two leak reports with the same allocation site, report only
one of them.

Provide a helper method to BugReporter to facilitate this.

llvm-svn: 151287
2012-02-23 21:38:21 +00:00
Anna Zaks 07de9c12f3 [analyzer] Invalidate the region passed to pthread_setspecific() call.
Make this call an exception in ExprEngine::invalidateArguments:
'int pthread_setspecific(ptheread_key k, const void *)' stores
a value into thread local storage. The value can later be retrieved
with 'void *ptheread_getspecific(pthread_key)'. So even thought the
parameter is 'const void *', the region escapes through the
call.

(Here we just blacklist the call in the ExprEngine's default
logic. Another option would be to add a checker which evaluates
the call and triggers the call to invalidate regions.)

Teach the Malloc Checker, which treats all system calls as safe about
the API.

llvm-svn: 151220
2012-02-23 01:05:27 +00:00
Anna Zaks 40a7eb3837 [analyzer] Malloc cleanup:
- We should not evaluate strdup in the Malloc Checker, it's the job of
CString checker, so just update the RefState to reflect allocated
memory.

- Refactor to reduce LOC: remove some wrapper auxiliary functions, make
all functions return the state and add the transition in one place
(instead of in each auxiliary function).

llvm-svn: 151188
2012-02-22 19:24:52 +00:00
Anna Zaks 199e8e585b [analyzer] Malloc checker: mark 'strdup' and 'strndup' as allocators.
llvm-svn: 151124
2012-02-22 03:14:20 +00:00
Anna Zaks 4ca45b1d00 [analyzer] Malloc: fix another false positive.
, when we return a symbol reachable to the malloced one via pointer
arithmetic.

llvm-svn: 151121
2012-02-22 02:36:01 +00:00
Anna Zaks 3705a1ee10 [analyzer] Change naming in bug reports "tainted" -> "untrusted"
llvm-svn: 151120
2012-02-22 02:35:58 +00:00
Ted Kremenek b14b42d477 Have ScanReachableSymbols reported reachable regions. Fixes a false positive with nested array literals. <rdar://problem/10686586>
llvm-svn: 151012
2012-02-21 00:46:29 +00:00
Anna Zaks 3508a00543 [analyzer] + a couple more malloc tests.
llvm-svn: 151008
2012-02-21 00:00:48 +00:00
Anna Zaks 19a66678d5 [analyzer] Make KeyChainAPI checker inlining-aware.
llvm-svn: 151007
2012-02-21 00:00:44 +00:00
Anna Zaks 1526881ee0 [analyzer] Make Malloc aware of inter-procedural execution + basic
tests.

llvm-svn: 150993
2012-02-20 22:25:23 +00:00
Anna Zaks 0cdce4df76 [analyzer] Turn on by default the Malloc Checker and a couple of CString
checks:

- unix.Malloc - Checks for memory leaks, double free, use-after-free.
- unix.cstring.NullArg - Checks for null pointers passed as arguments to
CString functions + evaluates CString functions.
- unix.cstring.BadSizeArg - Checks for common anti-patterns in
strncat size argument.

llvm-svn: 150988
2012-02-20 21:10:37 +00:00
Ted Kremenek 1c95ef4e94 Teach analyzer that blocks with no captures are globals. Fixes <rdar://problem/10348049>.
llvm-svn: 150896
2012-02-18 22:41:01 +00:00
Ted Kremenek b0d37508d0 Fix crash in analyzer diagnostic generation involving subexpressions of OpaqueValueExpr not appearing in the ParentMap. Fixes <rdar://problem/10797980>.
llvm-svn: 150894
2012-02-18 22:02:57 +00:00
Ted Kremenek e8a5ba89ec Teach analyzer about NSAutoreleasePool -allocWithZone:. Fixes <rdar://problem/10640253>.
llvm-svn: 150892
2012-02-18 21:37:48 +00:00
Ted Kremenek 3d64453f9d Add analyzer test for using of C++ references with ObjC object pointers, reported in <rdar://problem/10569024>.
llvm-svn: 150891
2012-02-18 21:27:25 +00:00
Ted Kremenek e98d63a823 Adopt ExprEngine and checkers to ObjC property refactoring. Everything was working, but now diagnostics are aware of message expressions implied by uses of properties. Fixes <rdar://problem/9241180>.
llvm-svn: 150888
2012-02-18 20:53:30 +00:00
Anna Zaks 1fdedc99f2 [analyzer] Malloc Checker more tests.
llvm-svn: 150847
2012-02-17 22:35:34 +00:00
Anna Zaks e56167e8f8 [analyzer] Fix another false positive in the Malloc Checker, by making
it aware of CString APIs that return the input parameter.

Malloc Checker needs to know how the 'strcpy' function is
evaluated. Introduce the dependency on CStringChecker for that.
CStringChecker knows all about these APIs.

Addresses radar://10864450

llvm-svn: 150846
2012-02-17 22:35:31 +00:00
Anna Zaks 33c364b12b [analyzer] MallocChecker: more tests.
llvm-svn: 150734
2012-02-16 22:26:15 +00:00
Anna Zaks 546c49c3b2 [analyzer] Malloc Checker: Clean up bug naming:
- Rename the category "Logic Error" -> "Memory Error".
 - Shorten all the messages.

llvm-svn: 150733
2012-02-16 22:26:12 +00:00
Anna Zaks 9eb7bc82ae [analyzer] Malloc Checker: Make the diagnostic visitor handle the case
of failing realloc. + Minor cleanups.

llvm-svn: 150732
2012-02-16 22:26:07 +00:00
Sebastian Redl 6047f07e81 Revert "Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.""
This reintroduces commit r150682 with a fix for the Bullet benchmark crash.

llvm-svn: 150685
2012-02-16 12:22:20 +00:00
Sebastian Redl c3a3c60040 Revert "Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself."
It leads to a compiler crash in the Bullet benchmark.

This reverts commit r12014.

llvm-svn: 150684
2012-02-16 11:35:52 +00:00
Sebastian Redl 86fab844bb Make CXXNewExpr contain only a single initialier, and not hold the used constructor itself.
Holding the constructor directly makes no sense when list-initialized arrays come into play. The constructor is now held in a CXXConstructExpr, if construction is what is done. The new design can also distinguish properly between list-initialization and direct-initialization, as well as implicit default-initialization constructors and explicit value-initialization constructors. Finally, doing it this way removes redundance from the AST because CXXNewExpr doesn't try to handle both the allocation and the initialization responsibilities.

This breaks the static analysis of new expressions. I've filed PR12014 to track this.

llvm-svn: 150682
2012-02-16 10:58:10 +00:00
Anna Zaks 95308d3798 [analyzer] Diagnostics: Ensure that the default end of diagnostic path
piece can always be generated.

The default end of diagnostic path piece was failing to generate on a
BlockEdge that was outgoing from a basic block without a terminator,
resulting in a very simple diagnostic being rendered (ex: no path
highlighting or custom visitors). Reuse another function, which is
essentially doing the same thing and correct it not to fail when a block
has no terminator.

llvm-svn: 150659
2012-02-16 03:41:01 +00:00
Anna Zaks d32ead82d9 [analyzer] Malloc Checker: Give up when a pointer escapes into a struct.
We are not properly handling the memory regions that escape into struct
fields, which led to a bunch of false positives. Be conservative here
and give up when a pointer escapes into a struct.

llvm-svn: 150658
2012-02-16 03:40:57 +00:00
Anna Zaks 5a6213d22b [analyzer] Malloc Checker: Add another false positive as a todo test.
llvm-svn: 150534
2012-02-15 00:11:28 +00:00
Anna Zaks ac06814d2f [analyzer] Malloc Checker: add support for reallocf, which always frees
the passed in pointer on failure.

llvm-svn: 150533
2012-02-15 00:11:25 +00:00
Anna Zaks d51574850e [analyzer] Malloc Checker: add support for valloc + minor code
hardening.

llvm-svn: 150532
2012-02-15 00:11:22 +00:00
Dmitri Gribenko 800ddf3dda Generalize -Wempty-body: warn when statement body is empty (closes: PR11329)
* if, switch, range-based for: warn if semicolon is on the same line.
* for, while: warn if semicolon is on the same line and either next
statement is compound statement or next statement has more
indentation.

Replacing the semicolon with {} or moving the semicolon to the next
line will always silence the warning.

Tests from SemaCXX/if-empty-body.cpp merged into SemaCXX/warn-empty-body.cpp.

llvm-svn: 150515
2012-02-14 22:14:32 +00:00