[PATCH] CodeGen: Emit constant array temporaries into read-only globals.

Richard Smith richard at metafoo.co.uk
Tue Mar 3 15:26:20 PST 2015


I'm fine with this once you guys are in agreement on the linkage/comdat stuff.


================
Comment at: test/CodeGenCXX/cxx0x-initializer-array.cpp:47
@@ -46,3 +46,3 @@
   void g() {
-    // CHECK: store i32 -1,
     f(a{});
----------------
I'm not sure this test is still testing what it's supposed to test (that we emit dynamic zero initialization properly for array temporaries). Something like:

  void g(p ptr) {
    f(a{ptr});
  }

with the existing check for a `store i32 -1,` might work.

================
Comment at: test/CodeGenCXX/cxx0x-initializer-references.cpp:39-54
@@ -38,18 +38,8 @@
   void reference_to_aggregate() {
-    // CHECK: getelementptr {{.*}}, i32 0, i32 0
-    // CHECK-NEXT: store i32 1
-    // CHECK-NEXT: getelementptr {{.*}}, i32 0, i32 1
-    // CHECK-NEXT: store i32 2
-    // CHECK-NEXT: store %{{.*}}* %{{.*}}, %{{.*}}** %{{.*}}, align
+    // CHECK: store %"struct.reference::A"* @.reftmp, %"struct.reference::A"** %{{.*}}, align
     const A &ra1{1, 2};
 
-    // CHECK-NEXT: getelementptr inbounds [3 x i32], [3 x i32]* %{{.*}}, i{{32|64}} 0, i{{32|64}} 0
-    // CHECK-NEXT: store i32 1
-    // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
-    // CHECK-NEXT: store i32 2
-    // CHECK-NEXT: getelementptr inbounds i32, i32* %{{.*}}, i{{32|64}} 1
-    // CHECK-NEXT: store i32 3
-    // CHECK-NEXT: store [3 x i32]* %{{.*}}, [3 x i32]** %{{.*}}, align
+    // CHECK-NEXT: store [3 x i32]* @.reftmp1, [3 x i32]** %{{.*}}, align
     const int (&arrayRef)[] = {1, 2, 3};
 
     // CHECK-NEXT: ret
----------------
Likewise here, changing one of the constants to a reference to a function parameter would better preserve the intention of the test.

================
Comment at: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp:67-68
@@ -66,1 +66,4 @@
 
+// CHECK: @.reftmp = private constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+// CHECK: @.reftmp2 = private constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+
----------------
Can you avoid testing the names of these globals?

================
Comment at: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp:79
@@ +78,3 @@
+// CHECK: @.reftmp8 = private constant [2 x i32] [i32 42, i32 43], comdat($_ZN7PR204451fILi0EEEvv), align 4
+// CHECK: @.reftmp9 = private constant [3 x %"class.ConstExpr::C"] [%"class.ConstExpr::C" { i32 1 }, %"class.ConstExpr::C" { i32 2 }, %"class.ConstExpr::C" { i32 3 }], align 4
+
----------------
Please don't check for the name of this type; that makes the test more fragile than necessary.

================
Comment at: test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp:223-254
@@ -222,34 +228,28 @@
 haslist1::haslist1()
-// CHECK: alloca [3 x i32]
-// CHECK: store i32 1
-// CHECK: store i32 2
-// CHECK: store i32 3
+// CHECK-NOT: alloca [3 x i32]
+// CHECK: store i32* getelementptr inbounds ([3 x i32]* @.reftmp, i64 0, i64 0)
 // CHECK: store i{{32|64}} 3
   : il{1, 2, 3}
 {
   destroyme2 dm2;
 }
 
 struct haslist2 {
   std::initializer_list<destroyme1> il;
   haslist2();
 };
 
 // CHECK-LABEL: define void @_ZN8haslist2C2Ev
 haslist2::haslist2()
   : il{destroyme1(), destroyme1()}
 {
   destroyme2 dm2;
   // CHECK: call void @_ZN10destroyme2D1Ev
   // CHECK: call void @_ZN10destroyme1D1Ev
 }
 
 void fn10() {
   // CHECK-LABEL: define void @_Z4fn10v
-  // CHECK: alloca [3 x i32]
   // CHECK: call noalias i8* @_Znw{{[jm]}}
-  // CHECK: store i32 1
-  // CHECK: store i32 2
-  // CHECK: store i32 3
-  // CHECK: store i32*
   // CHECK: store i{{32|64}} 3
----------------
Please make both of these cases use a non-constant initializer; part of the point of these tests seems to be to check that we get the lifetime right.

http://reviews.llvm.org/D8034

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list