]> granicus.if.org Git - clang/commitdiff
Fix a bug where we would not mark temporaries as conditional when emitting a conditio...
authorAnders Carlsson <andersca@mac.com>
Thu, 4 Feb 2010 17:26:01 +0000 (17:26 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 4 Feb 2010 17:26:01 +0000 (17:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95311 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/conditional-temporaries.cpp

index 2ceefae0a0f77a8301da8b2b66b310a54ed250b3..563db0b2be1faf7832f14f39ca75b4977ec79c7a 100644 (file)
@@ -1538,9 +1538,12 @@ CodeGenFunction::EmitConditionalOperatorLValue(const ConditionalOperator* E) {
     
     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 @@ CodeGenFunction::EmitConditionalOperatorLValue(const ConditionalOperator* E) {
     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");
 
index 66fd803c2ee88300eeefc6a1558f097c6c9f4e54..b8ea5129d401d96272c9fdf36db17d2bf3ed4301 100644 (file)
@@ -9,14 +9,20 @@ struct A {
   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 {