]> granicus.if.org Git - clang/commitdiff
Handle emitting the assignment operator when the lhs is a reference. Fixes PR5227.
authorAnders Carlsson <andersca@mac.com>
Mon, 19 Oct 2009 18:28:22 +0000 (18:28 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 19 Oct 2009 18:28:22 +0000 (18:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84518 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/references.cpp

index 6542aa50d2661b554e3a1a0d1188277f3d7297e1..29ca900ed318d66b9aa18acb4481f3c25b77cf93 100644 (file)
@@ -1367,6 +1367,16 @@ LValue CodeGenFunction::EmitBinaryOperatorLValue(const BinaryOperator *E) {
   if (E->getOpcode() != BinaryOperator::Assign)
     return EmitUnsupportedLValue(E, "binary l-value expression");
 
+  if (!hasAggregateLLVMType(E->getType())) {
+    // Emit the LHS as an l-value.
+    LValue LV = EmitLValue(E->getLHS());
+    
+    llvm::Value *RHS = EmitScalarExpr(E->getRHS());
+    EmitStoreOfScalar(RHS, LV.getAddress(), LV.isVolatileQualified(), 
+                      E->getType());
+    return LV;
+  }
+  
   llvm::Value *Temp = CreateTempAlloca(ConvertType(E->getType()));
   EmitAggExpr(E, Temp, false);
   // FIXME: Are these qualifiers correct?
index 682aab310d0b40a628bfd5b1401067492d2476c9..8e0e1cbe84e831cec107e7181468a38167512c21 100644 (file)
@@ -130,3 +130,9 @@ namespace T {
   }
 }
 
+// PR5227.
+namespace PR5227 {
+void f(int &a) {
+  (a = 10) = 20;
+}
+}