summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-05-20 00:36:58 +0000
committerAnders Carlsson <andersca@mac.com>2009-05-20 00:36:58 +0000
commit7d4c083c1909ba1da94754abfab157efcbe7e898 (patch)
tree12e227ef70bb5fdd86df6ab61e68d2782a914fe9
parent7248923a5da4244e426b74205402df78b607ea54 (diff)
downloadbcm5719-llvm-7d4c083c1909ba1da94754abfab157efcbe7e898.tar.gz
bcm5719-llvm-7d4c083c1909ba1da94754abfab157efcbe7e898.zip
Bind references to lvalues correctly.
llvm-svn: 72150
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp6
-rw-r--r--clang/test/CodeGenCXX/references.cpp27
2 files changed, 33 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index dc447983f0e..bb9f20003ac 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -72,6 +72,12 @@ RValue CodeGenFunction::EmitAnyExprToTemp(const Expr *E, llvm::Value *AggLoc,
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/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp
index 26d7157e1cb..2b2b1ff8969 100644
--- a/clang/test/CodeGenCXX/references.cpp
+++ b/clang/test/CodeGenCXX/references.cpp
@@ -14,3 +14,30 @@ int& gr = g;
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);
+}
+
OpenPOWER on IntegriCloud