81 lines · cpp
1// RUN: %clang_cc1 -std=c++1y %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s2 3struct A {4 int n = 0;5 const char *p;6 char k = p[n];7 int f();8 int x = f();9 union {10 char c;11 double d = 1.0;12 };13};14 15int f();16 17union B {18 int a;19 int f();20 int b = f();21};22 23A a { .p = "foobar" };24A b { 4, "bazquux", .x = 42, .c = 9 };25A c { 1, 0, 'A', f(), { 3 } };26 27// CHECK: @[[STR_A:.*]] = {{.*}} [7 x i8] c"foobar\00"28// CHECK: @a ={{.*}} global {{.*}} zeroinitializer29 30// @b has a constant initializer31// CHECK: @[[STR_B:.*]] = {{.*}} [8 x i8] c"bazquux\00"32// CHECK: @b ={{.*}} global {{.*}} i32 4, {{.*}} @[[STR_B]], i8 117, i32 42, {{.*}} i8 933 34B x;35B y {};36B z { 1 };37// CHECK: @z ={{.*}} global {{.*}} { i32 1 }38 39// Brace initialization should initialize the first field even though it is40// unnamed.41union C {42 struct {43 int C::*memptr;44 };45};46 47C n{};48// CHECK: @n ={{.*}} global %union.C { %struct.anon { i64 -1 } }, align 849 50// Initialization of 'a':51 52// CHECK: store i32 0, ptr @a53// CHECK: store ptr @[[STR_A]], ptr getelementptr inbounds nuw ({{.*}} @a, i32 0, i32 1)54// CHECK: load ptr, ptr getelementptr inbounds nuw ({{.*}} @a, i32 0, i32 1)55// CHECK: load i32, ptr @a56// CHECK: getelementptr inbounds i8, ptr %{{.*}}, {{.*}} %{{.*}}57// CHECK: store i8 %{{.*}}, ptr getelementptr inbounds nuw ({{.*}} @a, i32 0, i32 2)58// CHECK: call noundef i32 @_ZN1A1fEv({{.*}} @a)59// CHECK: store i32 %{{.*}}, ptr getelementptr inbounds nuw ({{.*}}, ptr @a, i32 0, i32 3)60// CHECK: store double 1.000000e+00, ptr getelementptr inbounds nuw ({{.*}} @a, i32 0, i32 4)61 62// No dynamic initialization of 'b':63 64// CHECK-NOT: @b65 66// Initialization of 'c':67 68// CHECK: store i32 1, ptr @c69// CHECK: store ptr null, ptr getelementptr inbounds nuw ({{.*}} @c, i32 0, i32 1)70// CHECK-NOT: load71// CHECK: store i8 65, ptr getelementptr inbounds nuw ({{.*}} @c, i32 0, i32 2)72// CHECK: call noundef i32 @_Z1fv()73// CHECK: store i32 %{{.*}}, ptr getelementptr inbounds nuw ({{.*}}, ptr @c, i32 0, i32 3)74// CHECK-NOT: C1Ev75// CHECK: store i8 3, ptr {{.*}} @c, i32 0, i32 4)76 77// CHECK: call void @_ZN1BC1Ev({{.*}} @x)78 79// CHECK: call noundef i32 @_ZN1B1fEv({{.*}} @y)80// CHECK: store i32 %{{.*}}, ptr @y81