]> granicus.if.org Git - clang/commitdiff
When returning from a function that has a reference return type, use
authorDouglas Gregor <dgregor@apple.com>
Wed, 24 Mar 2010 23:14:04 +0000 (23:14 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 24 Mar 2010 23:14:04 +0000 (23:14 +0000)
EmitReferenceBindingToExpr() rather than assuming we have an
lvalue. This is just the lowest hanging fruit for PR6024, which still
requires a bit of work.

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

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

index a889e55a9e8031c70412ff09444d80c96eba3f56..ae2f791719d3d149688d253d2a6634c0e6bed441 100644 (file)
@@ -607,7 +607,8 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) {
   } else if (FnRetTy->isReferenceType()) {
     // If this function returns a reference, take the address of the expression
     // rather than the value.
-    Builder.CreateStore(EmitLValue(RV).getAddress(), ReturnValue);
+    RValue Result = EmitReferenceBindingToExpr(RV, false);
+    Builder.CreateStore(Result.getScalarVal(), ReturnValue);
   } else if (!hasAggregateLLVMType(RV->getType())) {
     Builder.CreateStore(EmitScalarExpr(RV), ReturnValue);
   } else if (RV->getType()->isAnyComplexType()) {
index 39b5909fb9a4feb5a3ec5695d8761fc95be88606..a15d4069c204138da4f675309e176dd461d3e2db 100644 (file)
@@ -147,3 +147,10 @@ void f(int &a) {
 struct s0;
 struct s1 { struct s0 &s0; };
 void f0(s1 a) { s1 b = a; }
+
+// PR6024
+// CHECK: @_Z2f2v()
+// CHECK: alloca
+// CHECK: store
+// CHECK: load
+const int &f2() { return 0; }