diff options
| author | Anders Carlsson <andersca@mac.com> | 2009-05-20 01:03:17 +0000 |
|---|---|---|
| committer | Anders Carlsson <andersca@mac.com> | 2009-05-20 01:03:17 +0000 |
| commit | 145eae52248031baddc00b680ce957cbb5961e2d (patch) | |
| tree | 7595a655f7f14ed7200b6457d077811135f22999 /clang | |
| parent | 9cbf8505062a290ce0352867aa0a0795c5a02da6 (diff) | |
| download | bcm5719-llvm-145eae52248031baddc00b680ce957cbb5961e2d.tar.gz bcm5719-llvm-145eae52248031baddc00b680ce957cbb5961e2d.zip | |
Add support for binding references to scalar rvalues.
llvm-svn: 72153
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 8 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/references.cpp | 13 |
2 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index bb9f20003ac..299bb6b4a4a 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/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/clang/test/CodeGenCXX/references.cpp b/clang/test/CodeGenCXX/references.cpp index 2b2b1ff8969..a1a6c0ae71a 100644 --- a/clang/test/CodeGenCXX/references.cpp +++ b/clang/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); } |

