Skip to content

Commit 2026b3f

Browse files
committed
Merge r101067 from mainline.
fix PR6660/6168: emit padding as zeros instead of undef. Because trailing fields may not be represented in initializer lists, they are being handled as padding and those fields *must* be zero initialized. llvm-svn: 101134
1 parent 3810f02 commit 2026b3f

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

clang/lib/CodeGen/CGExprConstant.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class ConstStructBuilder {
230230
if (NumBytes > 1)
231231
Ty = llvm::ArrayType::get(Ty, NumBytes);
232232

233-
llvm::Constant *C = llvm::UndefValue::get(Ty);
233+
llvm::Constant *C = llvm::Constant::getNullValue(Ty);
234234
Elements.push_back(C);
235235
assert(getAlignment(C) == 1 && "Padding must have 1 byte alignment!");
236236

@@ -268,7 +268,7 @@ class ConstStructBuilder {
268268
if (NumBytes > 1)
269269
Ty = llvm::ArrayType::get(Ty, NumBytes);
270270

271-
llvm::Constant *Padding = llvm::UndefValue::get(Ty);
271+
llvm::Constant *Padding = llvm::Constant::getNullValue(Ty);
272272
PackedElements.push_back(Padding);
273273
ElementOffsetInBytes += getSizeInBytes(Padding);
274274
}
@@ -508,7 +508,7 @@ class ConstExprEmitter :
508508
if (NumPadBytes > 1)
509509
Ty = llvm::ArrayType::get(Ty, NumPadBytes);
510510

511-
Elts.push_back(llvm::UndefValue::get(Ty));
511+
Elts.push_back(llvm::Constant::getNullValue(Ty));
512512
Types.push_back(Ty);
513513
}
514514

clang/test/CodeGen/decl.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// RUN: %clang_cc1 -emit-llvm < %s | FileCheck %s
1+
// RUN: %clang_cc1 -w -emit-llvm < %s | FileCheck %s
22

33
// CHECK: @test1.x = internal constant [12 x i32] [i32 1
44
// CHECK: @test2.x = internal constant [13 x i32] [i32 1,
5-
// CHECK: @test5w = global %0 { i32 2, [4 x i8] undef }
5+
// CHECK: @test5w = global %0 { i32 2, [4 x i8] zeroinitializer }
66
// CHECK: @test5y = global %union.test5u { double 7.300000e+0{{[0]*}}1 }
77

8+
// CHECK: @test6.x = internal constant %1 { i8 1, i8 2, i32 3, [4 x i8] zeroinitializer }
89
void test1() {
910
// This should codegen as a "@test1.x" global.
1011
const int x[] = { 1, 2, 3, 4, 6, 8, 9, 10, 123, 231, 123,23 };
@@ -59,3 +60,17 @@ void test5() {
5960
union test5u test5w = (union test5u)2;
6061
union test5u test5y = (union test5u)73.0;
6162

63+
64+
65+
// PR6660 - sqlite miscompile
66+
struct SelectDest {
67+
unsigned char eDest;
68+
unsigned char affinity;
69+
int iParm;
70+
int iMem;
71+
};
72+
73+
void test6() {
74+
struct SelectDest x = {1, 2, 3};
75+
test6f(&x);
76+
}

clang/test/CodeGen/union-init2.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | grep "bitcast (%0\* @r to %union.x\*), \[4 x i8\] undef"
1+
// RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s
22

33
// Make sure we generate something sane instead of a ptrtoint
44
union x {long long b;union x* a;} r = {.a = &r};
5+
6+
7+
// CHECK: bitcast (%0* @r to %union.x*), [4 x i8] zero

0 commit comments

Comments
 (0)