[cfe-commits] r101535 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/decl.c test/CodeGen/designated-initializers.c test/CodeGen/global-init.c test/CodeGen/union-init2.c

Nuno Lopes nunoplopes at sapo.pt
Fri Apr 16 13:56:35 PDT 2010


Author: nlopes
Date: Fri Apr 16 15:56:35 2010
New Revision: 101535

URL: http://llvm.org/viewvc/llvm-project?rev=101535&view=rev
Log:
emit padding as undef values, take 2
merge also a few tests I had here for this feature, and FileCheck'ize one file

Modified:
    cfe/trunk/lib/CodeGen/CGExprConstant.cpp
    cfe/trunk/test/CodeGen/decl.c
    cfe/trunk/test/CodeGen/designated-initializers.c
    cfe/trunk/test/CodeGen/global-init.c
    cfe/trunk/test/CodeGen/union-init2.c

Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=101535&r1=101534&r2=101535&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Apr 16 15:56:35 2010
@@ -259,7 +259,7 @@
   if (NumBytes > 1)
     Ty = llvm::ArrayType::get(Ty, NumBytes);
 
-  llvm::Constant *C = llvm::Constant::getNullValue(Ty);
+  llvm::Constant *C = llvm::UndefValue::get(Ty);
   Elements.push_back(C);
   assert(getAlignment(C) == 1 && "Padding must have 1 byte alignment!");
 
@@ -297,7 +297,7 @@
       if (NumBytes > 1)
         Ty = llvm::ArrayType::get(Ty, NumBytes);
 
-      llvm::Constant *Padding = llvm::Constant::getNullValue(Ty);
+      llvm::Constant *Padding = llvm::UndefValue::get(Ty);
       PackedElements.push_back(Padding);
       ElementOffsetInBytes += getSizeInBytes(Padding);
     }
@@ -537,7 +537,7 @@
         if (NumPadBytes > 1)
           Ty = llvm::ArrayType::get(Ty, NumPadBytes);
 
-        Elts.push_back(llvm::Constant::getNullValue(Ty));
+        Elts.push_back(llvm::UndefValue::get(Ty));
         Types.push_back(Ty);
       }
 

Modified: cfe/trunk/test/CodeGen/decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/decl.c?rev=101535&r1=101534&r2=101535&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/decl.c (original)
+++ cfe/trunk/test/CodeGen/decl.c Fri Apr 16 15:56:35 2010
@@ -2,7 +2,7 @@
 
 // CHECK: @test1.x = internal constant [12 x i32] [i32 1
 // CHECK: @test2.x = internal constant [13 x i32] [i32 1,
-// CHECK: @test5w = global %0 { i32 2, [4 x i8] zeroinitializer }
+// CHECK: @test5w = global %0 { i32 2, [4 x i8] undef }
 // CHECK: @test5y = global %union.test5u { double 7.300000e+0{{[0]*}}1 }
 
 // CHECK: @test6.x = internal constant %struct.SelectDest { i8 1, i8 2, i32 3, i32 0 }

Modified: cfe/trunk/test/CodeGen/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/designated-initializers.c?rev=101535&r1=101534&r2=101535&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/designated-initializers.c (original)
+++ cfe/trunk/test/CodeGen/designated-initializers.c Fri Apr 16 15:56:35 2010
@@ -1,22 +1,34 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o %t
-// RUN: grep "{ i8\* null, i32 1024 }" %t
-// RUN: grep "i32 0, i32 22" %t
+// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s
 
 struct foo {
     void *a;
     int b;
 };
 
+// CHECK: @u = global %union.anon zeroinitializer
 union { int i; float f; } u = { };
 
-int main(int argc, char **argv)
-{
-  union { int i; float f; } u2 = { };
-    static struct foo foo = {
-        .b = 1024,
-    };
-}
+// CHECK: @u2 = global %0 { i32 0, [4 x i8] undef }
+union { int i; double f; } u2 = { };
 
+// CHECK: @b = global [2 x i32] [i32 0, i32 22]
 int b[2] = {
-    [1] 22
+  [1] = 22
 };
+
+int main(int argc, char **argv)
+{
+  // CHECK: internal global %struct.foo { i8* null, i32 1024 }
+  static struct foo foo = {
+    .b = 1024,
+  };
+
+  // CHECK: bitcast %union.anon* %u2
+  // CHECK: call void @llvm.memset
+   union { int i; float f; } u2 = { };
+
+  // CHECK-NOT: call void @llvm.memset
+  union { int i; float f; } u3;
+
+  // CHECK: ret i32
+}

Modified: cfe/trunk/test/CodeGen/global-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/global-init.c?rev=101535&r1=101534&r2=101535&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/global-init.c (original)
+++ cfe/trunk/test/CodeGen/global-init.c Fri Apr 16 15:56:35 2010
@@ -12,19 +12,28 @@
 // CHECK: @c = weak global i32 0
 
 
-
 // Since this is marked const, it should get weak_odr linkage, since all
 // definitions have to be the same.
 // CHECK: @d = weak_odr constant i32 0
 const int d __attribute__((weak))= 0;
 
+// PR6168 "too many undefs"
+struct ManyFields {
+  int a;
+  int b;
+  int c;
+  char d;
+  int e;
+  int f;
+};
+
+// CHECK: global %0 { i32 1, i32 2, i32 0, i8 0, i32 0, i32 0 }
+struct ManyFields FewInits = {1, 2};
 
 
 // NOTE: tentative definitions are processed at the end of the translation unit.
 
 // This shouldn't be emitted as common because it has an explicit section.
 // rdar://7119244
-int b __attribute__((section("foo")));
-
 // CHECK: @b = global i32 0, section "foo"
-
+int b __attribute__((section("foo")));

Modified: cfe/trunk/test/CodeGen/union-init2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/union-init2.c?rev=101535&r1=101534&r2=101535&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/union-init2.c (original)
+++ cfe/trunk/test/CodeGen/union-init2.c Fri Apr 16 15:56:35 2010
@@ -1,7 +1,13 @@
 // RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s
 
 // Make sure we generate something sane instead of a ptrtoint
+// CHECK: bitcast (%0* @r to %union.x*), [4 x i8] undef
 union x {long long b;union x* a;} r = {.a = &r};
 
 
-// CHECK: bitcast (%0* @r to %union.x*), [4 x i8] zero
\ No newline at end of file
+// CHECK: global %1 { [3 x i8] zeroinitializer, [5 x i8] undef }
+union z {
+  char a[3];
+  long long b;
+};
+union z y = {};





More information about the cfe-commits mailing list