mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 23:31:50 +08:00
make clang emit undefs for padding of structs and unions instead of zeros. this enables constant compaction optimizations.
llvm-svn: 85504
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user