]> granicus.if.org Git - clang/commitdiff
- Fixed subexpressions evaluation order for binary operators to match order in code...
authorMarcin Swiderski <marcin.sfider@gmail.com>
Sun, 24 Oct 2010 08:21:40 +0000 (08:21 +0000)
committerMarcin Swiderski <marcin.sfider@gmail.com>
Sun, 24 Oct 2010 08:21:40 +0000 (08:21 +0000)
- Fixed test cases for unreachable code warnings produced by Sema.

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

lib/Analysis/CFG.cpp
test/Sema/warn-unreachable.c

index e44f0fc90b248d8d3eb306e008a87a4abc813563..6f7be9a252ce198622ca890ffd6712445c99c80e 100644 (file)
@@ -912,15 +912,17 @@ CFGBlock *CFGBuilder::VisitBinaryOperator(BinaryOperator *B,
       AppendStmt(Block, B, asc);
     }
 
-    // If visiting RHS causes us to finish 'Block' and the LHS doesn't
-    // create a new block, then we should return RBlock.  Otherwise
-    // we'll incorrectly return NULL.
-    CFGBlock *RBlock = Visit(B->getRHS());
-    CFGBlock *LBlock = Visit(B->getLHS(), AddStmtChoice::AsLValueNotAlwaysAdd);
-    return LBlock ? LBlock : RBlock;
+    Visit(B->getLHS(), AddStmtChoice::AsLValueNotAlwaysAdd);
+    return Visit(B->getRHS());
   }
 
-  return VisitStmt(B, asc);
+  if (asc.alwaysAdd()) {
+    autoCreateBlock();
+    AppendStmt(Block, B, asc);
+  }
+
+  Visit(B->getRHS());
+  return Visit(B->getLHS());
 }
 
 CFGBlock *CFGBuilder::VisitBlockExpr(BlockExpr *E, AddStmtChoice asc) {
index 17a2c7c9a67c8d28d17b4359b7597f146f0edb59..20e0c3172401f4077c79eb4e092cce1aed607c16 100644 (file)
@@ -35,8 +35,8 @@ void test2() {
       dead();   // expected-warning {{will never be executed}}
 
   case 3:
-  live()        // expected-warning {{will never be executed}}
-    +           
+  live()
+    +           // expected-warning {{will never be executed}}
     halt();
   dead();
 
@@ -75,8 +75,8 @@ void test2() {
     goto c6;
   case 7:
     halt()
-      +         // expected-warning {{will never be executed}}
-      dead();
+      +
+      dead();   // expected-warning {{will never be executed}}
     -           // expected-warning {{will never be executed}}
       halt();
   case 8: