[cfe-commits] use undef for padding

Nuno Lopes nuno.lopes at ist.utl.pt
Tue Oct 27 03:15:16 PDT 2009


Hi,

I made a patch to make clang emit padding as undefs instead of nulls.  
This is a first step to expose more information to llvm's optimizers  
(including one that's in the workings). Probably there are other  
places where undefs could be emitted instead as well.
I'm submitting the patch first for review because I'm not exactly sure  
of the C semantics regarding the initialization of e.g. global unions  
(i.e., is it safe to make it undef?)

Thanks,
Nuno
-------------- next part --------------
Index: test/CodeGen/cast-to-union.c
===================================================================
--- test/CodeGen/cast-to-union.c	(revision 85219)
+++ test/CodeGen/cast-to-union.c	(working copy)
@@ -1,5 +1,5 @@
 // RUN: clang-cc -emit-llvm  %s -o - | FileCheck %s
-// CHECK: w = global %0 { i32 2, [4 x i8] zeroinitializer }
+// CHECK: w = global %0 { i32 2, [4 x i8] undef }
 // CHECK: y = global %union.u { double 7.300000e+0{{[0]*}}1 }
 // CHECK: store i32 351, i32
 
Index: test/CodeGen/union-init2.c
===================================================================
--- test/CodeGen/union-init2.c	(revision 85219)
+++ test/CodeGen/union-init2.c	(working copy)
@@ -1,4 +1,4 @@
-// RUN: clang-cc -emit-llvm %s -o - -triple i686-pc-linux-gnu | grep "bitcast (%0\* @r to %union.x\*), \[4 x i8\] zeroinitializer"
+// RUN: clang-cc -emit-llvm %s -o - -triple i686-pc-linux-gnu | grep "bitcast (%0\* @r to %union.x\*), \[4 x i8\] undef"
 
 // Make sure we generate something sane instead of a ptrtoint
 union x {long long b;union x* a;} r = {.a = &r};
Index: lib/CodeGen/CGExprConstant.cpp
===================================================================
--- lib/CodeGen/CGExprConstant.cpp	(revision 85219)
+++ lib/CodeGen/CGExprConstant.cpp	(working copy)
@@ -228,7 +228,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!");
 
@@ -266,7 +266,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);
       }
@@ -496,7 +496,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);
       }
 


More information about the cfe-commits mailing list