aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGExpr.cpp8
-rw-r--r--test/CodeGenCXX/references.cpp13
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index bb9f20003a..299bb6b4a4 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -78,6 +78,14 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
return RValue::get(LV.getAddress());
}
+ if (!hasAggregateLLVMType(E->getType())) {
+ // Make a temporary variable that we can bind the reference to.
+ llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(E->getType()),
+ "reftmp");
+ EmitStoreOfScalar(EmitScalarExpr(E), Temp, false, E->getType());
+ return RValue::get(Temp);
+ }
+
CGM.ErrorUnsupported(E, "reference binding");
return GetUndefRValue(DestType);
}
diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp
index 2b2b1ff896..a1a6c0ae71 100644
--- a/test/CodeGenCXX/references.cpp
+++ b/test/CodeGenCXX/references.cpp
@@ -19,25 +19,32 @@ void t3() {
struct C {};
+void f(const bool&);
void f(const int&);
void f(const _Complex int&);
void f(const C&);
+void test_bool() {
+ bool a = true;
+ f(a);
+
+ f(true);
+}
+
void test_scalar() {
int a = 10;
-
f(a);
+
+ f(10);
}
void test_complex() {
_Complex int a = 10i;
-
f(a);
}
void test_aggregate() {
C c;
-
f(c);
}