From 7d4c083c1909ba1da94754abfab157efcbe7e898 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 20 May 2009 00:36:58 +0000 Subject: [PATCH] Bind references to lvalues correctly. llvm-svn: 72150 --- clang/lib/CodeGen/CGExpr.cpp | 6 ++++++ clang/test/CodeGenCXX/references.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index dc447983f0e4..bb9f20003ac1 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 26d7157e1cb1..2b2b1ff8969e 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); +} +