[cfe-commits] r150931 - in /cfe/trunk: lib/CodeGen/CGClass.cpp lib/CodeGen/CGDecl.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprCXX.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sun Feb 19 08:03:10 PST 2012


Author: cornedbee
Date: Sun Feb 19 10:03:09 2012
New Revision: 150931

URL: http://llvm.org/viewvc/llvm-project?rev=150931&view=rev
Log:
Make heap-allocation of std::initializer_list 'work'.

Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGExprCXX.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sun Feb 19 10:03:09 2012
@@ -456,7 +456,7 @@
 
     // Now, outside of the initializer cleanup scope, destroy the backing array
     // for a std::initializer_list member.
-    CGF.MaybeEmitStdInitializerListCleanup(LV, Init);
+    CGF.MaybeEmitStdInitializerListCleanup(LV.getAddress(), Init);
 
     return;
   }

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sun Feb 19 10:03:09 2012
@@ -1093,7 +1093,7 @@
                                               AggValueSlot::IsDestructed,
                                          AggValueSlot::DoesNotNeedGCBarriers,
                                               AggValueSlot::IsNotAliased));
-    MaybeEmitStdInitializerListCleanup(lvalue, init);
+    MaybeEmitStdInitializerListCleanup(lvalue.getAddress(), init);
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Sun Feb 19 10:03:09 2012
@@ -1263,19 +1263,17 @@
                        Alignment, isVolatile);
 }
 
-void CodeGenFunction::MaybeEmitStdInitializerListCleanup(LValue lvalue,
-                                                    const Expr *init) {
+void CodeGenFunction::MaybeEmitStdInitializerListCleanup(llvm::Value *loc,
+                                                         const Expr *init) {
   const ExprWithCleanups *cleanups = dyn_cast<ExprWithCleanups>(init);
-  if (!cleanups)
-    return; // Nothing interesting here.
-  init = cleanups->getSubExpr();
+  if (cleanups)
+    init = cleanups->getSubExpr();
 
   if (isa<InitListExpr>(init) &&
       cast<InitListExpr>(init)->initializesStdInitializerList()) {
     // We initialized this std::initializer_list with an initializer list.
     // A backing array was created. Push a cleanup for it.
-    EmitStdInitializerListCleanup(lvalue.getAddress(),
-                                  cast<InitListExpr>(init));
+    EmitStdInitializerListCleanup(loc, cast<InitListExpr>(init));
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Sun Feb 19 10:03:09 2012
@@ -762,6 +762,8 @@
                               AggValueSlot::DoesNotNeedGCBarriers,
                               AggValueSlot::IsNotAliased);
     CGF.EmitAggExpr(Init, Slot);
+
+    CGF.MaybeEmitStdInitializerListCleanup(NewPtr, Init);
   }
 }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sun Feb 19 10:03:09 2012
@@ -1811,7 +1811,7 @@
   llvm::Value* EmitCXXTypeidExpr(const CXXTypeidExpr *E);
   llvm::Value *EmitDynamicCast(llvm::Value *V, const CXXDynamicCastExpr *DCE);
 
-  void MaybeEmitStdInitializerListCleanup(LValue lvalue, const Expr *init);
+  void MaybeEmitStdInitializerListCleanup(llvm::Value *loc, const Expr *init);
   void EmitStdInitializerListCleanup(llvm::Value *loc,
                                      const InitListExpr *init);
 

Modified: cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp?rev=150931&r1=150930&r2=150931&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp Sun Feb 19 10:03:09 2012
@@ -195,3 +195,23 @@
   // CHECK: call void @_ZN10destroyme2D1Ev
   // CHECK: call void @_ZN10destroyme1D1Ev
 }
+
+void fn10() {
+  // CHECK: define void @_Z4fn10v
+  // CHECK: alloca [3 x i32]
+  // CHECK: call noalias i8* @_Znwm
+  // CHECK: store i32 1
+  // CHECK: store i32 2
+  // CHECK: store i32 3
+  // CHECK: store i32*
+  // CHECK: store i{{32|64}} 3
+  (void) new std::initializer_list<int> {1, 2, 3};
+}
+
+void fn11() {
+  // CHECK: define void @_Z4fn11v
+  (void) new std::initializer_list<destroyme1> {destroyme1(), destroyme1()};
+  // CHECK: call void @_ZN10destroyme1D1Ev
+  destroyme2 dm2;
+  // CHECK: call void @_ZN10destroyme2D1Ev
+}





More information about the cfe-commits mailing list