Expr::EvalResult *switchCond;
CFG::BuildOptions::ForcedBlkExprs::value_type *cachedEntry;
+ const Stmt *lastLookup;
public:
explicit CFGBuilder(ASTContext *astContext,
SwitchTerminatedBlock(NULL), DefaultCaseBlock(NULL),
TryTerminatedBlock(NULL), badCFG(false), BuildOpts(buildOpts),
switchExclusivelyCovered(false), switchCond(0),
- cachedEntry(0) {}
+ cachedEntry(0), lastLookup(0) {}
// buildCFG - Used by external clients to construct the CFG.
CFG* buildCFG(const Decl *D, Stmt *Statement);
// Interface to CFGBlock - adding CFGElements.
void appendStmt(CFGBlock *B, Stmt *S) {
- if (cachedEntry) {
- assert(cachedEntry->first == S);
+ if (alwaysAdd(S))
cachedEntry->second = B;
- cachedEntry = 0;
- }
B->appendStmt(S, cfg->getBumpVectorContext());
}
const Stmt *stmt) const {
return builder.alwaysAdd(stmt) || kind == AlwaysAdd;
}
-
+
bool CFGBuilder::alwaysAdd(const Stmt *stmt) {
if (!BuildOpts.forcedBlkExprs)
return false;
+
+ if (lastLookup == stmt) {
+ if (cachedEntry) {
+ assert(cachedEntry->first == stmt);
+ return true;
+ }
+ return false;
+ }
+ lastLookup = stmt;
+
+ // Perform the lookup!
CFG::BuildOptions::ForcedBlkExprs *fb = *BuildOpts.forcedBlkExprs;
- if (!fb)
+ if (!fb) {
+ // No need to update 'cachedEntry', since it will always be null.
+ assert(cachedEntry == 0);
return false;
+ }
CFG::BuildOptions::ForcedBlkExprs::iterator itr = fb->find(stmt);
- if (itr == fb->end())
+ if (itr == fb->end()) {
+ cachedEntry = 0;
return false;
-
+ }
+
cachedEntry = &*itr;
return true;
}
} while (0)
+// Test that we don't report divide-by-zero errors in unreachable code.
+// This test should be left as is, as it also tests CFG functionality.
+void radar9171946() {
+ if (0) {
+ 0 / (0 ? 1 : 0); // expected-warning {{expression result unused}}
+ }
+}
+
int test_pr8876() {
PR8876(0); // no-warning
PR8876_pos(0); // expected-warning{{indirection of non-volatile null pointer will be deleted, not trap}} expected-note{{consider using __builtin_trap() or qualifying pointer with 'volatile'}}