diff options
author | Anders Carlsson <andersca@mac.com> | 2009-05-20 00:36:58 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-05-20 00:36:58 +0000 |
commit | 4bbab92167713bf4f79c0b14dcc4e83d08ac4019 (patch) | |
tree | 9efb228c348cd5ad13da22b3dc2c41167de0aa1a | |
parent | 4029ca7ae9d3ffd7738fe2ed8782bebc30f36fd6 (diff) |
Bind references to lvalues correctly.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72150 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 6 | ||||
-rw-r--r-- | test/CodeGenCXX/references.cpp | 27 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index dc447983f0..bb9f20003a 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/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/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 26d7157e1c..2b2b1ff896 100644 --- a/test/CodeGenCXX/references.cpp +++ b/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); +} + |