[cfe-commits] r72150 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp
Anders Carlsson
andersca at mac.com
Tue May 19 17:36:58 PDT 2009
Author: andersca
Date: Tue May 19 19:36:58 2009
New Revision: 72150
URL: http://llvm.org/viewvc/llvm-project?rev=72150&view=rev
Log:
Bind references to lvalues correctly.
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=72150&r1=72149&r2=72150&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 19 19:36:58 2009
@@ -72,6 +72,12 @@
RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
QualType DestType) {
+ if (E->isLvalue(getContext()) == Expr::LV_Valid) {
+ // Emit the expr as an lvalue.
+ LValue LV = EmitLValue(E);
+ return RValue::get(LV.getAddress());
+ }
+
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=72150&r1=72149&r2=72150&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Tue May 19 19:36:58 2009
@@ -14,3 +14,30 @@
void t3() {
int b = gr;
}
+
+// Test reference binding.
+
+struct C {};
+
+void f(const int&);
+void f(const _Complex int&);
+void f(const C&);
+
+void test_scalar() {
+ int a = 10;
+
+ f(a);
+}
+
+void test_complex() {
+ _Complex int a = 10i;
+
+ f(a);
+}
+
+void test_aggregate() {
+ C c;
+
+ f(c);
+}
+
More information about the cfe-commits
mailing list