diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Analysis/CFG.cpp | 24 | ||||
-rw-r--r-- | lib/Analysis/CFGStmtMap.cpp | 19 | ||||
-rw-r--r-- | lib/Analysis/ReachableCode.cpp | 14 | ||||
-rw-r--r-- | lib/Checker/BugReporter.cpp | 16 | ||||
-rw-r--r-- | lib/Checker/GRExprEngine.cpp | 4 | ||||
-rw-r--r-- | lib/Checker/UnreachableCodeChecker.cpp | 18 | ||||
-rw-r--r-- | lib/Sema/AnalysisBasedWarnings.cpp | 6 |
7 files changed, 64 insertions, 37 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index cc3a388862..963d45dd98 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1846,15 +1846,19 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) { for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I) for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI) - FindSubExprAssignments(*BI, SubExprAssignments); + if (CFGStmt S = BI->getAs<CFGStmt>()) + FindSubExprAssignments(S, SubExprAssignments); for (CFG::iterator I=cfg.begin(), E=cfg.end(); I != E; ++I) { // Iterate over the statements again on identify the Expr* and Stmt* at the // block-level that are block-level expressions. - for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI) - if (Expr* Exp = dyn_cast<Expr>(*BI)) { + for (CFGBlock::iterator BI=(*I)->begin(), EI=(*I)->end(); BI != EI; ++BI) { + CFGStmt CS = BI->getAs<CFGStmt>(); + if (!CS.isValid()) + continue; + if (Expr* Exp = dyn_cast<Expr>(CS.getStmt())) { if (BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) { // Assignment expressions that are not nested within another @@ -1875,6 +1879,7 @@ static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) { unsigned x = M->size(); (*M)[Exp] = x; } + } // Look at terminators. The condition is a block-level expression. @@ -1959,9 +1964,13 @@ public: for (CFG::const_iterator I = cfg->begin(), E = cfg->end(); I != E; ++I ) { unsigned j = 1; for (CFGBlock::const_iterator BI = (*I)->begin(), BEnd = (*I)->end() ; - BI != BEnd; ++BI, ++j ) - StmtMap[*BI] = std::make_pair((*I)->getBlockID(),j); + BI != BEnd; ++BI, ++j ) { + CFGStmt CS = BI->getAs<CFGStmt>(); + if (!CS.isValid()) + continue; + StmtMap[CS] = std::make_pair((*I)->getBlockID(),j); } + } } virtual ~StmtPrinterHelper() {} @@ -2090,7 +2099,10 @@ public: static void print_stmt(llvm::raw_ostream &OS, StmtPrinterHelper* Helper, const CFGElement &E) { - Stmt *S = E; + CFGStmt CS = E.getAs<CFGStmt>(); + if (!CS) + return; + Stmt *S = CS.getStmt(); if (Helper) { // special printing for statement-expressions. diff --git a/lib/Analysis/CFGStmtMap.cpp b/lib/Analysis/CFGStmtMap.cpp index 965eca1b3c..3a030f9bdd 100644 --- a/lib/Analysis/CFGStmtMap.cpp +++ b/lib/Analysis/CFGStmtMap.cpp @@ -50,15 +50,18 @@ static void Accumulate(SMap &SM, CFGBlock *B) { // First walk the block-level expressions. for (CFGBlock::iterator I = B->begin(), E = B->end(); I != E; ++I) { const CFGElement &CE = *I; - if (Stmt *S = CE.getStmt()) { - CFGBlock *&Entry = SM[S]; - // If 'Entry' is already initialized (e.g., a terminator was already), - // skip. - if (Entry) - continue; + CFGStmt CS = CE.getAs<CFGStmt>(); + if (!CS.isValid()) + continue; + + CFGBlock *&Entry = SM[CS]; + // If 'Entry' is already initialized (e.g., a terminator was already), + // skip. + if (Entry) + continue; - Entry = B; - } + Entry = B; + } // Look at the label of the block. diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index eb3f7d4c0f..00882641db 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -31,9 +31,13 @@ static SourceLocation GetUnreachableLoc(const CFGBlock &b, SourceRange &R1, R1 = R2 = SourceRange(); top: - if (sn < b.size()) - S = b[sn].getStmt(); - else if (b.getTerminator()) + if (sn < b.size()) { + CFGStmt CS = b[sn].getAs<CFGStmt>(); + if (!CS) + goto top; + + S = CS.getStmt(); + } else if (b.getTerminator()) S = b.getTerminator(); else return SourceLocation(); @@ -43,7 +47,7 @@ top: const BinaryOperator *BO = cast<BinaryOperator>(S); if (BO->getOpcode() == BO_Comma) { if (sn+1 < b.size()) - return b[sn+1].getStmt()->getLocStart(); + return b[sn+1].getAs<CFGStmt>().getStmt()->getLocStart(); const CFGBlock *n = &b; while (1) { if (n->getTerminator()) @@ -54,7 +58,7 @@ top: if (n->pred_size() != 1) return SourceLocation(); if (!n->empty()) - return n[0][0].getStmt()->getLocStart(); + return n[0][0].getAs<CFGStmt>().getStmt()->getLocStart(); } } R1 = BO->getLHS()->getSourceRange(); diff --git a/lib/Checker/BugReporter.cpp b/lib/Checker/BugReporter.cpp index 5043d90526..a3f4f032a2 100644 --- a/lib/Checker/BugReporter.cpp +++ b/lib/Checker/BugReporter.cpp @@ -1165,15 +1165,15 @@ static void GenerateExtensivePathDiagnostic(PathDiagnostic& PD, } if (const BlockEntrance *BE = dyn_cast<BlockEntrance>(&P)) { - if (const Stmt* S = BE->getFirstStmt()) { - if (IsControlFlowExpr(S)) { - // Add the proper context for '&&', '||', and '?'. - EB.addContext(S); - } - else - EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt()); + if (CFGStmt S = BE->getFirstElement().getAs<CFGStmt>()) { + if (IsControlFlowExpr(S)) { + // Add the proper context for '&&', '||', and '?'. + EB.addContext(S); + } + else + EB.addExtendedContext(PDB.getEnclosingStmtLocation(S).asStmt()); } - + break; } } while (0); diff --git a/lib/Checker/GRExprEngine.cpp b/lib/Checker/GRExprEngine.cpp index bead4e1c1a..e01c645a89 100644 --- a/lib/Checker/GRExprEngine.cpp +++ b/lib/Checker/GRExprEngine.cpp @@ -634,7 +634,7 @@ void GRExprEngine::ProcessEndWorklist(bool hasWorkRemaining) { } void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) { - CurrentStmt = CE.getStmt(); + CurrentStmt = CE.getAs<CFGStmt>(); PrettyStackTraceLoc CrashInfo(getContext().getSourceManager(), CurrentStmt->getLocStart(), "Error evaluating statement"); @@ -721,7 +721,7 @@ void GRExprEngine::ProcessStmt(const CFGElement CE,GRStmtNodeBuilder& builder) { Builder->SetCleanedState(*I == EntryNode ? CleanedState : GetState(*I)); // Visit the statement. - if (CE.asLValue()) + if (CE.getAs<CFGStmt>().asLValue()) VisitLValue(cast<Expr>(CurrentStmt), *I, Dst); else Visit(CurrentStmt, *I, Dst); diff --git a/lib/Checker/UnreachableCodeChecker.cpp b/lib/Checker/UnreachableCodeChecker.cpp index 7a56c7f46b..12d13073b8 100644 --- a/lib/Checker/UnreachableCodeChecker.cpp +++ b/lib/Checker/UnreachableCodeChecker.cpp @@ -116,10 +116,12 @@ void UnreachableCodeChecker::VisitEndAnalysis(ExplodedGraph &G, // FIXME: This should be extended to include other unreachable markers, // such as llvm_unreachable. if (!CB->empty()) { - const Stmt *First = CB->front(); - if (const CallExpr *CE = dyn_cast<CallExpr>(First)) { - if (CE->isBuiltinCall(Ctx) == Builtin::BI__builtin_unreachable) - continue; + CFGElement First = CB->front(); + if (CFGStmt S = First.getAs<CFGStmt>()) { + if (const CallExpr *CE = dyn_cast<CallExpr>(S.getStmt())) { + if (CE->isBuiltinCall(Ctx) == Builtin::BI__builtin_unreachable) + continue; + } } } @@ -173,9 +175,11 @@ void UnreachableCodeChecker::FindUnreachableEntryPoints(const CFGBlock *CB) { // Find the Stmt* in a CFGBlock for reporting a warning const Stmt *UnreachableCodeChecker::getUnreachableStmt(const CFGBlock *CB) { - if (CB->size() > 0) - return CB->front().getStmt(); - else if (const Stmt *S = CB->getTerminator()) + for (CFGBlock::const_iterator I = CB->begin(), E = CB->end(); I != E; ++I) { + if (CFGStmt S = I->getAs<CFGStmt>()) + return S; + } + if (const Stmt *S = CB->getTerminator()) return S; else return 0; diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp index a46755bbd9..297d010995 100644 --- a/lib/Sema/AnalysisBasedWarnings.cpp +++ b/lib/Sema/AnalysisBasedWarnings.cpp @@ -129,7 +129,11 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) { HasPlainEdge = true; continue; } - Stmt *S = B[B.size()-1]; + CFGElement CE = B[B.size()-1]; + CFGStmt CS = CE.getAs<CFGStmt>(); + if (!CS.isValid()) + continue; + Stmt *S = CS.getStmt(); if (isa<ReturnStmt>(S)) { HasLiveReturn = true; continue; |