aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/CheckDeadStores.cpp
AgeCommit message (Collapse)Author
2010-01-25Split libAnalysis into two libraries: libAnalysis and libChecker.Ted Kremenek
(1) libAnalysis is a generic analysis library that can be used by Sema. It defines the CFG, basic dataflow analysis primitives, and inexpensive flow-sensitive analyses (e.g. LiveVariables). (2) libChecker contains the guts of the static analyzer, incuding the path-sensitive analysis engine and domain-specific checks. Now any clients that want to use the frontend to build their own tools don't need to link in the entire static analyzer. This change exposes various obvious cleanups that can be made to the layout of files and headers in libChecker. More changes pending. :) This change also exposed a layering violation between AnalysisContext and MemRegion. BlockInvocationContext shouldn't explicitly know about BlockDataRegions. For now I've removed the BlockDataRegion* from BlockInvocationContext (removing context-sensitivity; although this wasn't used yet). We need to have a better way to extend BlockInvocationContext (and any LocationContext) to add context-sensitivty. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94406 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-23Suppress dead store warnings involving objects initialized with ↵Ted Kremenek
CXXExprTemporaries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91986 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-16Add (initial?) static analyzer support for handling C++ references.Ted Kremenek
This change was a lot bigger than I originally anticipated; among other things it requires us storing more information in the CFG to record what block-level expressions need to be evaluated as lvalues. The big change is that CFGBlocks no longer contain Stmt*'s by CFGElements. Currently CFGElements just wrap Stmt*, but they also store a bit indicating whether the block-level expression should be evalauted as an lvalue. DeclStmts involving the initialization of a reference require us treating the initialization expression as an lvalue, even though that information isn't recorded in the AST. Conceptually this change isn't that complicated, but it required bubbling up the data through the CFGBuilder, to GRCoreEngine, and eventually to GRExprEngine. The addition of CFGElement is also useful for when we want to handle more control-flow constructs or other data we want to keep in the CFG that isn't represented well with just a block of statements. In GRExprEngine, this patch introduces logic for evaluating the lvalues of references, which currently retrieves the internal "pointer value" that the reference represents. EvalLoad does a two stage load to catch null dereferences involving an invalid reference (although this could possibly be caught earlier during the initialization of a reference). Symbols are currently symbolicated using the reference type, instead of a pointer type, and special handling is required creating ElementRegions that layer on SymbolicRegions (see the changes to RegionStoreManager). Along the way, the DeadStoresChecker also silences warnings involving dead stores to references. This was the original change I introduced (which I wrote test cases for) that I realized caused GRExprEngine to crash. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91501 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-15Until we can make the dead stores checker smarter, dont' emit dead store ↵Ted Kremenek
warnings for C++ objects (whose constructors/destructors have possible side-effects). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91412 91177308-0d34-0410-b5e6-96231b3b80d8
2009-12-03Add a heuristic to the dead stores checker to prune dead stores for ↵Ted Kremenek
variables annotated with '__block'. This is overly conservative, but now the analyzer doesn't report dead stores for variables that can be updated by a block call. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90364 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-29Port BugReporter and BugType to StringRef.Benjamin Kramer
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90086 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-28lib/Analysis: Remove VISIBILITY_HIDDEN from definitions in anonymous namespaceKovarththanan Rajaratnam
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90028 91177308-0d34-0410-b5e6-96231b3b80d8
2009-11-22Change CheckDeadStores to use Expr::isNullPointerConstant, which will ↵Ted Kremenek
correctly determine whether an expression is a null pointer constant. Patch by Kovarththanan Rajaratnam! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89621 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-10Make AnalysisManager stateless. Now other analyzer components only depends onZhongxing Xu
local node information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81433 91177308-0d34-0410-b5e6-96231b3b80d8
2009-09-09Remove tabs, and whitespace cleanups.Mike Stump
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81346 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-30Remove the ASTContext parameter from the attribute-related methods of Decl.Argyrios Kyrtzidis
The implementations of these methods can Use Decl::getASTContext() to get the ASTContext. This commit touches a lot of files since call sites for these methods are everywhere. I used pre-tokenized "carbon.h" and "cocoa.h" headers to do some timings, and there was no real time difference between before the commit and after it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74501 91177308-0d34-0410-b5e6-96231b3b80d8
2009-06-18Move the static DeclAttrs map into ASTContext. Fixes <rdar://problem/6983177>.Douglas Gregor
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73702 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-07Remove hack from LiveVariables analysis where variables whose address are takenTed Kremenek
are considered 'live'. This hack isn't needed anymore because we have a separation in the path-sensitive analyzer between variable names and bindings; the analyzer can continue to reason about the storage of a variable after its name is no longer directly referenced. Now the live variables analysis literally means "is this name live". Along this line, update the dead stores checker to explicitly look for variables whose values have escaped. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68504 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-02Sentence-type bug type and category.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68345 91177308-0d34-0410-b5e6-96231b3b80d8
2009-04-01Fix: <rdar://problem/6740387>. Sending nil to an object that returns a structTed Kremenek
should only be an error if that value is consumed. This fix was largely accomplished by moving 'isConsumedExpr' back to ParentMap. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68195 91177308-0d34-0410-b5e6-96231b3b80d8
2009-02-09Fix PR 2514: Do not flag dead initializations for variables initialized to a ↵Ted Kremenek
constant global variable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64149 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-25Rename Expr::isConstantExpr to Expr::isConstantInitializer; this more Eli Friedman
accurately states what the function is trying to do and how it is different from Expr::isEvaluatable. Also get rid of a parameter that is both unused and inaccurate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62951 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-20Dead stores checker: Fix <rdar://problem/6506065> by being more selective ↵Ted Kremenek
when say that a store is dead even though the computed value is used in the enclosing expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62552 91177308-0d34-0410-b5e6-96231b3b80d8
2009-01-09Dead stores checker: Don't flag dead stores for self-assignments (common ↵Ted Kremenek
escape hatch for 'unused variable' warnings). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62010 91177308-0d34-0410-b5e6-96231b3b80d8
2008-11-24Rename NamedDecl::getName() to getNameAsString(). Replace a bunch of Chris Lattner
uses of getName() with uses of getDeclName(). This upgrades a bunch of diags to take DeclNames instead of std::strings. This also tweaks a couple of diagnostics to be cleaner and changes CheckInitializerTypes/PerformInitializationByConstructor to pass around DeclarationNames instead of std::strings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59947 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-15Enhance dead store checker to not flag preincrements to dead variables where ↵Ted Kremenek
the preincrement is a subexpression, e.g. foo(++x); This can cause false negatives, but will remove a whole class of false positives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57554 91177308-0d34-0410-b5e6-96231b3b80d8
2008-09-20Add "category" to BugTypes, allowing bugs to be grouped.Ted Kremenek
Changed casing of many bug names. The convention will be to have bug names (mostly) lower cased, and categories use some capitalization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56385 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-09Added FIXME.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54568 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-09Don't use Expr::isIntegerConstantExpr just to check if a pointer value is ↵Ted Kremenek
initialize to NULL. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54563 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-07Don't flag any dead stores for variables marked unused.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54492 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-05Added decl_iterator to DeclStmt to provide an abstract interface to iterate ↵Ted Kremenek
over the ScopedDecls of a DeclStmt. Updated a few clients of DeclStmt::getNextDeclarator() to use decl_iterator instead. Will update other clients after additional testing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54368 91177308-0d34-0410-b5e6-96231b3b80d8
2008-08-02Change 'dead store (++/--)' to 'dead increment'Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54268 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-25Don't emit 'dead initialization' warnings for variables marked 'unused'.Ted Kremenek
This fixes PR 2573: http://llvm.org/bugs/show_bug.cgi?id=2573 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54009 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-24Issue dead store warnings for preincrements involved in a subexpression.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53983 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-23Don't flag dead stores when the result of a preincrement/predecrement is ↵Ted Kremenek
used in an enclosing expression. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53964 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-23Further refine dead store checking to distinguish between dead stores and ↵Ted Kremenek
dead increments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53960 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-22Rename file.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53906 91177308-0d34-0410-b5e6-96231b3b80d8