]> granicus.if.org Git - clang/commitdiff
Add support for binding references to scalar rvalues.
authorAnders Carlsson <andersca@mac.com>
Wed, 20 May 2009 01:03:17 +0000 (01:03 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 20 May 2009 01:03:17 +0000 (01:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72153 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/references.cpp

index bb9f20003ac18b55109090eea0ec27f6d3446905..299bb6b4a4aea0fe4424e08c704997cdc265d19c 100644 (file)
@@ -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);
 }
index 2b2b1ff8969e4c15fcab85d2ff0f9c1a2a05a032..a1a6c0ae71a014b026586f6a449586096f33cde7 100644 (file)
@@ -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);
 }