]> granicus.if.org Git - clang/commitdiff
An edge from a call expression to the exit block is only an abnormal edge
authorJohn McCall <rjmccall@apple.com>
Fri, 30 Apr 2010 07:10:06 +0000 (07:10 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 30 Apr 2010 07:10:06 +0000 (07:10 +0000)
if *none* of the successors of the call expression is the exit block.
This matters when a call of bool type is the condition of (say) a while
loop in a function with no statements after the loop.  This *can* happen
in C, but it's much more common in C++ because of overloaded operators.

Suppresses some substantial number of spurious -Wmissing-noreturn warnings.

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

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

index 7c1d8cbae9ee9ea47dc2f92babcab5570e68a9e1..dffdf6b4455d4801201eaa99b506a8a492a46372 100644 (file)
@@ -147,7 +147,8 @@ static ControlFlowKind CheckFallThrough(AnalysisContext &AC) {
 
     bool NoReturnEdge = false;
     if (CallExpr *C = dyn_cast<CallExpr>(S)) {
-      if (B.succ_begin()[0] != &cfg->getExit()) {
+      if (std::find(B.succ_begin(), B.succ_end(), &cfg->getExit())
+            == B.succ_end()) {
         HasAbnormalEdge = true;
         continue;
       }
index 5ca2eca61a936f7151f6268917f40db3d1ceea20..8016c3da5cc571dd085a52bfa6adc060b02f92e9 100644 (file)
@@ -27,3 +27,12 @@ template void B::g<int>(int); // expected-note {{in instantiation of function te
 struct X {
   virtual void g() { f(); }
 };
+
+namespace test1 {
+  bool condition();
+
+  // We don't want a warning here.
+  void foo() {
+    while (condition()) {}
+  }
+}