summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Frontend
diff options
context:
space:
mode:
authorAnna Zaks <ganna@apple.com>2012-05-30 23:14:48 +0000
committerAnna Zaks <ganna@apple.com>2012-05-30 23:14:48 +0000
commit34d89b7ddc709c48baf87d68c401f3565e67a2b5 (patch)
tree82349b44390f3f4da134098c0db13521771daec2 /clang/lib/StaticAnalyzer/Frontend
parent5541f6026ec31ad3cba33b436bbd30185a936ac6 (diff)
downloadbcm5719-llvm-34d89b7ddc709c48baf87d68c401f3565e67a2b5.tar.gz
bcm5719-llvm-34d89b7ddc709c48baf87d68c401f3565e67a2b5.zip
[analyzer]Fix another occurrence of iterator invalidation (LocalTUDecls)
Follow up in r155693, r155680. Prevents a hard to reproduce crash with the following stack trace: 3 libsystem_c.dylib 0x00007ff55a835050 _sigtramp + 18446744029881443184 4 clang 0x0000000106218e97 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) + 519 5 clang 0x0000000105cf3002 clang::ParseAST(clang::Sema&, bool, bool) + 690 6 clang 0x00000001059a41d8 clang::ASTFrontendAction::ExecuteAction() + 312 7 clang 0x00000001059a3df7 clang::FrontendAction::Execute() + 231 8 clang 0x00000001059b0ecc clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 860 9 clang 0x000000010595e451 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 961 10 clang 0x0000000105947f29 cc1_main(char const**, char const**, char const*, void*) + 969 11 clang 0x0000000105958259 main + 473 12 clang 0x0000000105947b34 start + 52 llvm-svn: 157721
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend')
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 993d8414906..a067043a555 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -315,10 +315,16 @@ void AnalysisConsumer::HandleDeclsGallGraph() {
// Otherwise, use the Callgraph to derive the order.
// Build the Call Graph.
CallGraph CG;
+
// Add all the top level declarations to the graph.
- for (SetOfDecls::iterator I = LocalTUDecls.begin(),
- E = LocalTUDecls.end(); I != E; ++I)
- CG.addToCallGraph(*I);
+ // Note: TraverseDecl may modify LocalTUDecls, but only by appending more
+ // entries. Thus we don't use an iterator, but rely on LocalTUDecls
+ // random access. By doing so, we automatically compensate for iterators
+ // possibly being invalidated, although this is a bit slower.
+ const unsigned n = LocalTUDecls.size();
+ for (unsigned i = 0 ; i < n ; ++i) {
+ CG.addToCallGraph(LocalTUDecls[i]);
+ }
// Find the top level nodes - children of root + the unreachable (parentless)
// nodes.
OpenPOWER on IntegriCloud