Bind references to lvalues correctly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72150 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index dc44798..bb9f200 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -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);
}
diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp
index 26d7157..2b2b1ff 100644
--- a/test/CodeGenCXX/references.cpp
+++ b/test/CodeGenCXX/references.cpp
@@ -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);
+}
+