aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-20 01:03:17 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-20 01:03:17 +0000
commite04d1c77ae15a6e973e2fac7723f6c364884f58d (patch)
tree5f82922adb4b6bd1ada21e0a7421b9460606df42
parent4bbab92167713bf4f79c0b14dcc4e83d08ac4019 (diff)
Add support for binding references to scalar rvalues.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72153 91177308-0d34-0410-b5e6-96231b3b80d8
-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);
}