[cfe-commits] r95311 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/conditional-temporaries.cpp

Anders Carlsson andersca at mac.com
Thu Feb 4 09:26:01 PST 2010


Author: andersca
Date: Thu Feb  4 11:26:01 2010
New Revision: 95311

URL: http://llvm.org/viewvc/llvm-project?rev=95311&view=rev
Log:
Fix a bug where we would not mark temporaries as conditional when emitting a conditional operator as an lvalue.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Feb  4 11:26:01 2010
@@ -1538,9 +1538,12 @@
     
     EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock);
     
+    // Any temporaries created here are conditional.
+    BeginConditionalBranch();
     EmitBlock(LHSBlock);
-
     LValue LHS = EmitLValue(E->getLHS());
+    EndConditionalBranch();
+    
     if (!LHS.isSimple())
       return EmitUnsupportedLValue(E, "conditional operator");
 
@@ -1548,8 +1551,11 @@
     Builder.CreateStore(LHS.getAddress(), Temp);
     EmitBranch(ContBlock);
     
+    // Any temporaries created here are conditional.
+    BeginConditionalBranch();
     EmitBlock(RHSBlock);
     LValue RHS = EmitLValue(E->getRHS());
+    EndConditionalBranch();
     if (!RHS.isSimple())
       return EmitUnsupportedLValue(E, "conditional operator");
 

Modified: cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp?rev=95311&r1=95310&r2=95311&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/conditional-temporaries.cpp Thu Feb  4 11:26:01 2010
@@ -9,14 +9,20 @@
   A() : i(0) { ctorcalls++; }
   ~A() { dtorcalls++; }
   int i;
+  
+  friend const A& operator<<(const A& a, int n) {
+    return a;
+  }
 };
 
 void g(int) { }
+void g(const A&) { }
 
 void f1(bool b) {
   g(b ? A().i : 0);
   g(b || A().i);
   g(b && A().i);
+  g(b ? A() << 1 : A() << 2);
 }
 
 struct Checker {





More information about the cfe-commits mailing list