| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s |
| 3 |
|
| 4 |
// C guarantees that brace-init with fewer initializers than members in the |
| 5 |
// aggregate will initialize the rest of the aggregate as-if it were static |
| 6 |
// initialization. In turn static initialization guarantees that padding is |
| 7 |
// initialized to zero bits. |
| 8 |
|
| 9 |
// CHECK: @__const.partial_init.s = private unnamed_addr constant { i8, [7 x i8], i64 } { i8 42, [7 x i8] zeroinitializer, i64 0 }, align 8 |
| 10 |
|
| 11 |
// Technically, we could initialize this padding to non-zero because all of the |
| 12 |
// struct's members have initializers. |
| 13 |
|
| 14 |
// CHECK: @__const.init_all.s = private unnamed_addr constant { i8, [7 x i8], i64 } { i8 42, [7 x i8] zeroinitializer, i64 -2401053089374216531 }, align 8 |
| 15 |
|
| 16 |
struct S { |
| 17 |
char c; |
| 18 |
long long l; |
| 19 |
}; |
| 20 |
|
| 21 |
void use(struct S*); |
| 22 |
|
| 23 |
// CHECK-LABEL: @empty_braces( |
| 24 |
// CHECK: %s = alloca |
| 25 |
// CHECK-NEXT: call void @llvm.memset{{.*}}(ptr align 8 %s, i8 0, |
| 26 |
// CHECK-NEXT: call void @use(ptr noundef %s) |
| 27 |
void empty_braces(void) { |
| 28 |
struct S s = {}; |
| 29 |
return use(&s); |
| 30 |
} |
| 31 |
|
| 32 |
// CHECK-LABEL: @partial_init( |
| 33 |
// CHECK: %s = alloca |
| 34 |
// CHECK-NEXT: call void @llvm.memcpy{{.*}}(ptr align 8 %s, {{.*}}@__const.partial_init.s |
| 35 |
// CHECK-NEXT: call void @use(ptr noundef %s) |
| 36 |
void partial_init(void) { |
| 37 |
struct S s = { .c = 42 }; |
| 38 |
return use(&s); |
| 39 |
} |
| 40 |
|
| 41 |
// CHECK-LABEL: @init_all( |
| 42 |
// CHECK: %s = alloca |
| 43 |
// CHECK-NEXT: call void @llvm.memcpy{{.*}}(ptr align 8 %s, {{.*}}@__const.init_all.s |
| 44 |
// CHECK-NEXT: call void @use(ptr noundef %s) |
| 45 |
void init_all(void) { |
| 46 |
struct S s = { .c = 42, .l = 0xdeadbeefc0fedead }; |
| 47 |
return use(&s); |
| 48 |
} |