]> granicus.if.org Git - clang/commitdiff
Since the 'is aliased' bit is critical for correctness in C++, it
authorJohn McCall <rjmccall@apple.com>
Fri, 26 Aug 2011 07:31:35 +0000 (07:31 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 26 Aug 2011 07:31:35 +0000 (07:31 +0000)
really shouldn't be optional.  Fix the remaining place where a
temporary was being passed as potentially-aliased memory.

Fixes PR10756.

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

lib/CodeGen/CGExprAgg.cpp
lib/CodeGen/CGExprCXX.cpp
lib/CodeGen/CGValue.h
test/CodeGenCXX/conditional-expr-lvalue.cpp

index c42c87b1ac810effffc074ac8a0a9e5ff7dbdf58..632e016f0eaaf5c94e5e3b8c97a65c00220e1948 100644 (file)
@@ -444,7 +444,8 @@ void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
         LValue RHS = CGF.EmitLValue(E->getRHS());
         LValue LHS = CGF.EmitLValue(E->getLHS());
         Dest = AggValueSlot::forLValue(LHS, AggValueSlot::IsDestructed,
-                                       needsGC(E->getLHS()->getType()));
+                                       needsGC(E->getLHS()->getType()),
+                                       AggValueSlot::IsAliased);
         EmitFinalDestCopy(E, RHS, true);
         return;
       }
@@ -469,7 +470,8 @@ void AggExprEmitter::VisitBinAssign(const BinaryOperator *E) {
     // Codegen the RHS so that it stores directly into the LHS.
     AggValueSlot LHSSlot =
       AggValueSlot::forLValue(LHS, AggValueSlot::IsDestructed, 
-                              needsGC(E->getLHS()->getType()));
+                              needsGC(E->getLHS()->getType()),
+                              AggValueSlot::IsAliased);
     CGF.EmitAggExpr(E->getRHS(), LHSSlot, false);
     EmitFinalDestCopy(E, LHS, true);
   }
@@ -1052,7 +1054,8 @@ LValue CodeGenFunction::EmitAggExprToLValue(const Expr *E) {
   llvm::Value *Temp = CreateMemTemp(E->getType());
   LValue LV = MakeAddrLValue(Temp, E->getType());
   EmitAggExpr(E, AggValueSlot::forLValue(LV, AggValueSlot::IsNotDestructed,
-                                         AggValueSlot::DoesNotNeedGCBarriers));
+                                         AggValueSlot::DoesNotNeedGCBarriers,
+                                         AggValueSlot::IsNotAliased));
   return LV;
 }
 
index cdab82eaab6c8665a2ecaa7c60f9a6aa1246e150..b638e5ba0d689fffc8fe3a37f7d8c491491a262c 100644 (file)
@@ -705,7 +705,8 @@ static void StoreAnyExprIntoOneUnit(CodeGenFunction &CGF, const CXXNewExpr *E,
     AggValueSlot Slot
       = AggValueSlot::forAddr(NewPtr, AllocType.getQualifiers(),
                               AggValueSlot::IsDestructed,
-                              AggValueSlot::DoesNotNeedGCBarriers);
+                              AggValueSlot::DoesNotNeedGCBarriers,
+                              AggValueSlot::IsNotAliased);
     CGF.EmitAggExpr(Init, Slot);
   }
 }
index c448949d134d27c65d96d8cafb9eeb14e4aec5c5..36b318fb2fd542668cf5963600c1505657e55150 100644 (file)
@@ -383,7 +383,7 @@ public:
   static AggValueSlot forAddr(llvm::Value *addr, Qualifiers quals,
                               IsDestructed_t isDestructed,
                               NeedsGCBarriers_t needsGC,
-                              IsAliased_t isAliased = IsAliased,
+                              IsAliased_t isAliased,
                               IsZeroed_t isZeroed = IsNotZeroed) {
     AggValueSlot AV;
     AV.Addr = addr;
@@ -397,7 +397,7 @@ public:
 
   static AggValueSlot forLValue(LValue LV, IsDestructed_t isDestructed,
                                 NeedsGCBarriers_t needsGC,
-                                IsAliased_t isAliased = IsAliased,
+                                IsAliased_t isAliased,
                                 IsZeroed_t isZeroed = IsNotZeroed) {
     return forAddr(LV.getAddress(), LV.getQuals(),
                    isDestructed, needsGC, isAliased, isZeroed);
index a0843c40f071d968cc6ef51e001b3979c4150ddd..96aa8b07a664c933bfe72f699546d173b4e1a79a 100644 (file)
@@ -5,3 +5,16 @@ void f(bool flag) {
   
   (flag ? a : b) = 3;
 }
+
+// PR10756
+namespace test0 {
+  struct A {
+    A(const A &);
+    A &operator=(const A &);
+    A sub() const;
+    void foo() const;
+  };
+  void foo(bool cond, const A &a) {
+    (cond ? a : a.sub()).foo();
+  }
+}