Commit Graph

81 Commits

Author SHA1 Message Date
Jordan Rose 2da564380a [analyzer] Always derive a CallEvent's return type from its origin expr.
Previously, we preferred to get a result type by looking at the callee's
declared result type. This allowed us to handlereferences, which are
represented in the AST as lvalues of their pointee type. (That is, a call
to a function returning 'int &' has type 'int' and value kind 'lvalue'.)

However, this results in us preferring the original type of a function
over a casted type. This is a problem when a function  pointer is casted
to another type, because the conjured result value will have the wrong
type. AdjustedReturnValueChecker is supposed to handle this, but still
doesn't handle the case where there is no "original function" at all,
i.e. where the callee is unknown.

Now, we instead look at the call expression's value kind (lvalue, xvalue,
or prvalue), and adjust the expr's type accordingly. This will have no
effect when the function is inlined, and will conjure the value that will
actually be used when it is not.

This makes AdjustedReturnValueChecker /nearly/ unnecessary; unfortunately,
the cases where it would still be useful are where we need to cast the
result of an inlined function or a checker-evaluated function, and in these
cases we don't know what we're casting /from/ by the time we can do post-
call checks. In light of that, remove AdjustedReturnValueChecker, which
was already not checking quite a few calls.

llvm-svn: 163065
2012-09-01 17:39:00 +00:00
Ted Kremenek 7c65b8f22a Rename the "experimental" checker package to "alpha". We will then refine
this group into "alpha" and "beta" to distinguish between checkers in
different levels of premature state.

llvm-svn: 162582
2012-08-24 19:46:03 +00:00
Anna Zaks 5a5a1755f2 [analyzer] Add osx.cocoa.NonNilReturnValue checker.
The checker adds assumptions that the return values from the known APIs
are non-nil. Teach the checker about NSArray/NSMutableArray/NSOrderedSet
objectAtIndex, objectAtIndexedSubscript.

llvm-svn: 162398
2012-08-22 21:19:56 +00:00
Anna Zaks 472dbcf156 [analyzer] Add a checker to manage dynamic type propagation.
Instead of sprinkling dynamic type info propagation throughout
ExprEngine, the added checker would add the more precise type
information on known APIs (Ex: ObjC alloc, new) and propagate
the type info in other cases (ex: ObjC init method, casts (the second is
not implemented yet)).

Add handling of ObjC alloc, new and init to the checker.

llvm-svn: 161357
2012-08-06 23:25:39 +00:00
Ted Kremenek b1fcddfc6a Remove experimental invalid iterators checker from the codebase until we have the time
to fix all the issues.  Currently the code is essentially unmaintained and buggy, and
needs major revision (with coupled enhancements to the analyzer core).

llvm-svn: 160754
2012-07-25 20:02:05 +00:00
Jordan Rose 8889cf008d [analyzer] Add debug.DumpCalls, which prints out any CallEvents it sees.
This is probably not so useful yet because it is not path-sensitive, though
it does try to show inlining with indentation.

This also adds a dump() method to CallEvent, which should be useful for
debugging.

llvm-svn: 160030
2012-07-10 23:56:23 +00:00
Jordan Rose 42ee04d00a [analyzer] Add a test that we are, in fact, doing a DFS on the ExplodedGraph.
Previously:
...the comment said DFS...
...the WorkList being instantiated said BFS...
...and the implementation was actually DFS...
...due to an unintentional change in 2010...
...and everything kept working anyway.

This fixes our std::deque implementation of BFS, but switches back to a
SmallVector-based implementation of DFS.

We should probably still investigate the ramifications of DFS vs. BFS,
especially for large functions (and especially when we hit our block path
limit), since this might completely change our memory use. It can also mask
some bugs and reveal others depending on when we halt analysis. But at least
we will not have this kind of little mistake creep in again.

llvm-svn: 159397
2012-06-29 00:33:10 +00:00
Jordan Rose efef760214 [analyzer] Add ObjCLoopChecker: objects from NSArray et al are non-nil.
While collections containing nil elements can still be iterated over in an
Objective-C for-in loop, the most common Cocoa collections -- NSArray,
NSDictionary, and NSSet -- cannot contain nil elements. This checker adds
that assumption to the analyzer state.

This was the cause of some minor false positives concerning CFRelease calls
on objects in an NSArray.

llvm-svn: 158319
2012-06-11 16:40:41 +00:00
Anna Zaks 6b7b7e66d1 [analyzer] Minor cleanup to checkers' help text.
llvm-svn: 157402
2012-05-24 17:31:59 +00:00
Jordy Rose 31ae259a41 [analyzer] Introduce clang_analyzer_eval for regression test constraint checks.
The new debug.ExprInspection checker looks for calls to clang_analyzer_eval,
and emits a warning of TRUE, FALSE, or UNKNOWN (or UNDEFINED) based on the
constrained value of its (boolean) argument. It does not modify the analysis
state though the conditions tested can result in branches (e.g. through the
use of short-circuit operators).

llvm-svn: 156919
2012-05-16 16:01:07 +00:00
Anna Zaks 590c7bc12e [analyzer]Turn on MallocSizeOfChecker by default; shorten the diagnostic
llvm-svn: 156341
2012-05-07 23:30:29 +00:00
Anna Zaks c000e7ed3d Add a basic CallGraph to Analysis.
The final graph contains a single root node, which is a parent of all externally available functions(and 'main'). As well as a list of Parentless/Unreachable functions, which are either truly unreachable or are unreachable due to our analyses imprecision.

The analyzer checkers debug.DumpCallGraph or debug.ViewGraph can be used to look at the produced graph.

Currently, the graph is not very precise, for example, it entirely skips edges resulted from ObjC method calls.

llvm-svn: 152272
2012-03-08 00:42: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
Ryan Govostes 55011c017c [analyzer] New checker for assignment of non-0/1 values to Boolean variables.
llvm-svn: 150306
2012-02-11 16:32:09 +00:00
Anna Zaks cd37bf4ec8 [analyzer] Split the MallocChecker into two versions - pessimistic and
optimistic.

TODO: actually implement the pessimistic version of the checker. Ex: it
needs to assume that any function that takes a pointer might free it.

The optimistic version relies on annotations to tell us which functions
can free the pointer.

llvm-svn: 150111
2012-02-08 23:16:52 +00:00
Anna Zaks e0c7c27473 [analyzer] Allow each CString check to be enabled/disabled
separately.

llvm-svn: 149947
2012-02-07 00:56:14 +00:00
Anna Zaks 8e009df96e [analyzer] Turn on by default two checkers:
- osx.coreFoundation.containers.IndexOutOfBounds
 - osx.cocoa.SelfInit

llvm-svn: 149747
2012-02-04 02:31:57 +00:00
Anna Zaks 87b6ff09f9 [analyzer] Add checks for common anti-patterns in strncat.
(Since this is syntax only, might be a good candidate for turning into a
compiler warning.)

llvm-svn: 149407
2012-01-31 19:33:39 +00:00
Anna Zaks 58cc6cabe5 [analyzer] Rename the checker as per Ted's comment. Remove the reference
from the driver.

llvm-svn: 149276
2012-01-30 21:14:16 +00:00
Anna Zaks 6523e46941 [analyzer] Make osx.cocos.CFContainersSyntax a default checker.
llvm-svn: 149258
2012-01-30 19:12:37 +00:00
Anna Zaks 4f870e652a [analyzer] Add index out of bounds check for CFArrayGetArrayAtIndex.
llvm-svn: 149228
2012-01-30 06:42:48 +00:00
Anna Zaks 06f10bf05a [analyzer] Add an AST checker that checks for a common pitfall when
using CFArrayCreate & family.

Specifically, CFArrayCreate's input should be:
'A C array of the pointer-sized values to be in the new array.'

(radar://10717339)

llvm-svn: 149008
2012-01-26 01:05:43 +00:00
Ted Kremenek b9ff6b2302 Reenable DeadStoresChecker under --analyze, and move the IdempotentOperationsChecker to the 'experimental' category. Fixes <rdar://problem/10146347>.
llvm-svn: 148533
2012-01-20 06:00:17 +00:00
Ted Kremenek 89eaf8d531 Implement checker that looks for calls to mktemps and friends that have fewer than 6 Xs. Implements <rdar://problem/6336672>.
llvm-svn: 148531
2012-01-20 05:35:06 +00:00
Ted Kremenek c54dc9515d Turn 'SecuritySyntaxChecker' into a "meta" security checker for insecure APIs. Now
multiple checks are exposed as separate checkers, but CheckerManager only creates
one Checker object.

llvm-svn: 148525
2012-01-20 01:44:29 +00:00
Ted Kremenek b3512d3a48 Add initial version of checker to check if virtual member functions are called transitively
from C++ constructors or destructors.  Checker by Lei Zhang with a few tweaks by Ted Kremenek.

llvm-svn: 147494
2012-01-03 23:18:57 +00:00
Peter Collingbourne 266e3dda17 Add an experimental MallocSizeofChecker, which reports inconsistencies
between the casted type of the return value of a malloc/calloc/realloc
call and the operand of any sizeof expressions contained within
its argument(s).

llvm-svn: 146144
2011-12-08 08:31:14 +00:00
Anna Zaks 1c215d0a11 [analyzer] Add a debug checker to test for tainted data.
llvm-svn: 145827
2011-12-05 18:58:01 +00:00
Anna Zaks 5c5bf9b634 [analyzer] Adding generic taint checker.
The checker is responsible for defining attack surface and adding taint to symbols.

llvm-svn: 144825
2011-11-16 19:58:13 +00:00
Anna Zaks 62c650f477 [analyzer] There should be a space between "expect" and "only"
llvm-svn: 143787
2011-11-05 05:20:51 +00:00
Ted Kremenek 0062e74961 Add source-level dominators analysis. Patch by Guoping Long!
llvm-svn: 142885
2011-10-25 00:25:24 +00:00
Jordy Rose c49ec53e29 [analyzer] Move the knowledge of whether or not GC is enabled for the current analysis from CFRefCount to ExprEngine.
Remove TransferFuncs from ExprEngine and AnalysisConsumer.

Demote RetainReleaseChecker to a regular checker, and give it the name osx.cocoa.RetainCount (class name change coming shortly). Update tests accordingly.

llvm-svn: 138998
2011-09-02 05:55:19 +00:00
Anna Zaks a06421a02c MacOSKeychainAPIChecker: Turn it on by default.
llvm-svn: 137740
2011-08-16 20:02:05 +00:00
Ted Kremenek 907377e303 [analyzer] Remove 'all-experimental' checker group.
llvm-svn: 136849
2011-08-04 00:25:50 +00:00
Ted Kremenek 3f955e6d89 [analyzer] rename all experimental checker packages to have 'experimental' be the common root package.
llvm-svn: 136835
2011-08-03 23:14:55 +00:00
Ted Kremenek 1c2fb270ce [analyzer] Introduce MallocOverflowSecurityChecker, a simple flow-sensitive checker that may be useful for security auditing. This checker is currently too noisy to be on by default.
llvm-svn: 136804
2011-08-03 20:17:43 +00:00
Anna Zaks 9ab728bb05 KeychainAPI checker: only check the paths on which the allocator function returned noErr. (+ minor cleanup)
llvm-svn: 136694
2011-08-02 17:11:03 +00:00
Anna Zaks 15f496c118 Add a skeleton for the Keychain Services API Checker. Register it as OSX experimental for now. Note, the checker still does not handle tracking of escaped values, taking into account the return value of the allocator functions, nor the actual bug reporting..
llvm-svn: 136659
2011-08-01 22:40:01 +00:00
Jordy Rose bc7483f505 [analyzer] CStringChecker checks functions in the C standard library, not C++. Its external name is now unix.experimental.CString.
llvm-svn: 132958
2011-06-14 01:40:43 +00:00
Ted Kremenek 8067746554 Move the SelfInit checker to the 'cocoa.experimental' package.
llvm-svn: 130598
2011-04-30 06:46:45 +00:00
Argyrios Kyrtzidis 4ee039647a [analyzer] Checker Packages can now belong to a group. This requires llvm commit r128474.
llvm-svn: 128475
2011-03-29 18:54:02 +00:00
Ted Kremenek 104f6dfd1f Tweak grammar in checker description.
llvm-svn: 128310
2011-03-26 00:25:42 +00:00
Ted Kremenek 49c79790de Rework checker "packages" and groups to be more hierarchical.
llvm-svn: 128187
2011-03-24 00:28:47 +00:00
Anders Carlsson d91d5f162f Add an Objective-C checker that checks that arguments passed to some variadic Objective-C methods are of Objective-C pointer types.
Ted or Argiris, I'd appreciate a review!

llvm-svn: 127572
2011-03-13 20:35:21 +00:00
Ted Kremenek a4a57c10da Re-enable the IdempotentOperations checker for --analyze, and put it and the DeadStores checker into the "deadcode" group.
llvm-svn: 127531
2011-03-12 06:14:28 +00:00
Ted Kremenek f89710b936 Add initial version of "IteratorsChecker", a checker to find misues uses of C++ iterators.
This checker was created by Jim Goodnow II, and I migrated it to the
new Checker interface (recent changes by Argiris).

llvm-svn: 127525
2011-03-12 02:49:15 +00:00
Argyrios Kyrtzidis 2c49ec7f1d [analyzer] Migrate NSErrorChecker and DereferenceChecker to CheckerV2.
They cooperate in that NSErrorChecker listens for ImplicitNullDerefEvent events that
DereferenceChecker can dispatch.
ImplicitNullDerefEvent is when we dereferenced a location that may be null.

llvm-svn: 126659
2011-02-28 17:36:18 +00:00
Argyrios Kyrtzidis 6d6801c5c7 [analzyer] Migrate CallAndMessageChecker to CheckerV2.
llvm-svn: 126626
2011-02-28 01:28:13 +00:00
Argyrios Kyrtzidis 0a5a41d799 [analyzer] Migrate AdjustedReturnValueChecker to CheckerV2.
llvm-svn: 126624
2011-02-28 01:28:05 +00:00
Argyrios Kyrtzidis 6fff2e3d36 [analyzer] Migrate AttrNonNullChecker to CheckerV2.
llvm-svn: 126623
2011-02-28 01:28:01 +00:00