]> granicus.if.org Git - clang/commitdiff
Teach -Wreturn-type that destructors can appear
authorTed Kremenek <kremenek@apple.com>
Wed, 26 Jan 2011 04:49:52 +0000 (04:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 26 Jan 2011 04:49:52 +0000 (04:49 +0000)
after a 'return' in a CFGBlock.  This accidentally
was working before, but the false assumption that
'return' always appeared at the end of the block
was uncovered by a recent change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124280 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/warn-missing-noreturn.cpp

index 2f02e158cbd7c1d2ded50dbc9e46b12d8d7e5bd1..99f19fca78476b6c92600a22e3752a21f2e5ed48 100644 (file)
@@ -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;
index 08a20b627c54e04102e92643d6a95a07c506da7d..4caff66af703fd1292451d31250d4b72e4bfd492 100644 (file)
@@ -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
+