]> granicus.if.org Git - clang/commitdiff
Generalize handling for unreachable code warnings to all binary operators.
authorMike Stump <mrs@apple.com>
Fri, 15 Jan 2010 23:33:51 +0000 (23:33 +0000)
committerMike Stump <mrs@apple.com>
Fri, 15 Jan 2010 23:33:51 +0000 (23:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93584 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/warn-unreachable.c

index d81e187bb304d2bffbd1afed00ae23fc5b1c3605..b308613a46f7aa23ab210ba085d82cf627906619 100644 (file)
@@ -1339,24 +1339,21 @@ static SourceLocation GetUnreachableLoc(CFGBlock &b) {
 
   switch (S->getStmtClass()) {
   case Expr::BinaryOperatorClass: {
-    BinaryOperator *Op = cast<BinaryOperator>(S);
-    if (Op->getOpcode() == BinaryOperator::Comma) {
-      if (b.size() < 2) {
-        CFGBlock *n = &b;
-        while (1) {
-          if (n->getTerminator())
-            return n->getTerminator()->getLocStart();
-          if (n->succ_size() != 1)
-            return SourceLocation();
-          n = n[0].succ_begin()[0];
-          if (n->pred_size() != 1)
-            return SourceLocation();
-          if (!n->empty())
-            return n[0][0].getStmt()->getLocStart();
-        }
+    if (b.size() < 2) {
+      CFGBlock *n = &b;
+      while (1) {
+        if (n->getTerminator())
+          return n->getTerminator()->getLocStart();
+        if (n->succ_size() != 1)
+          return SourceLocation();
+        n = n[0].succ_begin()[0];
+        if (n->pred_size() != 1)
+          return SourceLocation();
+        if (!n->empty())
+          return n[0][0].getStmt()->getLocStart();
       }
-      return b[1].getStmt()->getLocStart();
     }
+    return b[1].getStmt()->getLocStart();
   }
   default: ;
   }
index 08ad6536987b62805d3049cae17cc7c88c6c6fac..205c39c6e2cc11f4d790936256d6ae02acc8335c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code
+// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value
 
 int halt() __attribute__((noreturn));
 int live();
@@ -35,9 +35,9 @@ void test2() {
       dead();   // expected-warning {{will never be executed}}
 
   case 3:
-    live(),
-      halt();
-    dead();     // expected-warning {{will never be executed}}
+  live()
+    + halt();
+  dead();     // expected-warning {{will never be executed}}
 
   case 4:
   a4: