aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/AnalysisBasedWarnings.cpp25
-rw-r--r--test/SemaCXX/warn-missing-noreturn.cpp10
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index 2f02e158cb..99f19fca78 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -121,26 +121,29 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
const CFGBlock& B = **I;
if (!live[B.getBlockID()])
continue;
- if (B.size() == 0) {
+
+ // Destructors can appear after the 'return' in the CFG. This is
+ // normal. We need to look pass the destructors for the return
+ // statement (if it exists).
+ CFGBlock::const_reverse_iterator ri = B.rbegin(), re = B.rend();
+ for ( ; ri != re ; ++ri) {
+ CFGElement CE = *ri;
+ if (isa<CFGStmt>(CE))
+ break;
+ }
+
+ // No more CFGElements in the block?
+ if (ri == re) {
if (B.getTerminator() && isa<CXXTryStmt>(B.getTerminator())) {
HasAbnormalEdge = true;
continue;
}
-
// A labeled empty statement, or the entry block...
HasPlainEdge = true;
continue;
}
- CFGElement CE = B[B.size()-1];
-
- if (!isa<CFGStmt>(CE)) {
- HasPlainEdge = true;
- continue;
- }
- CFGStmt CS = CE.getAs<CFGStmt>();
- if (!CS.isValid())
- continue;
+ CFGStmt CS = cast<CFGStmt>(*ri);
Stmt *S = CS.getStmt();
if (isa<ReturnStmt>(S)) {
HasLiveReturn = true;
diff --git a/test/SemaCXX/warn-missing-noreturn.cpp b/test/SemaCXX/warn-missing-noreturn.cpp
index 08a20b627c..4caff66af7 100644
--- a/test/SemaCXX/warn-missing-noreturn.cpp
+++ b/test/SemaCXX/warn-missing-noreturn.cpp
@@ -93,3 +93,13 @@ int rdar8875247_test() {
rdar8875247 f;
} // expected-warning{{control reaches end of non-void function}}
+struct rdar8875247_B {
+ rdar8875247_B();
+ ~rdar8875247_B();
+};
+
+rdar8875247_B test_rdar8875247_B() {
+ rdar8875247_B f;
+ return f;
+} // no-warning
+