aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/AnalysisDeclContext.cpp
AgeCommit message (Collapse)AuthorFilesLines
2016-10-10[Analysis] Use unique_ptr in AnalyaisDeclContextManager's ContextMap.Justin Lebar1-9/+5
Reviewers: timshen Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25426 llvm-svn: 283774
2016-03-28[analyzer] Use BodyFarm-synthesized body even when actual body available.Devin Coughlin1-6/+12
Change body autosynthesis to use the BodyFarm-synthesized body even when an actual body exists. This enables the analyzer to use the simpler, analyzer-provided body to model the behavior of the function rather than trying to understand the actual body. Further, this makes the analyzer robust against changes in headers that expose the implementations of those bodies. rdar://problem/25145950 llvm-svn: 264687
2016-02-23[analyzer] Find ObjC 'self' decl even when block captures local named 'self'.Devin Coughlin1-2/+6
When looking up the 'self' decl in block captures, make sure to find the actual self declaration even when the block captures a local variable named 'self'. rdar://problem/24751280 llvm-svn: 261703
2016-02-07[analyzer] Invalidate destination of std::copy() and std::copy_backward().Devin Coughlin1-0/+15
Now that the libcpp implementations of these methods has a branch that doesn't call memmove(), the analyzer needs to invalidate the destination for these methods explicitly. rdar://problem/23575656 llvm-svn: 260043
2015-11-15[analyzer] Handle calling ObjC super method from inside C++ lambda.Devin Coughlin1-0/+17
When calling a ObjC method on super from inside a C++ lambda, look at the captures to find "self". This mirrors how the analyzer handles calling super in an ObjC block and fixes an assertion failure. rdar://problem/23550077 llvm-svn: 253176
2015-10-20Roll-back r250822.Angel Garcia Gomez1-2/+2
Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
2015-10-20Apply modernize-use-default to clang.Angel Garcia Gomez1-2/+2
Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
2015-07-02Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer1-3/+3
++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
2015-02-06Update APIs that return a pair of iterators to return an iterator_range instead.Benjamin Kramer1-4/+4
Convert uses of those APIs into ranged for loops. NFC. llvm-svn: 228404
2014-11-19Update for LLVM API change to make Small(Ptr)Set::insert return ↵David Blaikie1-1/+1
pair<iterator, bool> as per the C++ standard's associative container concept. llvm-svn: 222335
2014-08-29unique_ptrify the result of CFG::buildCFG/CFGBuilder::buildCFGDavid Blaikie1-4/+3
llvm-svn: 216755
2014-08-27Add support for the static analyzer to synthesize function implementations ↵Ted Kremenek1-6/+14
from external model files. Currently the analyzer lazily models some functions using 'BodyFarm', which constructs a fake function implementation that the analyzer can simulate that approximates the semantics of the function when it is called. BodyFarm does this by constructing the AST for such definitions on-the-fly. One strength of BodyFarm is that all symbols and types referenced by synthesized function bodies are contextual adapted to the containing translation unit. The downside is that these ASTs are hardcoded in Clang's own source code. A more scalable model is to allow these models to be defined as source code in separate "model" files and have the analyzer use those definitions lazily when a function body is needed. Among other things, it will allow more customization of the analyzer for specific APIs and platforms. This patch provides the initial infrastructure for this feature. It extends BodyFarm to use an abstract API 'CodeInjector' that can be used to synthesize function bodies. That 'CodeInjector' is implemented using a new 'ModelInjector' in libFrontend, which lazily parses a model file and injects the ASTs into the current translation unit. Models are currently found by specifying a 'model-path' as an analyzer option; if no path is specified the CodeInjector is not used, thus defaulting to the current behavior in the analyzer. Models currently contain a single function definition, and can be found by finding the file <function name>.model. This is an initial starting point for something more rich, but it bootstraps this feature for future evolution. This patch was contributed by Gábor Horváth as part of his Google Summer of Code project. Some notes: - This introduces the notion of a "model file" into FrontendAction and the Preprocessor. This nomenclature is specific to the static analyzer, but possibly could be generalized. Essentially these are sources pulled in exogenously from the principal translation. Preprocessor gets a 'InitializeForModelFile' and 'FinalizeForModelFile' which could possibly be hoisted out of Preprocessor if Preprocessor exposed a new API to change the PragmaHandlers and some other internal pieces. This can be revisited. FrontendAction gets a 'isModelParsingAction()' predicate function used to allow a new FrontendAction to recycle the Preprocessor and ASTContext. This name could probably be made something more general (i.e., not tied to 'model files') at the expense of losing the intent of why it exists. This can be revisited. - This is a moderate sized patch; it has gone through some amount of offline code review. Most of the changes to the non-analyzer parts are fairly small, and would make little sense without the analyzer changes. - Most of the analyzer changes are plumbing, with the interesting behavior being introduced by ModelInjector.cpp and ModelConsumer.cpp. - The new functionality introduced by this change is off-by-default. It requires an analyzer config option to enable. llvm-svn: 216550
2014-05-20[C++11] Use 'nullptr'. Analysis edition.Craig Topper1-14/+14
llvm-svn: 209191
2014-04-15Fix typo from r206232Richard Trieu1-2/+2
llvm-svn: 206234
2014-04-15Fix a bad interaction between -Wtautological-overlap-compare and delayedRichard Trieu1-0/+6
diagnostics which caused delayed diagnostics on dead paths to be emitted. llvm-svn: 206232
2014-03-23remove a bunch of unused private methodsNuno Lopes1-5/+0
found with a smarter version of -Wunused-member-function that I'm playwing with. Appologies in advance if I removed someone's WIP code. ARCMigrate/TransProperties.cpp | 8 ----- AST/MicrosoftMangle.cpp | 1 Analysis/AnalysisDeclContext.cpp | 5 --- Analysis/LiveVariables.cpp | 14 ---------- Index/USRGeneration.cpp | 10 ------- Sema/Sema.cpp | 33 +++++++++++++++++++++--- Sema/SemaChecking.cpp | 3 -- Sema/SemaDecl.cpp | 20 ++------------ StaticAnalyzer/Checkers/GenericTaintChecker.cpp | 1 9 files changed, 34 insertions(+), 61 deletions(-) llvm-svn: 204561
2014-03-14[C++11] Replacing BlockDecl iterators capture_begin() and capture_end() with ↵Aaron Ballman1-6/+4
iterator_range captures(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203958
2014-03-13[C++11] Replacing CXXRecordDecl iterators init_begin() and init_end() with ↵Aaron Ballman1-4/+2
iterator_range inits(). Updating all of the usages of the iterators with range-based for loops. llvm-svn: 203819
2014-02-19Use llvm::DeleteContainerSeconds when possibleReid Kleckner1-7/+3
llvm-svn: 201739
2014-01-13[analyzer] Add a CFG node for the allocator call in a C++ 'new' expression.Jordan Rose1-1/+3
In an expression like "new (a, b) Foo(x, y)", two things happen: - Memory is allocated by calling a function named 'operator new'. - The memory is initialized using the constructor for 'Foo'. Currently the analyzer only models the second event, though it has special cases for both the default and placement forms of operator new. This patch is the first step towards properly modeling both events: it changes the CFG so that the above expression now generates the following elements. 1. a 2. b 3. (CFGNewAllocator) 4. x 5. y 6. Foo::Foo The analyzer currently ignores the CFGNewAllocator element, but the next step is to treat that as a call like any other. The CFGNewAllocator element is not added to the CFG for analysis-based warnings, since none of them take advantage of it yet. llvm-svn: 199123
2014-01-10[analyzer] Model getters of known-@synthesized Objective-C properties.Jordan Rose1-5/+12
...by synthesizing their body to be "return self->_prop;", with an extra nudge to RetainCountChecker to still treat the value as +0 if we have no other information. This doesn't handle weak properties, but that's mostly correct anyway, since they can go to nil at any time. This also doesn't apply to properties whose implementations we can't see, since they may not be backed by an ivar at all. And finally, this doesn't handle properties of C++ class type, because we can't invoke the copy constructor. (Sema has actually done this work already, but the AST it synthesizes is one the analyzer doesn't quite handle -- it has an rvalue DeclRefExpr.) Modeling setters is likely to be more difficult (since it requires handling strong/copy), but not impossible. <rdar://problem/11956898> llvm-svn: 198953
2014-01-07Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth1-1/+1
encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
2014-01-04Only mark dump() function definitions 'used' in debug buildsAlp Toker1-1/+1
This has the dual effect of (1) enabling more dead-stripping in release builds and (2) ensuring that debug helper functions aren't stripped away in debug builds, as they're intended to be called from the debugger. Note that the attribute is applied to definitions rather than declarations in headers going forward because it's now conditional on NDEBUG: /// \brief Mark debug helper function definitions like dump() that should not be /// stripped from debug builds. Requires corresponding macro added in LLVM r198456. llvm-svn: 198489
2013-07-19[analyzer] Include analysis stack in crash traces.Jordan Rose1-6/+10
Sample output: 0. Program arguments: ... 1. <eof> parser at end of file 2. While analyzing stack: #0 void inlined() #1 void test() 3. crash-trace.c:6:3: Error evaluating statement llvm-svn: 186639
2013-06-06[analyzer; new edges] Simplify edges in a C++11 for-range loop.Jordan Rose1-0/+23
Previously our edges were completely broken here; now, the final result is a very simple set of edges in most cases: one up to the "for" keyword for context, and one into the body of the loop. This matches the behavior for ObjC for-in loops. In the AST, however, CXXForRangeStmts are handled very differently from ObjCForCollectionStmts. Since they are specified in terms of equivalent statements in the C++ standard, we actually have implicit AST nodes for all of the semantic statements. This makes evaluation very easy, but diagnostic locations a bit trickier. Fortunately, the problem can be generally defined away by marking all of the implicit statements as part of the top-level for-range statement. One of the implicit statements in a for-range statement is the declaration of implicit iterators __begin and __end. The CFG synthesizes two separate DeclStmts to match each of these decls, but until now these synthetic DeclStmts weren't in the function's ParentMap. Now, the CFG keeps track of its synthetic statements, and the AnalysisDeclContext will make sure to add them to the ParentMap. <rdar://problem/14038483> llvm-svn: 183449
2013-05-18Revert "[analyzer; alternate edges] improve support for edges with ↵Jordan Rose1-22/+8
PseudoObjectExprs." Ted and I spent a long time discussing this today and found out that neither the existing code nor the new code was doing what either of us thought it was, which is never good. The good news is we found a much simpler way to fix the motivating test case (an ObjCSubscriptExpr). This reverts r182083, but pieces of it will come back in subsequent commits. llvm-svn: 182185
2013-05-17[analyzer; alternate edges] improve support for edges with PseudoObjectExprs.Ted Kremenek1-8/+22
This optimizes some spurious edges resulting from PseudoObjectExprs. This required far more changes than I anticipated. The current ParentMap does not record any hierarchy information between a PseudoObjectExpr and its *semantic* expressions that may be wrapped in OpaqueValueExprs, which are the expressions actually laid out in the CFG. This means the arrow pruning logic could not map from an expression to its containing PseudoObjectExprs. To solve this, this patch adds a variant of ParentMap that returns the "semantic" parentage of expressions (essentially as they are viewed by the CFG). This alternate ParentMap is then used by the arrow reducing logic to identify edges into pseudo object expressions, and then eliminate them. llvm-svn: 182083
2013-03-30[analyzer] Add debug helper LocationContext::dumpStack().Jordan Rose1-0/+26
Sample output: #0 void construct(pointer __p, llvm::ImutAVLTree<llvm::ImutContainerInfo<clang::ento::BugType *> > *const &__val) #1 void push_back(const value_type &__x) #2 void destroy() #3 void release() #4 void ~ImmutableSet() llvm-svn: 178400
2013-03-29Add configuration plumbing to enable static initializer branching in the CFG ↵Ted Kremenek1-1/+3
for the analyzer. This setting still isn't enabled yet in the analyzer. This is just prep work. llvm-svn: 178317
2013-02-04clang/Analysis: Fix r174245, a valgrind error in ↵NAKAMURA Takumi1-0/+1
AnalysisDeclContext::getBody(bool &IsAutosynthesized), to initialize IsAutosynthesized explicitly. llvm-svn: 174303
2013-02-02[analyzer] Always inline functions with bodies generated by BodyFarm.Anna Zaks1-2/+15
Inlining these functions is essential for correctness. We often have cases where we do not inline calls. For example, the shallow mode and when reanalyzing previously inlined ObjC methods as top level. llvm-svn: 174245
2012-12-06Use the BlockDecl captures list to infer the direct captures for a ↵Ted Kremenek1-4/+7
BlockDataRegion. Fixes <rdar://problem/12415065>. We still need to do a recursive walk to determine all static/global variables referenced by a block, which is needed for region invalidation. llvm-svn: 169481
2012-12-04Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth1-5/+4
uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
2012-11-03[analyzer] add LocationContext::inTopFrame() helper.Anna Zaks1-0/+4
llvm-svn: 167351
2012-09-24Add clarifying comment.Ted Kremenek1-0/+2
llvm-svn: 164557
2012-09-21Implement faux-body-synthesis of well-known functions in the static analyzer ↵Ted Kremenek1-6/+25
when their implementations are unavailable. Start by simulating dispatch_sync(). This change is largely a bunch of plumbing around something very simple. We use AnalysisDeclContext to conjure up a fake function body (using the current ASTContext) when one does not exist. This is controlled under the analyzer-config option "faux-bodies", which is off by default. The plumbing in this patch is largely to pass the necessary machinery around. CallEvent needs the AnalysisDeclContextManager to get the function definition, as one may get conjured up lazily. BugReporter and PathDiagnosticLocation needed to be relaxed to handle invalid locations, as the conjured body has no real source locations. We do some primitive recovery in diagnostic generation to generate some reasonable locations (for arrows and events), but it can be improved. llvm-svn: 164339
2012-09-05[analyzer] Always include destructors in the analysis CFG.Jordan Rose1-2/+4
While destructors will continue to not be inlined (unless the analyzer config option 'c++-inlining' is set to 'destructors'), leaving them out of the CFG is an incomplete model of the behavior of an object, and can cause false positive warnings (like PR13751, now working). Destructors for temporaries are still not on by default, since (a) we haven't actually checked this code to be sure it's fully correct (in particular, we probably need to be very careful with regard to lifetime-extension when a temporary is bound to a reference, C++11 [class.temporary]p5), and (b) ExprEngine doesn't actually do anything when it sees a temporary destructor in the CFG -- not even invalidate the object region. To enable temporary destructors, set the 'cfg-temporary-dtors' analyzer config option to '1'. The old -cfg-add-implicit-dtors cc1 option, which controlled all implicit destructors, has been removed. llvm-svn: 163264
2012-07-26[analyzer] Don't crash on implicit statements inside initializers.Jordan Rose1-1/+9
Our BugReporter knows how to deal with implicit statements: it looks in the ParentMap until it finds a parent with a valid location. However, since initializers are not in the body of a constructor, their sub-expressions are not in the ParentMap. That was easy enough to fix in AnalysisDeclContext. ...and then even once THAT was fixed, there's still an extra funny case of Objective-C object pointer fields under ARC, which are initialized with a top-level ImplicitValueInitExpr. To catch these cases, PathDiagnosticLocation will now fall back to the start of the current function if it can't find any other valid SourceLocations. This isn't great, but it's miles better than a crash. (All of this is only relevant when constructors and destructors are being inlined, i.e. under -cfg-add-initializers and -cfg-add-implicit-dtors.) llvm-svn: 160810
2012-07-04Drop the ASTContext.h include from DeclFriend.h and DeclTemplate.h.Benjamin Kramer1-0/+1
llvm-svn: 159723
2012-06-01static analyzer: add inlining support for directly called blocks.Ted Kremenek1-14/+27
llvm-svn: 157833
2012-04-28[analyzer] Remove references to idx::TranslationUnit. Index is dead, ↵Jordy Rose1-8/+3
cross-TU inlining never panned out. llvm-svn: 155751
2012-03-11Unify naming of LangOptions variable/get function across the Clang stack ↵David Blaikie1-1/+1
(Lex to AST). The member variable is always "LangOpts" and the member function is always "getLangOpts". Reviewed by Chris Lattner llvm-svn: 152536
2012-03-10Replace a map of boolean values with a set.Benjamin Kramer1-14/+8
No functionality change. llvm-svn: 152494
2012-03-10Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr toJohn McCall1-11/+7
track whether the referenced declaration comes from an enclosing local context. I'm amenable to suggestions about the exact meaning of this bit. llvm-svn: 152491
2012-03-01Move llvm/ADT/SaveAndRestore.h -> llvm/Support/SaveAndRestore.h.Argyrios Kyrtzidis1-1/+1
Needs llvm update. llvm-svn: 151829
2012-02-27Move "clang/Analysis/Support/SaveAndRestore.h" to "llvm/ADT/SaveAndRestore.h"Argyrios Kyrtzidis1-1/+1
to make it more widely available. Depends on llvm commit r151564 llvm-svn: 151566
2011-12-22Colorize and condense CFG pretty-printing.Ted Kremenek1-2/+2
llvm-svn: 147203
2011-12-22Enhance AnalysisDeclContext::getReferencedBlockVars() to understand ↵Ted Kremenek1-1/+11
PseudoObjExprs. It turns out that the information collected by this method is a super set of the captured variables in BlockDecl. llvm-svn: 147122
2011-11-14[analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that ↵Ted Kremenek1-0/+9
capture the 'self' variable of the enclosing ObjC method decl. Fixes <rdar://problem/10380300>. llvm-svn: 144556
2011-10-24Actually rename the file AnalysisContext.cpp -> AnalysisDeclContext.cppChandler Carruth1-0/+454
to match the CMakeLists.txt change in r142782; this should fix the CMake build. llvm-svn: 142784