xref: /llvm-project/clang/test/AST/ast-dump-APValue-struct.cpp (revision f9ead46931aef2978ddf350ba6523638175d7861)
1 // Test without serialization:
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
3 // RUN:            -ast-dump %s -ast-dump-filter Test \
4 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
5 //
6 // Test with serialization:
7 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 -emit-pch -o %t %s
8 // RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value -std=gnu++17 \
9 // RUN:           -include-pch %t -ast-dump-all -ast-dump-filter Test /dev/null \
10 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
11 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
12 
13 struct S0 {
14   int i = 0;
15   union {
16     int j = 0;
17   } u0;
18 };
19 
20 struct S1 {
21   int i = 0;
22   union {
23     struct {
24       int j = 0;
25     } s;
26   } u1;
27 };
28 
29 struct S2 {
30   int i = 0;
31   union {
32     union {
33       int j = 0;
34     } u;
35   } u2;
36 };
37 
38 struct S3 {
39   int i = 0;
40   union {
41     union {
42       struct {
43         int j = 0;
44       } j;
45     } u;
46   } u3;
47 };
48 
49 struct S4 : S0 {
50   int i = 1, j = 2, k = 3;
51   struct {
52   } s;
53   int a = 4, b = 5, c = 6;
54 };
55 
56 struct S5 : S4 {
57   int arr0[8] = {1, 2, 3, 4};
58   int arr1[8] = {1, 2, 3, 4, 0, 0, 0, 0};
59 };
60 
Test()61 void Test() {
62   constexpr S0 s0{};
63   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s0 'const S0' constexpr listinit
64   // CHECK-NEXT:  |   |-value: Struct
65   // CHECK-NEXT:  |   | `-fields: Int 0, Union .j Int 0
66 
67   constexpr S1 s1{};
68   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s1 'const S1' constexpr listinit
69   // CHECK-NEXT:  |   |-value: Struct
70   // CHECK-NEXT:  |   | |-field: Int 0
71   // CHECK-NEXT:  |   | `-field: Union .s
72   // CHECK-NEXT:  |   |   `-Struct
73   // CHECK-NEXT:  |   |     `-field: Int 0
74 
75   constexpr S2 s2{};
76   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s2 'const S2' constexpr listinit
77   // CHECK-NEXT:  |   |-value: Struct
78   // CHECK-NEXT:  |   | `-fields: Int 0, Union .u Union .j Int 0
79 
80   constexpr S3 s3{};
81   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s3 'const S3' constexpr listinit
82   // CHECK-NEXT:  |   |-value: Struct
83   // CHECK-NEXT:  |   | |-field: Int 0
84   // CHECK-NEXT:  |   | `-field: Union .u
85   // CHECK-NEXT:  |   |   `-Union .j
86   // CHECK-NEXT:  |   |     `-Struct
87   // CHECK-NEXT:  |   |       `-field: Int 0
88 
89   constexpr S4 s4{};
90   // CHECK:  | `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s4 'const S4' constexpr listinit
91   // CHECK-NEXT:  |   |-value: Struct
92   // CHECK-NEXT:  |   | |-base: Struct
93   // CHECK-NEXT:  |   | | `-fields: Int 0, Union .j Int 0
94   // CHECK-NEXT:  |   | |-fields: Int 1, Int 2, Int 3
95   // CHECK-NEXT:  |   | |-field: Struct
96   // CHECK-NEXT:  |   | `-fields: Int 4, Int 5, Int 6
97 
98   constexpr S5 s5{};
99   // CHECK:    `-VarDecl {{.*}} <col:{{.*}}, col:{{.*}}> col:{{.*}} s5 'const S5' constexpr listinit
100   // CHECK-NEXT:      |-value: Struct
101   // CHECK-NEXT:      | |-base: Struct
102   // CHECK-NEXT:      | | |-base: Struct
103   // CHECK-NEXT:      | | | `-fields: Int 0, Union .j Int 0
104   // CHECK-NEXT:      | | |-fields: Int 1, Int 2, Int 3
105   // CHECK-NEXT:      | | |-field: Struct
106   // CHECK-NEXT:      | | `-fields: Int 4, Int 5, Int 6
107   // CHECK-NEXT:      | |-field: Array size=8
108   // CHECK-NEXT:      | | |-elements: Int 1, Int 2, Int 3, Int 4
109   // CHECK-NEXT:      | | `-filler: 4 x Int 0
110   // CHECK-NEXT:      | `-field: Array size=8
111   // CHECK-NEXT:      |   |-elements: Int 1, Int 2, Int 3, Int 4
112   // CHECK-NEXT:      |   `-elements: Int 0, Int 0, Int 0, Int 0
113 }
114