[cfe-commits] r72159 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGenCXX/references.cpp

Eli Friedman eli.friedman at gmail.com
Tue May 19 19:31:20 PDT 2009


Author: efriedma
Date: Tue May 19 21:31:19 2009
New Revision: 72159

URL: http://llvm.org/viewvc/llvm-project?rev=72159&view=rev
Log:
Handle the remaining unhandled cases in EmitReferenceBindingToExpr.

It would be nice if someone could write an ObjC++ testcase for the case 
of passing a property returning a struct to a function taking a const
reference.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/references.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=72159&r1=72158&r2=72159&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue May 19 21:31:19 2009
@@ -72,28 +72,31 @@
 
 RValue CodeGenFunction::EmitReferenceBindingToExpr(const Expr* E,
                                                    QualType DestType) {
-  if (E->isLvalue(getContext()) == Expr::LV_Valid && !E->getBitField()) {
+  RValue Val;
+  if (E->isLvalue(getContext()) == Expr::LV_Valid) {
     // Emit the expr as an lvalue.
     LValue LV = EmitLValue(E);
-    return RValue::get(LV.getAddress());
+    if (LV.isSimple())
+      return RValue::get(LV.getAddress());
+    Val = EmitLoadOfLValue(LV, E->getType());
+  } else {
+    Val = EmitAnyExprToTemp(E);
   }
-  
-  if (!hasAggregateLLVMType(E->getType())) {
-    // Create 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);
-  } else if (E->getType()->isAnyComplexType()) {
+
+  if (Val.isAggregate()) {
+    Val = RValue::get(Val.getAggregateAddr());
+  } else {
     // Create a temporary variable that we can bind the reference to.
     llvm::Value *Temp = CreateTempAlloca(ConvertTypeForMem(E->getType()), 
                                          "reftmp");
-    EmitComplexExprIntoAddr(E, Temp, false);
-    return RValue::get(Temp);
+    if (Val.isScalar())
+      EmitStoreOfScalar(Val.getScalarVal(), Temp, false, E->getType());
+    else
+      StoreComplexToAddr(Val.getComplexVal(), Temp, false);
+    Val = RValue::get(Temp);
   }
-  
-  CGM.ErrorUnsupported(E, "reference binding");
-  return GetUndefRValue(DestType);
+
+  return Val;
 }
 
 

Modified: cfe/trunk/test/CodeGenCXX/references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/references.cpp?rev=72159&r1=72158&r2=72159&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/references.cpp Tue May 19 21:31:19 2009
@@ -24,6 +24,8 @@
 void f(const _Complex int&);
 void f(const C&);
 
+C structfunc();
+
 void test_bool() {
   bool a = true;
   f(a);
@@ -39,6 +41,9 @@
   f(s.bitfield);
   
   f(10);
+
+  __attribute((vector_size(16))) typedef int vec4;
+  f((vec4){1,2,3,4}[0]);
 }
 
 void test_complex() {
@@ -51,5 +56,7 @@
 void test_aggregate() {
   C c;
   f(c);
+
+  f(structfunc());
 }
 





More information about the cfe-commits mailing list