Skip to content

Commit b35635e

Browse files
committed
Remove a kludge from analysis based warnings that used to detect
temporaries with no-return destructors. The CFG now properly supports temporaries and implicit destructors which both makes this kludge no longer work, and conveniently removes the need for it. Turn on CFG handling of implicit destructors and initializers. Several ad-hoc benchmarks don't indicate any measurable performance impact from growing the CFG, and it fixes real correctness problems with warnings. As a result of turning on these CFG elements, we started to tickle an inf-loop in the unreachable code logic used for warnings. The fix is trivial. llvm-svn: 123056
1 parent bf4832c commit b35635e

File tree

3 files changed

+6
-22
lines changed

3 files changed

+6
-22
lines changed

clang/lib/Analysis/ReachableCode.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ static SourceLocation GetUnreachableLoc(const CFGBlock &b, SourceRange &R1,
3030
unsigned sn = 0;
3131
R1 = R2 = SourceRange();
3232

33-
top:
3433
if (sn < b.size()) {
3534
CFGStmt CS = b[sn].getAs<CFGStmt>();
3635
if (!CS)
37-
goto top;
38-
36+
return SourceLocation();
37+
3938
S = CS.getStmt();
4039
} else if (b.getTerminator())
4140
S = b.getTerminator();

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,6 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
177177
}
178178
}
179179
}
180-
// FIXME: Remove this hack once temporaries and their destructors are
181-
// modeled correctly by the CFG.
182-
if (ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(S)) {
183-
for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I) {
184-
const FunctionDecl *FD = E->getTemporary(I)->getDestructor();
185-
if (FD->hasAttr<NoReturnAttr>() ||
186-
FD->getType()->getAs<FunctionType>()->getNoReturnAttr()) {
187-
NoReturnEdge = true;
188-
HasFakeEdge = true;
189-
break;
190-
}
191-
}
192-
}
193180
// FIXME: Add noreturn message sends.
194181
if (NoReturnEdge == false)
195182
HasPlainEdge = true;
@@ -405,7 +392,8 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
405392

406393
// Don't generate EH edges for CallExprs as we'd like to avoid the n^2
407394
// explosion for destrutors that can result and the compile time hit.
408-
AnalysisContext AC(D, 0, false);
395+
AnalysisContext AC(D, 0, /*useUnoptimizedCFG=*/false, /*addehedges=*/false,
396+
/*addImplicitDtors=*/true, /*addInitializers=*/true);
409397

410398
// Warning: check missing 'return'
411399
if (P.enableCheckFallThrough) {

clang/test/SemaCXX/return-noreturn.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ namespace PR6884 {
77
~abort_struct() __attribute__((noreturn));
88
};
99

10-
// FIXME: Should either of these actually warn, since the destructor is
11-
// marked noreturn?
12-
1310
int f() {
1411
abort_struct();
15-
} // expected-warning{{control reaches end of non-void function}}
12+
}
1613

1714
int f2() {
1815
abort_struct s;
19-
} // expected-warning{{control reaches end of non-void function}}
16+
}
2017
}

0 commit comments

Comments
 (0)