aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2009-10-29 11:27:06 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2009-10-29 11:27:06 +0000
commitc6eb131a83eb35d0c896170652563449648a32c3 (patch)
treef523865ee816ab38fd4f23fd78b0751ba05680bc
parent4fff4b3fdf49272a26b7cb7bd564a521e938805b (diff)
make clang emit undefs for padding of structs and unions instead of zeros. this enables constant compaction optimizations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85504 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/CGExprConstant.cpp6
-rw-r--r--test/CodeGen/cast-to-union.c2
-rw-r--r--test/CodeGen/union-init2.c2
3 files changed, 5 insertions, 5 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index dc0aa9e7c4..9145d92128 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -228,7 +228,7 @@ class VISIBILITY_HIDDEN ConstStructBuilder {
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 @@ class VISIBILITY_HIDDEN ConstStructBuilder {
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 @@ public:
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);
}
diff --git a/test/CodeGen/cast-to-union.c b/test/CodeGen/cast-to-union.c
index 6742992949..1f7e045770 100644
--- a/test/CodeGen/cast-to-union.c
+++ b/test/CodeGen/cast-to-union.c
@@ -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
diff --git a/test/CodeGen/union-init2.c b/test/CodeGen/union-init2.c
index 184d75f471..e782425cf2 100644
--- a/test/CodeGen/union-init2.c
+++ b/test/CodeGen/union-init2.c
@@ -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};