Commit Graph

455 Commits

Author SHA1 Message Date
Ted Kremenek 134a83a799 Enhance UnixAPIChecker to also warn about zero-sized allocations to calloc() and realloc(). Patch by Cyril Roelandt!
llvm-svn: 147500
2012-01-03 23:43:13 +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
Rafael Espindola d1c9c9bbfd Fix cmake build with -DBUILD_SHARED_LIBS=ON.
llvm-svn: 147338
2011-12-29 04:31:59 +00:00
Ted Kremenek 72be32af88 Colorize and condense CFG pretty-printing.
llvm-svn: 147203
2011-12-22 23:33:52 +00:00
Ted Kremenek 5586354d7d Fix typos in analyzer diagnostics pointed out by Matt Beaumont-Gay and Robert Purves.
llvm-svn: 147139
2011-12-22 06:35:52 +00:00
Anna Zaks 3b0ab206d2 [analyzer] Add support for taint flowing through a function (atoi).
Check if the input parameters are tainted (or point to tainted data) on
a checkPreStmt<CallExpr>. If the output should be tainted, record it in
the state. On post visit (checkPostStmt<CallExpr>), use the state to
make decisions (in addition to the existing logic). Use this logic for
atoi and fscanf.

llvm-svn: 146793
2011-12-17 00:26:34 +00:00
Anna Zaks e48ee50324 [analyzer] Better stdin support.
llvm-svn: 146748
2011-12-16 18:28:50 +00:00
Anna Zaks 099fe3fb28 [analyzer] Treat stdin as a source of taint.
Some of the test cases do not currently work because the analyzer core
does not seem to call checkers for pre/post DeclRefExpr visits.
(Opened radar://10573500. To be fixed later on.)

llvm-svn: 146536
2011-12-14 00:56:18 +00:00
Anna Zaks eefc0e9342 [analyzer] Mark output of fscanf and fopen as tainted.
llvm-svn: 146533
2011-12-14 00:56:02 +00:00
Anna Zaks d6bb3227de [analyzer] Mark getenv output as tainted.
Also, allow adding taint to a region (not only a symbolic value).

llvm-svn: 146532
2011-12-14 00:55:58 +00:00
Anna Zaks 7c96b7db96 [analyzer] CStringChecker should not rely on the analyzer generating UndefOrUnknown value when it cannot reason about the expression.
We are now often generating expressions even if the solver is not known to be able to simplify it. This is another cleanup of the existing code, where the rest of the analyzer and checkers should not base their logic on knowing ahead of the time what the solver can reason about. 

In this case, CStringChecker is performing a check for overflow of 'left+right' operation. The overflow can be checked with either 'maxVal-left' or 'maxVal-right'. Previously, the decision was based on whether the expresion evaluated to undef or not. With this patch, we check if one of the arguments is a constant, in which case we know that 'maxVal-const' is easily simplified. (Another option is to use canReasonAbout() method of the solver here, however, it's currently is protected.)

This patch also contains 2 small bug fixes:
 - swap the order of operators inside SValBuilder::makeGenericVal.
 - handle a case when AddeVal is unknown in GenericTaintChecker::getPointedToSymbol.

llvm-svn: 146343
2011-12-11 18:43:40 +00:00
Francois Pichet 311084734d Unbreak MSVC build.
llvm-svn: 146146
2011-12-08 09:32:22 +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
Richard Smith 1e1f5abf77 DeadStoresChecker: when whitelisting dead initializations with constants, look
for a foldable constant rather than an IR-level constant. This is still far too
liberal, but is a step in the right direction.

llvm-svn: 145990
2011-12-06 23:25:15 +00:00
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 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 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 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 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
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
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 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
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
Anna Zaks 62c650f477 [analyzer] There should be a space between "expect" and "only"
llvm-svn: 143787
2011-11-05 05:20:51 +00:00
Anna Zaks 1c887b35fb [analyzer] CheckerContext::getPredecessor() cleanup
Remove unnecessary calls to CheckerContext::getPredecessor() + Comments.

llvm-svn: 143513
2011-11-01 22:41:01 +00:00
Ted Kremenek a98358ea13 [analyzer] ObjC message sends to nil receivers that return structs are now okay (compiler zeroes out the data). Fixes <rdar://problem/9151319>.
llvm-svn: 143215
2011-10-28 19:05:10 +00:00
Anna Zaks c9abbe2b3e [analyzer] Add getLocationContext to CheckerContext
CheckerContext::getPredecessor is only used to get to the LocationContext
half of the times.

llvm-svn: 143061
2011-10-26 21:06:44 +00:00
Anna Zaks 6b1c21268d [analyzer] Remove EmitBasicReport form CheckerContext.
The path sensitive checkers should use EmitBasicReport, which provides the
node information.

llvm-svn: 143060
2011-10-26 21:06:39 +00:00
Anna Zaks da4c8d6811 [analyzer] Rename generateNode -> addTransition in CheckerContext
Also document addTransition methods.

llvm-svn: 143059
2011-10-26 21:06:34 +00:00
Anna Zaks 58734db080 [analyzer] Remove getEngine() form CheckerContext
A step toward making sure that diagnostics report should only
be generated though the CheckerContext and not though BugReporter
or ExprEngine directly.

llvm-svn: 142947
2011-10-25 19:57:11 +00:00
Anna Zaks b473816b4a [analyzer] Simplify CheckerContext
Remove dead members/parameters: ProgramState, respondsToCallback, autoTransition.
Remove addTransition method since it's the same as generateNode. Maybe we should
rename generateNode to genTransition (since a transition is always automatically
generated)?

llvm-svn: 142946
2011-10-25 19:57:06 +00:00
Anna Zaks f380534a1a [analyzer] Make branch for condition callback use CheckerContext
Now, all the path sensitive checkers use CheckerContext!

llvm-svn: 142944
2011-10-25 19:56:54 +00:00
Anna Zaks 3eae33412d [analyze] Convert EndOfPath callback to use CheckerContext
Get rid of the EndOfPathBuilder completely.
Use the generic NodeBuilder to generate nodes.
Enqueue the end of path frontier explicitly.

llvm-svn: 142943
2011-10-25 19:56:48 +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
Anna Zaks e4e5712cd7 [analyzer] Node builders cleanup + comments
Renamed PureNodeBuilder->StmtNodeBuilder.

llvm-svn: 142849
2011-10-24 21:19:59 +00:00
Anna Zaks 7b8a2609ff [analyzer] Remove more dependencies from global Builder
- OSAtomicChecker
- ExprEngine::processStmt

llvm-svn: 142846
2011-10-24 21:19:43 +00:00
Ted Kremenek 81ce1c8a99 Rename AnalysisContext to AnalysisDeclContext. Not only is this name more accurate, but it frees up the name AnalysisContext for other uses.
llvm-svn: 142782
2011-10-24 01:32:45 +00:00
Anna Zaks a99b41f37f [analyzer] Make NodeBuilder and Pred node loosely coupled
NodeBuilder should not assume it's dealing with a single predecessor. Remove predecessor getters. Modify the BranchNodeBuilder to not be responsible for doing auto-transitions (which depend on a predecessor).

llvm-svn: 142453
2011-10-18 23:06:44 +00:00
Anna Zaks e83ddcc4ec [analyzer] Remove dead code.
ExprEngineBuilders is not used.

llvm-svn: 142450
2011-10-18 23:06:29 +00:00
Anna Zaks 6d285c58ec [analyzer] Modularize builder use in processBranch.
Take advantage of the new builders for branch processing. As part of this change pass generic NodeBuilder (instead of BranchNodeBuilder) to the BranchCondition callback and remove the unused methods form BranchBuilder.

llvm-svn: 142448
2011-10-18 23:06:21 +00:00
Anna Zaks ce5e97efdd [analyzer] NodeBuilder Refactoring: Subclass BranchNodeBuilder from NodeBuilder.
llvm-svn: 142444
2011-10-18 23:06:04 +00:00
Anna Zaks fc0189aadc [analyzer] Node Builder refactoring: Introduce a simple Node Builder responsible for generating the node frontier.
Currently we have a bunch of different node builders which provide some common
functionality but are difficult to refactor. Each builder generates nodes of
different kinds and calculates the frontier nodes, which should be propagated
to the next step (after the builder dies).

Introduce a new NodeBuilder which provides very basic node generation facilities
but takes care of the second problem. The idea is that all the other builders
will eventually use it. Use this builder in CheckerContext instead of
StmtNodeBuilder (the way the frontier is propagated to the StmtBuilder
is a hack and will be removed later on).

llvm-svn: 142443
2011-10-18 23:05:58 +00:00
Benjamin Kramer b89514a9b8 Change operator<< for raw_ostream and NamedDecl to take a reference instead of a pointer.
Passing a pointer was a bad idea as it collides with the overload for void*.

llvm-svn: 141971
2011-10-14 18:45:37 +00:00
Anna Zaks cc92521066 [analyzer] Fix a typo.
llvm-svn: 141678
2011-10-11 16:49:54 +00:00
Anna Zaks fedf5dfc71 [analyzer] Warn about the use of insecure, deprecated vfork() function PR11053 (http://llvm.org/bugs/show_bug.cgi?id=11053).
A patch by Graham Lee!

llvm-svn: 141643
2011-10-11 04:34:54 +00:00
Richard Smith caf3390d44 Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
   and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
   behaviour.
 - Factor out evaluation of bitfield bit widths.
 - Fix a few places which would evaluate an expression twice: once to determine
   whether it is a constant expression, then again to get the value.

llvm-svn: 141561
2011-10-10 18:28:20 +00:00
Ted Kremenek dccc2b2277 Remove AnalysisContext::getLiveVariables(), and introduce a templatized mechanism to lazily create analyses that are attached to AnalysisContext objects.
llvm-svn: 141425
2011-10-07 22:21:02 +00:00
John McCall f937c023bf Rename TagDecl::isDefinition -> isCompleteDefinition
for better self-documenting code, since the semantics
are subtly different from getDefinition().

llvm-svn: 141355
2011-10-07 06:10:15 +00:00
Peter Collingbourne d937a99465 Clang-side build system infrastructure for multiple tblgens.
llvm-svn: 141267
2011-10-06 01:52:10 +00:00
Anna Zaks 3e0f415d0d [analyzer] Remove the dependency on CheckerContext::getStmt() as well as the method itself.
llvm-svn: 141262
2011-10-06 00:43:15 +00:00
Ted Kremenek f3e3f6645e Fix major regression in RetainCountChecker. DefaultSummaries were not being used when they were meant to be. Fixes <rdar://problem/10241614>.
llvm-svn: 141250
2011-10-05 23:54:29 +00:00
Anna Zaks c4aa22cdd4 [analyzer] Remove the last dependency on CheckerContext::getNodeBuilder() as well as the method itself.
Checkers should not directly access NodeBuilder, nodes can be created by calling the CheckerContext's generateNode() methods.

llvm-svn: 141249
2011-10-05 23:44:11 +00:00
Anna Zaks 77f8661d18 [analyzer] OSAtomicChecker implements evalCall in a very invasive way - it essentially simulates inlining of compareAndSwap() by means of setting the NodeBuilder flags and calling ExprEngine directly.
This commit introduces a new callback just for this checker to unblock checker API cleanup. 

llvm-svn: 141246
2011-10-05 23:37:30 +00:00
Anna Zaks 8569d2d8f2 [analyzer] Removing more references to CheckerContext::getNodeBuilder(): ask CheckerContext to generate the nodes.
llvm-svn: 141136
2011-10-04 23:29:16 +00:00
Anna Zaks 23d7ba3579 [analyzer] Removing references to CheckerContext::getNodeBuilder(): checkers can obtain block count directly from the Context.
llvm-svn: 141112
2011-10-04 20:43:05 +00:00
Anna Zaks c76ec12ccf [analyzer] Remove unused methods, add comments to others.
llvm-svn: 141098
2011-10-04 18:34:40 +00:00
Anna Zaks 208d54ce09 [analyzer] Remove redundant state (AnalysisContext pointer for every BinaryOperator tracked) from IdempotentOperationChecker.
llvm-svn: 141045
2011-10-03 23:07:13 +00:00
Anna Zaks 892427e2fa [analyzer] In UndefBranchChecker, use a node generator which does not create an edge/branching. (ExprEngine should be in charge of generating edges. The checkers should examine the condition and generate PostCondition node if needed.)
llvm-svn: 141034
2011-10-03 21:55:56 +00:00
Anna Zaks c42197d0f8 [analyzer] Cleanup in UndefBranchChecker:
- Remove unused FindUndefExpr::ProgramStateManager.
  - The Condition parameter of the callback is the terminator of the block, no need to retrieve it again.

llvm-svn: 141027
2011-10-03 21:16:32 +00:00
Argyrios Kyrtzidis b8c3aaf479 Allow getting all source locations of selector identifiers in a ObjCMethodDecl.
Instead of always storing all source locations for the selector identifiers
we check whether all the identifiers are in a "standard" position; "standard" position is

  -Immediately before the arguments: -(id)first:(int)x second:(int)y;
  -With a space between the arguments: -(id)first: (int)x second: (int)y;
  -For nullary selectors, immediately before ';': -(void)release;

In such cases we infer the locations instead of storing them.

llvm-svn: 140989
2011-10-03 06:37:04 +00:00
John McCall 525f05597f Tweak the interface for analyzing the CF conventions for a name
to take a FunctionDecl* instead of an llvm::StringRef.  Eventually
we might push more logic in there, like using slightly different
conventions for C++ methods.

Also, fix a bug where 'copy' and 'create' were being caught in 
non-camel-cased strings.  We want copyFoo and CopyFoo and XCopy
but not Xcopy or xcopy.

llvm-svn: 140911
2011-10-01 00:48:56 +00:00
Anna Zaks 819b0d8619 [analyzer] Fix a bug in RetainReleaseChecker diagnostics. It gives more precise error message on the modified test case (and prevents duplicate diagnostics when we purge at block granularity).
llvm-svn: 140840
2011-09-30 02:19:19 +00:00
Anna Zaks 0070c6d4db Fix a crash in MallocOverflowSecurityChecker. Patch by Lei Zhang.
llvm-svn: 140648
2011-09-27 22:25:01 +00:00
Benjamin Kramer 1f88d2f531 Fix comment typo.
Patch by Rui Paulo!

llvm-svn: 140448
2011-09-24 03:04:03 +00:00
David Blaikie 83d382b1ca Switch assert(0/false) llvm_unreachable.
llvm-svn: 140367
2011-09-23 05:06:16 +00:00
Anna Zaks c29bed3989 [analyzer] Refactor PathDiagnosticLocation: Make PathDiagnosticLocation(SourceLocation...) private. Most of the effort here goes to making BugReport refer to a PathDiagnosticLocation instead of FullSourceLocation.
(Another step closer to the goal of having Diagnostics which can recover from invalid SourceLocations.)

llvm-svn: 140182
2011-09-20 21:38:35 +00:00
Anna Zaks 921f04924f [analyzer] Refactor: make PathDiagnosticLocation responsible for validation of SourceLocations (commit 2 of ?):
- Fix a fixme and move the logic of creating a PathDiagnosticLocation corresponding to a ProgramPoint into a PathDiagnosticLocation constructor.
- Rename PathDiagnosticLocation::create to differentiate from the added constructor.

llvm-svn: 139825
2011-09-15 18:56:07 +00:00
Anna Zaks 3a769bd996 [analyzer] Refactor: make PathDiagnosticLocation responsible for validation of SourceLocations (commit 2 of ?):
- Modify all PathDiagnosticLocation constructors that take Stmt to also requre LocationContext.
- Add a constructor which should be used in case there is no valid statement/location (it will grab the location of the enclosing function).

llvm-svn: 139763
2011-09-15 01:08:34 +00:00
Anna Zaks 2c65eea947 [analyzer] Refactor: Make PathDiagnosticLocation responsible for creating a valid object given an ExploadedNode (the same logic can be reused by other checkers).
llvm-svn: 139672
2011-09-14 00:25:17 +00:00
Douglas Gregor 79a91418bd Switch LangOptions over to a .def file that describes header of the
language options. Use that .def file to declare the LangOptions class
and initialize all of its members, eliminating a source of annoying
initialization bugs.

AST serialization changes are next up.

llvm-svn: 139605
2011-09-13 17:21:33 +00:00
Benjamin Kramer 2667afa980 Make helpers static, remove unused variables.
llvm-svn: 139078
2011-09-03 03:30:59 +00:00
Jordy Rose 087611ed81 [analyzer] Remove TransferFuncs.h, then deal with the fallout.
And with that, TransferFuncs is gone!

llvm-svn: 139003
2011-09-02 08:02:59 +00:00
Jordy Rose 75e680eae3 [analyzer] Move RetainReleaseChecker to the Checkers library and rename it to RetainCountChecker...and clean up the file while I'm at it.
llvm-svn: 139002
2011-09-02 06:44:22 +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
Douglas Gregor e8bbc12152 Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making
ASTUnit build the ASTContext as needed when loading an AST file,
rather than doing so after the fact. No actual functionality change (yet).

llvm-svn: 138985
2011-09-02 00:18:52 +00:00
Zhongxing Xu bfb8e2fe6e If size was equal to 0, either NULL or a pointer suitable to be passed to
free() is returned by realloc(). Most code expect NULL.

And we only need to transfer one final ProgramState.

llvm-svn: 138937
2011-09-01 04:53:59 +00:00
Jordy Rose 973a8886f6 [analyzer] Fix varargs helper to only use POD types even for named arguments. Thanks, Joerg.
llvm-svn: 138875
2011-08-31 18:33:45 +00:00
Anna Zaks 50dd696339 [analyzer] MacOSKeychainAPIChecker: Simplify getSymbolForRegion by using existing API. Thanks Jordy.
llvm-svn: 138765
2011-08-29 21:10:00 +00:00
Anna Zaks 814adf7752 Fix: Bug 10798 - [analyzer] Crash when analyzing ICU. (A slight improvement on the previous commit.)
llvm-svn: 138762
2011-08-29 20:43:37 +00:00
Anna Zaks cda129eb1c Fix bug 10797: Crash: "cast<Ty>() argument of incompatible type!" assert when analyzing ICU.
Patch by Jean-Daniel Dupas. Thanks for spotting and fixing!

llvm-svn: 138757
2011-08-29 20:05:54 +00:00
Jordy Rose 1fad663126 [analyzer] Change the check::RegionChanges callback to include the regions explicitly requested for invalidation.
Also, allow CallOrObjCMessage to wrap a CXXConstructExpr as well.

Finally, this allows us to remove the clunky whitelisting system from CFRefCount/RetainReleaseChecker. Slight regression due to CXXNewExprs not yet being handled in post-statement callbacks (PR forthcoming).

llvm-svn: 138716
2011-08-27 22:51:26 +00:00
Jeffrey Yasskin 0e9cdbbb06 Handle CXXTempObjectRegion in StackAddrEscapeChecker.
Also convert stack-addr-ps.cpp to use the analyzer instead of just Sema, now
that it doesn't crash, and extract the stack-block test into another file since
it errors, and that prevents the analyzer from running.

llvm-svn: 138613
2011-08-26 00:41:31 +00:00
Anna Zaks 5be8a4d104 [analyzer] MacOSKeychainAPIChecker: Cleanup AllocationState structure.
llvm-svn: 138535
2011-08-25 00:59:06 +00:00
Anna Zaks 85913db489 [analyzer] MacOSKeychainAPIChecker: Add the custom BugReport visitor(which highlights the allocation site) to all the relevant reports within the checker.
llvm-svn: 138531
2011-08-25 00:32:42 +00:00
Anna Zaks f880cff209 [analyzer] Do not use references in std::pair.
llvm-svn: 138497
2011-08-24 21:58:55 +00:00
Anna Zaks 0d67579497 [analyzer] Unbreak the release buildbot.
llvm-svn: 138493
2011-08-24 21:40:10 +00:00
Anna Zaks be460898bb [analyzer] MacOSKeychainAPIChecker: Provide reacher diagnostic trace by pointing to the allocation site when reporting a leak.
llvm-svn: 138479
2011-08-24 20:52:46 +00:00
Anna Zaks 0897a23517 [analyzer] MacOSKeychainAPIChecker: Add reasoning about functions which MIGHT deallocate the memory region allocated with SecKeychain APIs. Specifically, when the buffer is passed to CFStringCreateWithBytesNoCopy along with a custom deallocator, which might potentially correctly release the memory.
llvm-svn: 138417
2011-08-24 00:06:27 +00:00
Anna Zaks f9e9c4e9bc [analyzer] MacOSKeychainAPIChecker: Retrieve the memory region which we are tracking even when it's no longer a SymbolicRegion, for example, when it is cast to char*.
llvm-svn: 138415
2011-08-23 23:56:12 +00:00
Anna Zaks bb167011e3 Move creation of the deallocation mismatch report into a separate function for future reuse.
llvm-svn: 138414
2011-08-23 23:47:36 +00:00
Anna Zaks bd7972b49e [analyzer] MacOSKeychainAPIChecker: Users of KeyChain API often use free() to deallocate the password. Catch this error explicitly and generate the error message at the place where free() is called.
llvm-svn: 138296
2011-08-22 23:18:12 +00:00
Jordy Rose 82c673de33 [analyzer] Replace calls to getNameAsString() with StringRef equivalents.
llvm-svn: 138215
2011-08-21 05:25:15 +00:00
Benjamin Kramer 3cca223a2a Fix compile on platforms that don't implicitly include stdarg.h here.
llvm-svn: 138214
2011-08-20 21:50:41 +00:00
Jordy Rose 5a3c9ff3a3 [analyzer] Move handling of hardcoded noreturn ("panic") methods from CFRefCount to NoReturnFunctionChecker. No functionality change intended.
llvm-svn: 138210
2011-08-20 20:55:40 +00:00
Ted Kremenek 417d566775 Remove dead code.
llvm-svn: 138183
2011-08-20 01:15:28 +00:00
Anna Zaks f86615ca5c Static Analyzer Diagnostics: Kill the addVisitorCreator(callbackTy, void*) API in favor of addVisitor(BugReporterVisitor*).
1) Create a header file to expose the predefined visitors. And move the parent(BugReporterVisitor) there as well.

2) Remove the registerXXXVisitor functions - the Visitor constructors/getters can be used now to create the object. One exception is registerVarDeclsLastStore(), which registers more then one visitor, so make it static member of FindLastStoreBRVisitor.

3) Modify all the checkers to use the new API.

llvm-svn: 138126
2011-08-19 22:33:38 +00:00
Anna Zaks 3a6bdf8f82 Remove EnhancedBugReport and RangedBugReport - pull all the extra functionality they provided into their parent BugReport. The only functional changes are: made getRanges() non const - it adds default range to Ranges if none are supplied, made getStmt() private, which was another FIXME.
llvm-svn: 137894
2011-08-17 23:00:25 +00:00
Jordy Rose 59cce71af6 [analyzer] Overhaul of checker registration in preparation for basic plugin support. Removes support for checker groups (we can add them back in later if we decide they are still useful), and -analyzer-checker-help output is a little worse for the time being (no packages).
llvm-svn: 137758
2011-08-16 21:24:21 +00:00
Anna Zaks a06421a02c MacOSKeychainAPIChecker: Turn it on by default.
llvm-svn: 137740
2011-08-16 20:02:05 +00:00
Anna Zaks 01ae1e1197 MacOSKeychainAPIChecker: Do not report double allocation if first allocation returned an error.
llvm-svn: 137720
2011-08-16 16:30:24 +00:00
Anna Zaks 5443a6497b MacOSKeychainAPIChecker: The security API/memory leak checker should always generate regular nodes instead of sink nodes.
llvm-svn: 137681
2011-08-15 23:23:15 +00:00
Ted Kremenek 001fd5b498 Rename GRState to ProgramState, and cleanup some code formatting along the way.
llvm-svn: 137665
2011-08-15 22:09:50 +00:00
Anna Zaks 29f9b7adc3 MacOSKeychainAPIChecker: Use llvm::SmallString instead of std::string (as per code review for r137523).
llvm-svn: 137633
2011-08-15 18:42:00 +00:00
Ted Kremenek 5ef32dbf2a Cleanup various declarations of 'Stmt*' to be 'Stmt *', etc. in libAnalyzer and libStaticAnalyzer[*]. It was highly inconsistent, and very ugly to look at.
llvm-svn: 137537
2011-08-12 23:37:29 +00:00
Ted Kremenek e8f7316fee [analyzer] change "tag" in ProgramPoint from "void*" to a ProgramPointTag*.
Having a notion of an actual ProgramPointTag will aid in introspection of the analyzer's behavior.
For example, the GraphViz output of the analyzer will pretty-print the tags in a useful manner.

llvm-svn: 137529
2011-08-12 23:04:46 +00:00
Anna Zaks 59d741fec6 MacOSKeychainAPIChecker: If the allocated data address entered as an enclosing function parameter, skip it to avoid false positives.
llvm-svn: 137526
2011-08-12 22:47:22 +00:00
Anna Zaks fdd0aca0a5 MacOSKeychainAPIChecker:
Report errors earlier: on checkDeadSymbols() and clear the state after the symbol we are tracking goes out of scope. 

Also, perform lazy error checking. Instead of forcing the paths to be split depending one the return value of the allocator, make the return symbol depend on the allocated data symbol, which prolongs its life span to the time when the allocated data symbol becomes dead.

llvm-svn: 137523
2011-08-12 21:56:43 +00:00
Jordy Rose add45b78dd [analyzer] Nitpicks on Olaf's patch, which I meant to e-mail but then didn't in
time. One is cleanup, the other is me being OCD about enum group nesting.

llvm-svn: 137517
2011-08-12 21:41:07 +00:00
Anna Zaks c94894fbc2 MacOSKeychainAPIChecker: There is no need to use SymbolMetadata to represent the allocated data symbol, we can just use the symbol corresponding to the SymbolicRegion. This simplifies tracking of the symbol, for example, SymbolMetadata needs to go through extra hoops to stay alive.
Make AllocationState internal to the MacOSKeychainAPIChecker class.

llvm-svn: 137514
2011-08-12 21:14:26 +00:00
Ted Kremenek 8df44b2632 [analyzer] Introduce new MemRegion, "TypedValueRegion", so that we can separate TypedRegions that implement getValueType() from those that don't.
Patch by Olaf Krzikalla!

llvm-svn: 137498
2011-08-12 20:02:48 +00:00
Anna Zaks 177ecfac21 KeychainAPI checker: Track SymbolMetadata instead of MemRegion in checker state so that we could clear the state on evalDeadSymbols; also track the return value.
llvm-svn: 137003
2011-08-05 23:52:45 +00:00
Anna Zaks c52bed1814 KeychainAPI checker: Generate an error on double allocation. Pull out getAsPointeeMemoryRegion so that it could be reused.
llvm-svn: 136952
2011-08-05 00:37:00 +00:00
Anna Zaks c686177555 KeychainAPI checker: Track additional pair of SecKeychain APIs. Also, keep exploring the transition on which a call to allocator function failed (to be able to find errors in examples like ErrorCodesFromDifferentAPISDoNotInterfere).
llvm-svn: 136930
2011-08-04 21:53:01 +00:00
Anna Zaks 08be9b99e3 KeychainAPI checker: Refactor to make it easier to add more allocator/deallocator API pairs. Add the allocator function ID to the checker state. Better comments.
llvm-svn: 136889
2011-08-04 17:28:06 +00:00
Anna Zaks 4aa34a5325 KeychainAPI checker: refactor to use early exit.
llvm-svn: 136852
2011-08-04 00:31:38 +00:00
Anna Zaks 388c18ec7f KeychainAPI checker: Add basic diagnostics. Track MemoryRegion istead of SymbolicRef since the address might not be a symbolic value in some cases, for example in fooOnlyFree() test.
llvm-svn: 136851
2011-08-04 00:26:57 +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
Benjamin Kramer 558e37858b Remove dead code flagged by GCC's -Wunused-but-set-variable.
llvm-svn: 136581
2011-07-31 01:06:41 +00:00
Ted Kremenek e9fda1e48a [analyzer] Overhaul how the static analyzer expects CFGs by forcing CFGs to be linearized only when used by the static analyzer. This required a rewrite of LiveVariables, and exposed a ton of subtle bugs.
The motivation of this large change is to drastically simplify the logic in ExprEngine going forward.

Some fallout is that the output of some BugReporterVisitors is not as accurate as before; those will
need to be fixed over time.  There is also some possible performance regression as RemoveDeadBindings
will be called frequently; this can also be improved over time.

llvm-svn: 136419
2011-07-28 23:07:59 +00:00
Ted Kremenek e227f49302 [analyzer] fix bug in malloc checker where the tracked symbol would not properly be removed from the state.
llvm-svn: 136418
2011-07-28 23:07:51 +00:00
Chandler Carruth d48db2115a Rename getInstantiationLineNumber to getExpansionLineNumber in both
SourceManager and FullSourceLoc.

llvm-svn: 135969
2011-07-25 21:09:52 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Jordy Rose a39e10fd7c [analyzer] Very minor cleanup in PthreadLockChecker. No functionality change.
llvm-svn: 135518
2011-07-19 20:31:42 +00:00
Jordy Rose d9c522100e [analysis] Add checks for double-locking and lock order reversal bugs for
pthread and XNU locks. Patch by Rui Paulo!

llvm-svn: 135515
2011-07-19 20:21:41 +00:00
Ted Kremenek c85964ed90 [analyzer] Place checking for Core Foundation "Create" rule into a proper API. No functionality change.
llvm-svn: 135349
2011-07-16 19:50:32 +00:00
Jordy Rose f3dd00a26c Clean up UnixAPIChecker, including switching its array of BugTypes to llvm::OwningPtr<BugType> vars (the new convention). No functionality change.
llvm-svn: 135255
2011-07-15 06:28:59 +00:00
Jordy Rose ede26958bf Clean up MacOSXAPIChecker, including switching its array of BugTypes to a single llvm::OwningPtr<BugType> (the new convention). No functionality change.
llvm-svn: 135250
2011-07-15 06:02:19 +00:00
Eric Christopher bf15d2b311 Update for llvm commit r134291.
Fixes rdar://9714064

llvm-svn: 134292
2011-07-02 00:20:22 +00:00
Douglas Gregor fe31481f68 Introduce a new AST node describing reference binding to temporaries.
MaterializeTemporaryExpr captures a reference binding to a temporary
value, making explicit that the temporary value (a prvalue) needs to
be materialized into memory so that its address can be used. The
intended AST invariant here is that a reference will always bind to a
glvalue, and MaterializeTemporaryExpr will be used to convert prvalues
into glvalues for that binding to happen. For example, given

  const int& r = 1.0;

The initializer of "r" will be a MaterializeTemporaryExpr whose
subexpression is an implicit conversion from the double literal "1.0"
to an integer value. 

IR generation benefits most from this new node, since it was
previously guessing (badly) when to materialize temporaries for the
purposes of reference binding. There are likely more refactoring and
cleanups we could perform there, but the introduction of
MaterializeTemporaryExpr fixes PR9565, a case where IR generation
would effectively bind a const reference directly to a bitfield in a
struct. Addresses <rdar://problem/9552231>.

llvm-svn: 133521
2011-06-21 17:03:29 +00:00
Jordy Rose b41f7c55f5 [analyzer] Finish size argument checking for strncat (and strncpy).
llvm-svn: 133472
2011-06-20 21:55:40 +00:00
Jordy Rose 789adbb3ed [analyzer] Replace stream-built error message with constant string. No functionality change.
llvm-svn: 133410
2011-06-20 03:51:53 +00:00
Jordy Rose 328deeed7f [analyzer] Re-enable checking for strncpy, along with a new validation of the size argument. strncat is not yet up-to-date, but I'm leaving it enabled for now (there shouldn't be any false positives, at least...)
llvm-svn: 133408
2011-06-20 03:49:16 +00:00
Jordy Rose dceb0cf3f3 [analyzer] Eliminate "byte string function" from CStringChecker's diagnostics, and make it easier to provide custom messages for overflow checking, in preparation for re-enabling strncpy checking.
llvm-svn: 133406
2011-06-20 02:06:40 +00:00
Jordy Rose c026370858 [analyzer] Clean up modeling of strcmp, including cases where a string literal has an embedded null character, and where both arguments are the same buffer. Also use nested ifs rather than early returns; in this case early returns will lose any assumptions we've made earlier in the function.
llvm-svn: 133154
2011-06-16 07:13:34 +00:00
Jordy Rose 0585a61821 [analyzer] Fix trivial errors in previous commit.
I will not commit without building first.
I will not commit without building first.
I will not commit without building first...

llvm-svn: 133150
2011-06-16 05:56:50 +00:00
Jordy Rose 455bd58d4e [analyzer] Cleanup: mainly 80-char violations and preferring SValBuilder::getComparisonType() to just referencing IntTy.
llvm-svn: 133149
2011-06-16 05:51:02 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00