diff options
author | Jordan Rupprecht <rupprecht@google.com> | 2019-05-14 21:58:59 +0000 |
---|---|---|
committer | Jordan Rupprecht <rupprecht@google.com> | 2019-05-14 21:58:59 +0000 |
commit | b35a2aa71f76a334a9c98c0a3c3995b5d902d2b9 (patch) | |
tree | cdff4a5d1a715d4ad622fd8f190128b54bebe440 /test/CodeGen/padding-init.c | |
parent | 3748d41833787fcbf59cc5624e8d2b042a8991bc (diff) | |
parent | 741e05796da92b46d4f7bcbee00702ff37df6489 (diff) |
Creating branches/google/stable and tags/google/stable/2019-05-14 from r360103upstream/google/stable
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/google/stable@360714 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGen/padding-init.c')
-rw-r--r-- | test/CodeGen/padding-init.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/test/CodeGen/padding-init.c b/test/CodeGen/padding-init.c new file mode 100644 index 0000000000..0ff11efd64 --- /dev/null +++ b/test/CodeGen/padding-init.c @@ -0,0 +1,51 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=pattern %s -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ftrivial-auto-var-init=zero %s -emit-llvm -o - | FileCheck %s + +// C guarantees that brace-init with fewer initializers than members in the +// aggregate will initialize the rest of the aggregate as-if it were static +// initialization. In turn static initialization guarantees that padding is +// initialized to zero bits. + +// CHECK: @__const.partial_init.s = private unnamed_addr constant { i8, [7 x i8], i64 } { i8 42, [7 x i8] zeroinitializer, i64 0 }, align 8 + +// Technically, we could initialize this padding to non-zero because all of the +// struct's members have initializers. + +// CHECK: @__const.init_all.s = private unnamed_addr constant { i8, [7 x i8], i64 } { i8 42, [7 x i8] zeroinitializer, i64 -2401053089374216531 }, align 8 + +struct S { + char c; + long long l; +}; + +void use(struct S*); + +// CHECK-LABEL: @empty_braces( +// CHECK: %s = alloca +// CHECK-NEXT: %[[B:[0-9+]]] = bitcast %struct.S* %s to i8* +// CHECK-NEXT: call void @llvm.memset{{.*}}(i8* align 8 %[[B]], i8 0, +// CHECK-NEXT: call void @use(%struct.S* %s) +void empty_braces() { + struct S s = {}; + return use(&s); +} + +// CHECK-LABEL: @partial_init( +// CHECK: %s = alloca +// CHECK-NEXT: %[[B:[0-9+]]] = bitcast %struct.S* %s to i8* +// CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* align 8 %[[B]], {{.*}}@__const.partial_init.s +// CHECK-NEXT: call void @use(%struct.S* %s) +void partial_init() { + struct S s = { .c = 42 }; + return use(&s); +} + +// CHECK-LABEL: @init_all( +// CHECK: %s = alloca +// CHECK-NEXT: %[[B:[0-9+]]] = bitcast %struct.S* %s to i8* +// CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* align 8 %[[B]], {{.*}}@__const.init_all.s +// CHECK-NEXT: call void @use(%struct.S* %s) +void init_all() { + struct S s = { .c = 42, .l = 0xdeadbeefc0fedead }; + return use(&s); +} |