[cfe-commits] r94341 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/temp-order.cpp

Anders Carlsson andersca at mac.com
Sat Jan 23 16:20:05 PST 2010


Author: andersca
Date: Sat Jan 23 18:20:05 2010
New Revision: 94341

URL: http://llvm.org/viewvc/llvm-project?rev=94341&view=rev
Log:
Fix a nasty bug where temporaries weren't marked as being conditional in some cases.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGenCXX/temp-order.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=94341&r1=94340&r2=94341&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Sat Jan 23 18:20:05 2010
@@ -431,7 +431,11 @@
       EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, FalseBlock);
       EmitBlock(LHSTrue);
 
+      // Any temporaries created here are conditional.
+      StartConditionalBranch();
       EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock);
+      FinishConditionalBranch();
+
       return;
     } else if (CondBOp->getOpcode() == BinaryOperator::LOr) {
       // If we have "0 || X", simplify the code.  "1 || X" would have constant
@@ -454,7 +458,11 @@
       EmitBranchOnBoolExpr(CondBOp->getLHS(), TrueBlock, LHSFalse);
       EmitBlock(LHSFalse);
 
+      // Any temporaries created here are conditional.
+      StartConditionalBranch();
       EmitBranchOnBoolExpr(CondBOp->getRHS(), TrueBlock, FalseBlock);
+      FinishConditionalBranch();
+
       return;
     }
   }

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=94341&r1=94340&r2=94341&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat Jan 23 18:20:05 2010
@@ -283,6 +283,9 @@
   /// FinishConditionalBranch - Should be called after a conditional part of an
   /// expression has been emitted.
   void FinishConditionalBranch() {
+    assert(ConditionalBranchLevel != 0 &&
+           "Conditional branch mismatch!");
+    
     --ConditionalBranchLevel;
   }
 

Modified: cfe/trunk/test/CodeGenCXX/temp-order.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/temp-order.cpp?rev=94341&r1=94340&r2=94341&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/temp-order.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/temp-order.cpp Sat Jan 23 18:20:05 2010
@@ -129,10 +129,30 @@
   return tt.Product;
 }
 
+// 5, 2
+static unsigned f7() {
+  TempTracker tt;
+  {
+    (void)((A(tt, 2, false) && A(tt, 3, false)) || A(tt, 5, false));
+  }
+  return tt.Product;
+}
+
+// 5, 2
+static unsigned f8() {
+  TempTracker tt;
+  
+  {
+    (void)((A(tt, 2) || A(tt, 3)) && A(tt, 5));
+  }
+  return tt.Product;
+}
+
 extern "C" void error();
 extern "C" void print(const char *Name, unsigned N);
 
-#define ORDER3(a, b, c) (pow(a, 1) * pow(b, 2) * pow(c, 3))
+#define ORDER2(a, b) (pow(a, 1) * pow(b, 2))
+#define ORDER3(a, b, c) (ORDER2(a, b) * pow(c, 3))
 #define ORDER4(a, b, c, d) (ORDER3(a, b, c) * pow(d, 4))
 #define ORDER5(a, b, c, d, e) (ORDER4(a, b, c, d) * pow(e, 5))
 #define ORDER6(a, b, c, d, e, f) (ORDER5(a, b, c, d, e) * pow(f, 6))
@@ -171,6 +191,16 @@
   print("f6", f6());
   if (f6() != ORDER6(3, 7, 11, 5, 13, 2))
     error();
+
+//  CHECK: call void @print(i8* {{.*}}, i32 20)
+  print("f7", f7());
+  if (f7() != ORDER2(5, 2))
+    error();
+
+//  CHECK: call void @print(i8* {{.*}}, i32 20)
+  print("f8", f8());
+  if (f8() != ORDER2(5, 2))
+    error();
 }
 
 





More information about the cfe-commits mailing list