From e04d1c77ae15a6e973e2fac7723f6c364884f58d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 20 May 2009 01:03:17 +0000 Subject: [PATCH] Add support for binding references to scalar rvalues. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72153 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 8 ++++++++ test/CodeGenCXX/references.cpp | 13 ++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index bb9f20003a..299bb6b4a4 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -78,6 +78,14 @@ RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E, return RValue::get(LV.getAddress()); } + if (!hasAggregateLLVMType(E->getType())) { + // Make a temporary variable that we can bind the reference to. + llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(E->getType()), + "reftmp"); + EmitStoreOfScalar(EmitScalarExpr(E), Temp, false, E->getType()); + return RValue::get(Temp); + } + CGM.ErrorUnsupported(E, "reference binding"); return GetUndefRValue(DestType); } diff --git a/test/CodeGenCXX/references.cpp b/test/CodeGenCXX/references.cpp index 2b2b1ff896..a1a6c0ae71 100644 --- a/test/CodeGenCXX/references.cpp +++ b/test/CodeGenCXX/references.cpp @@ -19,25 +19,32 @@ void t3() { struct C {}; +void f(const bool&); void f(const int&); void f(const _Complex int&); void f(const C&); +void test_bool() { + bool a = true; + f(a); + + f(true); +} + void test_scalar() { int a = 10; - f(a); + + f(10); } void test_complex() { _Complex int a = 10i; - f(a); } void test_aggregate() { C c; - f(c); }