diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp b/contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp index 5ff7842..465f0c3 100644 --- a/contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp +++ b/contrib/llvm/tools/clang/lib/Analysis/AnalysisDeclContext.cpp @@ -157,6 +157,19 @@ AnalysisDeclContext::getBlockForRegisteredExpression(const Stmt *stmt) { return itr->second; } +/// Add each synthetic statement in the CFG to the parent map, using the +/// source statement's parent. +static void addParentsForSyntheticStmts(const CFG *TheCFG, ParentMap &PM) { + if (!TheCFG) + return; + + for (CFG::synthetic_stmt_iterator I = TheCFG->synthetic_stmt_begin(), + E = TheCFG->synthetic_stmt_end(); + I != E; ++I) { + PM.setParent(I->first, PM.getParent(I->second)); + } +} + CFG *AnalysisDeclContext::getCFG() { if (!cfgBuildOptions.PruneTriviallyFalseEdges) return getUnoptimizedCFG(); @@ -167,6 +180,9 @@ CFG *AnalysisDeclContext::getCFG() { // Even when the cfg is not successfully built, we don't // want to try building it again. builtCFG = true; + + if (PM) + addParentsForSyntheticStmts(cfg.get(), *PM); } return cfg.get(); } @@ -180,6 +196,9 @@ CFG *AnalysisDeclContext::getUnoptimizedCFG() { // Even when the cfg is not successfully built, we don't // want to try building it again. builtCompleteCFG = true; + + if (PM) + addParentsForSyntheticStmts(completeCFG.get(), *PM); } return completeCFG.get(); } @@ -222,6 +241,10 @@ ParentMap &AnalysisDeclContext::getParentMap() { PM->addStmt((*I)->getInit()); } } + if (builtCFG) + addParentsForSyntheticStmts(getCFG(), *PM); + if (builtCompleteCFG) + addParentsForSyntheticStmts(getUnoptimizedCFG(), *PM); } return *PM; } @@ -387,7 +410,7 @@ bool LocationContext::isParentOf(const LocationContext *LC) const { return false; } -void LocationContext::dumpStack() const { +void LocationContext::dumpStack(raw_ostream &OS, StringRef Indent) const { ASTContext &Ctx = getAnalysisDeclContext()->getASTContext(); PrintingPolicy PP(Ctx.getLangOpts()); PP.TerseOutput = 1; @@ -396,15 +419,15 @@ void LocationContext::dumpStack() const { for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) { switch (LCtx->getKind()) { case StackFrame: - llvm::errs() << '#' << Frame++ << ' '; - cast<StackFrameContext>(LCtx)->getDecl()->print(llvm::errs(), PP); - llvm::errs() << '\n'; + OS << Indent << '#' << Frame++ << ' '; + cast<StackFrameContext>(LCtx)->getDecl()->print(OS, PP); + OS << '\n'; break; case Scope: - llvm::errs() << " (scope)\n"; + OS << Indent << " (scope)\n"; break; case Block: - llvm::errs() << " (block context: " + OS << Indent << " (block context: " << cast<BlockInvocationContext>(LCtx)->getContextData() << ")\n"; break; @@ -412,6 +435,10 @@ void LocationContext::dumpStack() const { } } +void LocationContext::dumpStack() const { + dumpStack(llvm::errs()); +} + //===----------------------------------------------------------------------===// // Lazily generated map to query the external variables referenced by a Block. //===----------------------------------------------------------------------===// |