Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -std=c++1y %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
      2 
      3 struct 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 
     15 int f();
     16 
     17 union B {
     18   int a;
     19   int f();
     20   int b = f();
     21 };
     22 
     23 A a { .p = "foobar" };
     24 A b { 4, "bazquux", .x = 42, .c = 9 };
     25 A c { 1, 0, 'A', f(), { 3 } };
     26 
     27 // CHECK: @[[STR_A:.*]] = {{.*}} [7 x i8] c"foobar\00"
     28 // CHECK: @a = global {{.*}} zeroinitializer
     29 
     30 // @b has a constant initializer
     31 // CHECK: @[[STR_B:.*]] = {{.*}} [8 x i8] c"bazquux\00"
     32 // CHECK: @b = global {{.*}} i32 4, {{.*}} @[[STR_B]], {{.*}} i8 117, i32 42, {{.*}} i8 9
     33 
     34 B x;
     35 B y {};
     36 B z { 1 };
     37 // CHECK: @z = global {{.*}} { i32 1 }
     38 
     39 // Initialization of 'a':
     40 
     41 // CHECK: store i32 0, i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
     42 // CHECK: store i8* {{.*}} @[[STR_A]]{{.*}}, i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
     43 // CHECK: load i32* getelementptr inbounds ({{.*}} @a, i32 0, i32 0)
     44 // CHECK: load i8** getelementptr inbounds ({{.*}} @a, i32 0, i32 1)
     45 // CHECK: getelementptr inbounds i8* %{{.*}}, {{.*}} %{{.*}}
     46 // CHECK: store i8 %{{.*}}, i8* getelementptr inbounds ({{.*}} @a, i32 0, i32 2)
     47 // CHECK: call i32 @_ZN1A1fEv({{.*}} @a)
     48 // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}* @a, i32 0, i32 3)
     49 // CHECK: store double 1.000000e+00, double* getelementptr inbounds ({{.*}} @a, i32 0, i32 4, i32 0)
     50 
     51 // No dynamic initialization of 'b':
     52 
     53 // CHECK-NOT: @b
     54 
     55 // Initialization of 'c':
     56 
     57 // CHECK: store i32 1, i32* getelementptr inbounds ({{.*}} @c, i32 0, i32 0)
     58 // CHECK: store i8* null, i8** getelementptr inbounds ({{.*}} @c, i32 0, i32 1)
     59 // CHECK-NOT: load
     60 // CHECK: store i8 65, i8* getelementptr inbounds ({{.*}} @c, i32 0, i32 2)
     61 // CHECK: call i32 @_Z1fv()
     62 // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}}* @c, i32 0, i32 3)
     63 // CHECK-NOT: C1Ev
     64 // CHECK: store i8 3, i8* {{.*}} @c, i32 0, i32 4)
     65 
     66 // CHECK: call void @_ZN1BC1Ev({{.*}} @x)
     67 
     68 // CHECK: call i32 @_ZN1B1fEv({{.*}} @y)
     69 // CHECK: store i32 %{{.*}}, i32* getelementptr inbounds ({{.*}} @y, i32 0, i32 0)
     70