]> granicus.if.org Git - clang/commitdiff
Remove a kludge from analysis based warnings that used to detect
authorChandler Carruth <chandlerc@gmail.com>
Sat, 8 Jan 2011 06:54:40 +0000 (06:54 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 8 Jan 2011 06:54:40 +0000 (06:54 +0000)
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.

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

lib/Analysis/ReachableCode.cpp
lib/Sema/AnalysisBasedWarnings.cpp
test/SemaCXX/return-noreturn.cpp

index b9585800c9e828762e4efcb4ea5204e40251a42d..802b990143d404575c61e2aab7a0a9b9e899564b 100644 (file)
@@ -30,12 +30,11 @@ static SourceLocation GetUnreachableLoc(const CFGBlock &b, SourceRange &R1,
   unsigned sn = 0;
   R1 = R2 = SourceRange();
 
-top:
   if (sn < b.size()) {
     CFGStmt CS = b[sn].getAs<CFGStmt>();
     if (!CS)
-      goto top;
-    
+      return SourceLocation();
+
     S = CS.getStmt(); 
   } else if (b.getTerminator())
     S = b.getTerminator();
index f4fde40bfba8305c1f8952eb0e4ba6b902132605..20a503d6a56ff72d07b22cc2763476c7378ef348 100644 (file)
@@ -177,19 +177,6 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
         }
       }
     }
-    // FIXME: Remove this hack once temporaries and their destructors are
-    // modeled correctly by the CFG.
-    if (ExprWithCleanups *E = dyn_cast<ExprWithCleanups>(S)) {
-      for (unsigned I = 0, N = E->getNumTemporaries(); I != N; ++I) {
-        const FunctionDecl *FD = E->getTemporary(I)->getDestructor();
-        if (FD->hasAttr<NoReturnAttr>() ||
-            FD->getType()->getAs<FunctionType>()->getNoReturnAttr()) {
-          NoReturnEdge = true;
-          HasFakeEdge = true;
-          break;
-        }
-      }
-    }
     // FIXME: Add noreturn message sends.
     if (NoReturnEdge == false)
       HasPlainEdge = true;
@@ -405,7 +392,8 @@ AnalysisBasedWarnings::IssueWarnings(sema::AnalysisBasedWarnings::Policy P,
 
   // Don't generate EH edges for CallExprs as we'd like to avoid the n^2
   // explosion for destrutors that can result and the compile time hit.
-  AnalysisContext AC(D, 0, false);
+  AnalysisContext AC(D, 0, /*useUnoptimizedCFG=*/false, /*addehedges=*/false,
+                     /*addImplicitDtors=*/true, /*addInitializers=*/true);
 
   // Warning: check missing 'return'
   if (P.enableCheckFallThrough) {
index dfd548732150437db19f643123ee32800e2d1302..f7072b21771ea989fa81250455c2e25e40f52a53 100644 (file)
@@ -7,14 +7,11 @@ namespace PR6884 {
     ~abort_struct() __attribute__((noreturn));
   };
 
-  // FIXME: Should either of these actually warn, since the destructor is
-  //  marked noreturn?
-
   int f() {
     abort_struct();
-  } // expected-warning{{control reaches end of non-void function}}
+  }
 
   int f2() {
     abort_struct s;
-  } // expected-warning{{control reaches end of non-void function}}
+  }
 }