xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/member-init-anon-union.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -std=c++11 -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // PR10531.
4f4a2713aSLionel Sambuc 
5f4a2713aSLionel Sambuc int make_a();
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc static union {
8f4a2713aSLionel Sambuc   int a = make_a();
9f4a2713aSLionel Sambuc   char *b;
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc 
f()12f4a2713aSLionel Sambuc int f() { return a; }
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc // CHECK-LABEL: define internal void @__cxx_global_var_init
15f4a2713aSLionel Sambuc // CHECK-NOT: }
16f4a2713aSLionel Sambuc // CHECK: call {{.*}}@"[[CONSTRUCT_GLOBAL:.*]]C1Ev"
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc 
g()19f4a2713aSLionel Sambuc int g() {
20f4a2713aSLionel Sambuc   union {
21f4a2713aSLionel Sambuc     int a;
22f4a2713aSLionel Sambuc     int b = 81;
23f4a2713aSLionel Sambuc   };
24*0a6a1f1dSLionel Sambuc   // CHECK-LABEL: define {{.*}}_Z1gv
25f4a2713aSLionel Sambuc   // CHECK-NOT: }
26f4a2713aSLionel Sambuc   // CHECK: call {{.*}}@"[[CONSTRUCT_LOCAL:.*]]C1Ev"
27f4a2713aSLionel Sambuc   return b;
28f4a2713aSLionel Sambuc }
29f4a2713aSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc struct A {
31*0a6a1f1dSLionel Sambuc   A();
32*0a6a1f1dSLionel Sambuc };
33*0a6a1f1dSLionel Sambuc union B {
34*0a6a1f1dSLionel Sambuc   int k;
35*0a6a1f1dSLionel Sambuc   struct {
36*0a6a1f1dSLionel Sambuc     A x;
37*0a6a1f1dSLionel Sambuc     int y = 123;
38*0a6a1f1dSLionel Sambuc   };
B()39*0a6a1f1dSLionel Sambuc   B() {}
B(int n)40*0a6a1f1dSLionel Sambuc   B(int n) : k(n) {}
41*0a6a1f1dSLionel Sambuc };
42*0a6a1f1dSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc B b1;
44*0a6a1f1dSLionel Sambuc B b2(0);
45*0a6a1f1dSLionel Sambuc 
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN1BC2Ei(
48*0a6a1f1dSLionel Sambuc // CHECK-NOT: call void @_ZN1AC1Ev(
49*0a6a1f1dSLionel Sambuc // CHECK-NOT: store i32 123,
50*0a6a1f1dSLionel Sambuc // CHECK: store i32 %
51*0a6a1f1dSLionel Sambuc // CHECK-NOT: call void @_ZN1AC1Ev(
52*0a6a1f1dSLionel Sambuc // CHECK-NOT: store i32 123,
53*0a6a1f1dSLionel Sambuc // CHECK: }
54*0a6a1f1dSLionel Sambuc 
55*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*}} @_ZN1BC2Ev(
56*0a6a1f1dSLionel Sambuc // CHECK: call void @_ZN1AC1Ev(
57*0a6a1f1dSLionel Sambuc // CHECK: store i32 123,
58*0a6a1f1dSLionel Sambuc // CHECK: }
59*0a6a1f1dSLionel Sambuc 
60f4a2713aSLionel Sambuc 
61f4a2713aSLionel Sambuc // CHECK: define {{.*}}@"[[CONSTRUCT_LOCAL]]C2Ev"
62f4a2713aSLionel Sambuc // CHECK-NOT: }
63f4a2713aSLionel Sambuc // CHECK: store i32 81
64f4a2713aSLionel Sambuc 
65f4a2713aSLionel Sambuc // CHECK: define {{.*}}@"[[CONSTRUCT_GLOBAL]]C2Ev"
66f4a2713aSLionel Sambuc // CHECK-NOT: }
67f4a2713aSLionel Sambuc // CHECK: call {{.*}}@_Z6make_a
68