[cfe-commits] r72153 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp
Anders Carlsson
andersca at mac.com
Tue May 19 18:03:18 PDT 2009
Author: andersca
Date: Tue May 19 20:03:17 2009
New Revision: 72153
URL: http://llvm.org/viewvc/llvm-project?rev=72153&view=rev
Log:
Add support for binding references to scalar rvalues.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/references.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72153&r1=72152&r2=72153&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 19 20:03:17 2009
@@ -78,6 +78,14 @@
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);
}
Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72153&r1=72152&r2=72153&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Tue May 19 20:03:17 2009
@@ -19,25 +19,32 @@
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);
}
More information about the cfe-commits
mailing list