From 86aa0cdfd5aa7b099efbcd612a014d1b5f0ff799 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Mon, 19 Oct 2009 18:28:22 +0000 Subject: [PATCH] Handle emitting the assignment operator when the lhs is a reference. Fixes PR5227. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84518 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 10 ++++++++++ test/CodeGenCXX/references.cpp | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 6542aa50d2..29ca900ed3 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -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? diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 682aab310d..8e0e1cbe84 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -130,3 +130,9 @@ namespace T { } } +// PR5227. +namespace PR5227 { +void f(int &a) { + (a = 10) = 20; +} +} -- 2.50.1