Commit Graph

637 Commits

Author SHA1 Message Date
Anna Zaks ee1a43533b [analyzer] Refactor: Move symbol_iterator from SVal to SymExpr, use it
for finding dependent symbols for taint.

llvm-svn: 145986
2011-12-06 23:12:33 +00:00
Anna Zaks c25efccc8b [analyzer] Propagate taint through NonLoc to NonLoc casts.
- Created a new SymExpr type - SymbolCast.
 - SymbolCast is created when we don't know how to simplify a NonLoc to
NonLoc casts.
 - A bit of code refactoring: introduced dispatchCast to have better
code reuse, remove a goto.
 - Updated the test case to showcase the new taint flow.

llvm-svn: 145985
2011-12-06 23:12:27 +00:00
Anna Zaks 8629c0a4d0 [analyzer] Remove an unnecessary check.
llvm-svn: 145984
2011-12-06 23:12:17 +00:00
Anna Zaks 02a1fc1da6 [analyzer] Rely on LLVM Dominators in Clang dominator computation.
(Previously, Clang used it's implementation of dominators.)

The patch is contributed by Guoping Long!

llvm-svn: 145858
2011-12-05 21:33:11 +00:00
Anna Zaks 5c10794254 [analyzer] Mark ConstraintManager::canReasonAbout as protected.
llvm-svn: 145857
2011-12-05 21:33:06 +00:00
Anna Zaks 2d2999821b [analyzer] Simplify the condition.
This is a fixup for r145832.

The extra clauses do not matter after we remove the dependency on canReasonAbout(InitVal) in r145832.

llvm-svn: 145856
2011-12-05 21:33:01 +00:00
Anna Zaks d066f79c80 [analyzer] Unify SymbolVal and SymExprVal under a single SymbolVal
class.

We are going into the direction of handling SymbolData and other SymExpr
uniformly, so it makes less sense to keep two different SVal classes.
For example, the checkers would have to take an extra step to reason
about each type separately.

The classes have the same members, we were just using the SVal kind
field for easy differentiation in 3 switch statements. The switch
statements look more ugly now, but we can make the code more readable in
other ways, for example, moving some code into separate functions.

llvm-svn: 145833
2011-12-05 18:58:30 +00:00
Anna Zaks a636fbe73f [analyzer] Remove all uses of ConstraintManager::canResonAbout() from
ExprEngine.

Teach SimpleConstraintManager::assumeSymRel() to propagate constraints
to symbolic expressions.

+ One extra warning (real bug) is now generated due to enhanced
assumeSymRel().

llvm-svn: 145832
2011-12-05 18:58:25 +00:00
Anna Zaks 51090d5f7f [analyzer] First step toward removing
ConstraintManager::canReasonAbout() from the ExprEngine.

ExprEngine should not care if the constraint solver can reason about
something or not. The solver should be able to handle all the SymExprs.

To do this, the solver should be able to keep track of not only the
SymbolData but of all SymExprs. This is why we change SymbolRef to be an
alias of SymExpr*. When encountering an expression it cannot simplify,
the solver should just add the constraints to it.

llvm-svn: 145831
2011-12-05 18:58:19 +00:00
Anna Zaks 820e87e928 [analyzer] Minor improvements on RangeConstraint pretty-printing.
llvm-svn: 145830
2011-12-05 18:58:14 +00:00
Anna Zaks 223516523e [analyzer] Change RetainCountChecker to use symbol dump method instead
of relying on SymbolID.

This way any expression can be printed (not only SymbolData).

llvm-svn: 145829
2011-12-05 18:58:11 +00:00
Anna Zaks f784d08d25 [analyzer] Add ability to do a simple ProgramState dump() without
requiring CFG.

Adding more ugly code; the evnvironment printing should be moved to
envirnment at some point.

llvm-svn: 145828
2011-12-05 18:58:08 +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 719051e1c6 [analyzer] Make KeychainAPI checker less aggressive. radar://10508828
We trigger an error if free is called after a possibly failed allocation. Do not trigger the error if we know that the buffer is not null.

llvm-svn: 145584
2011-12-01 16:41:58 +00:00
Anna Zaks c6aa531a8f [analyzer] Refactor checkers to use helper function for getting callee Decl and name.
We are getting name of the called function or it's declaration in a few checkers. Refactor them to use the helper function in the CheckerContext. 

llvm-svn: 145576
2011-12-01 05:57:37 +00:00
Ted Kremenek 24fc93a940 When analyzing a C++ method (without a specific caller), assume 'this' is non-null. Fixes <rdar://problem/10508787>.
llvm-svn: 145575
2011-12-01 05:29:42 +00:00
Ted Kremenek 85825aebc9 Further tweak -Wurneachable-code and templates by allowing the warning to run on
explicit template specializations (which represent actual functions somebody wrote).

Along the way, refactor some other code which similarly cares about whether or
not they are looking at a template instantiation.

llvm-svn: 145547
2011-12-01 00:59:17 +00:00
Benjamin Kramer 9ce686e25f Update CMake build.
llvm-svn: 145506
2011-11-30 18:56:24 +00:00
Anna Zaks 92297f9dcc [analyzer] Add checker callback documentation.
llvm-svn: 145495
2011-11-30 17:12:52 +00:00
Ted Kremenek cfe4ff9725 Relax RegionStore to allow loads from CodeTextRegions. Apparently you can actually write code that does this. This seems worthy of a checker, but the StoreManager should handle the memory abstraction without crashing. Fixes PR 11450.
llvm-svn: 145424
2011-11-29 19:39:29 +00:00
Anna Zaks 951d205aec [analyzer] Minor cleanup of SValBuilder: Comments + code reuse.
llvm-svn: 145274
2011-11-28 20:43:37 +00:00
Anna Zaks 457c68726c [analyzer] Warn when non pointer arguments are passed to scanf (only when running taint checker).
There is an open radar to implement better scanf checking as a Sema warning. However, a bit of redundancy is fine in this case.

llvm-svn: 144964
2011-11-18 02:26:36 +00:00
Anna Zaks 040ddfedc0 [analyzer] Do not conjure a symbol when we need to propagate taint.
When the solver and SValBuilder cannot reason about symbolic expressions (ex: (x+1)*y ), the analyzer conjures a new symbol with no ties to the past. This helps it to recover some path-sensitivity. However, this breaks the taint propagation.

With this commit, we are going to construct the expression even if we cannot reason about it later on if an operand is tainted.

Also added some comments and asserts.

llvm-svn: 144932
2011-11-17 23:07:28 +00:00
Anna Zaks 89c00c9d3f [analyzer] Minor tweaks to the ProgramState::isTainted().
llvm-svn: 144928
2011-11-17 22:59:00 +00:00
Anna Zaks af36e9128a [analyzer] Add a helper method.
Naming could be improved.. But we should first rename the classes in the SVal hierarchy.

llvm-svn: 144927
2011-11-17 22:57:01 +00:00
Anna Zaks df6ca9fbee [analysis] Constify CheckerContext.
llvm-svn: 144871
2011-11-17 01:09:19 +00:00
Anna Zaks 871606d8de [analyzer] Put CheckerConext::getCalleeName out of line.
llvm-svn: 144870
2011-11-17 01:09:15 +00:00
Jim Goodnow II 8d21fc8239 Fixed crash with initializer lists and unnamed bitfields in the RegionStore
Manager. Added test to ensure proper binding of initialized values.
This patch fixes PR11249.

llvm-svn: 144831
2011-11-16 20:29:27 +00:00
Benjamin Kramer de2ac70c0a Update CMake build.
llvm-svn: 144829
2011-11-16 20:05:08 +00:00
Anna Zaks 20829c90be [analyzer] Catch the first taint propagation implied buffer overflow.
Change the ArrayBoundCheckerV2 to be more aggressive in reporting buffer overflows
when the offset is tainted. Previously, we did not report bugs when the state was
underconstrained (not enough information about the bound to determine if there is
an overflow) to avoid false positives. However, if we know that the buffer
offset is tainted - comes in from the user space and can be anything, we should
report it as a bug.

+ The very first example of us catching a taint related bug.
This is the only example we can currently handle. More to come...

llvm-svn: 144826
2011-11-16 19:58:17 +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 ec7dc5c137 [analyzer] Adding basic building blocks for taint propagation.
TaintTag.h will contain definitions of different taint kinds and their properties.
TaintManager will be responsible for implementing taint specific operations, storing taint.
ProgramState will provide API to add/remove taint.

llvm-svn: 144824
2011-11-16 19:58:10 +00:00
Anna Zaks 6b1a955130 [analyzer] Cleanup: Null->0, comments.
llvm-svn: 144823
2011-11-16 19:58:05 +00:00
Anna Zaks 3888aa4beb [analyzer] Factor getCalleeName to the checker context.
many checkers are trying to get a name of the callee when visiting
a CallExpr, so provide a convenience API.

llvm-svn: 144820
2011-11-16 19:57:55 +00:00
Ted Kremenek 8e7fbcc3e4 [static analyzer] Tweak RetainCountChecker's diagnostics to correctly indicate if a message was due to a property access. This can
potentially be refactored for other clients, and this is a regression from the refactoring of property acceses.

llvm-svn: 144571
2011-11-14 21:59:21 +00:00
Ted Kremenek 731607fab2 [analyzer;Regionstore] handle loads from StringLiteral elements for StringLiterals representing wide strings. Fixes PR 11294.
llvm-svn: 144563
2011-11-14 20:05:54 +00:00
Ted Kremenek 61fb647fb4 [static analyzer] be more specific when running removeDeadBindings. Instead of seeing if the predecessor node was a non-StmtPoint, check if it is specifically a BlockEntrance node.
llvm-svn: 144340
2011-11-11 00:10:55 +00:00
Ted Kremenek 20be0b4397 [static analyzer]: only call RemoveDeadBindings() when analyzing non-Expr stmts, entering a basic block, or analyzing non-consumed expressions. This sigificantly speeds up analysis time, and reduces analysis time down to 27% less than before we linearized the CFG.
llvm-svn: 144332
2011-11-10 23:26:10 +00:00
Richard Smith d62306a481 Constant expression evaluation: support for evaluation of structs and unions of
literal types, as well as derived-to-base casts for lvalues and
derived-to-virtual-base casts.

llvm-svn: 144265
2011-11-10 06:34:14 +00:00
Anna Zaks 0d58033bdb [analyzer] Remove redundant check from DivZeroChecker
Analysis by Ted:
"
    if (stateZero && !stateNotZero) {

is checking to see if:

  (A)  "it is possible for the value to be zero"   (stateZero)

    AND

  (B) "it is not possible for the value to be non-zero"  (!stateNotZero)

That said, the only way for both B to be true AND A to be false is if the path is completely infeasible by the time we reach the divide-by-zero check.  For the most part (all cases?), such cases should automatically get pruned out at branches (i.e., an infeasible path gets dropped), which is the case in our tests.  So the question is whether or not such an infeasible path might not get dropped earlier?  I can't envision any right now.

Indeed, the rest of the checker assumes that if the bug condition didn't fire then 'stateNotZero' is non-NULL:

    C.addTransition(stateNotZero);
"

llvm-svn: 144114
2011-11-08 19:56:35 +00:00
John McCall ffc8ca2d84 Rip out CK_GetObjCProperty.
llvm-svn: 143910
2011-11-07 05:09:54 +00:00
John McCall fe96e0b6be Change the AST representation of operations on Objective-C
property references to use a new PseudoObjectExpr
expression which pairs a syntactic form of the expression
with a set of semantic expressions implementing it.
This should significantly reduce the complexity required
elsewhere in the compiler to deal with these kinds of
expressions (e.g. IR generation's special l-value kind,
the static analyzer's Message abstraction), at the lower
cost of specifically dealing with the odd AST structure
of these expressions.  It should also greatly simplify
efforts to implement similar language features in the
future, most notably Managed C++'s properties and indexed
properties.

Most of the effort here is in dealing with the various
clients of the AST.  I've gone ahead and simplified the
ObjC rewriter's use of properties;  other clients, like
IR-gen and the static analyzer, have all the old
complexity *and* all the new complexity, at least
temporarily.  Many thanks to Ted for writing and advising
on the necessary changes to the static analyzer.

I've xfailed a small diagnostics regression in the static
analyzer at Ted's request.

llvm-svn: 143867
2011-11-06 09:01:30 +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
Benjamin Kramer 62144477eb Remove unused variables.
llvm-svn: 143696
2011-11-04 15:05:51 +00:00
Douglas Gregor 07216d174e Fix various minor issues find via unreachable code warnings, from
Ahmed Charles!

llvm-svn: 143569
2011-11-02 20:52:01 +00:00
Benjamin Kramer a4eadc5aa5 Remove virtually empty file.
llvm-svn: 143538
2011-11-02 12:04:24 +00:00
Anna Zaks 49ea5bf562 [analyzer] Make sink attribute part of the node profile.
This prevents caching out on nodes with different sink flag.
(This is a cleaner fix for radar://10376675).

llvm-svn: 143517
2011-11-01 22:41:19 +00:00
Anna Zaks 9e82c62222 [analyzer] Fix PR11282 - an assert in markAsSink
This is another fallout from the refactoring. We were
calling MarkAsSink on a cached out node.
(Fixes radar://10376675)

llvm-svn: 143516
2011-11-01 22:41:14 +00:00
Anna Zaks bfb3520fc5 [analyzer] Make sure the child builder use temporary destination sets
The parent and child builders should not share node sets.

llvm-svn: 143515
2011-11-01 22:41:09 +00:00
Anna Zaks 6d319489df [analyzer] BranchNodeBuilder should not generate autotransitions.
This fixes radar://10367606

llvm-svn: 143514
2011-11-01 22:41:06 +00:00