1 | // clang-format off |
2 | // REQUIRES: lld, x86 |
3 | |
4 | // Make sure class layout is correct. |
5 | // RUN: %clang_cl --target=x86_64-windows-msvc -Od -Z7 -c /Fo%t.obj -- %s |
6 | // RUN: lld-link -debug:full -nodefaultlib -entry:main %t.obj -out:%t.exe -pdb:%t.pdb |
7 | // RUN: env LLDB_USE_NATIVE_PDB_READER=1 %lldb -f %t.exe -s \ |
8 | // RUN: %p/Inputs/class_layout.lldbinit 2>&1 | FileCheck %s |
9 | |
10 | // CHECK: (lldb) expr a |
11 | // CHECK-NEXT: (A) $0 = (d1 = 'a', d2 = 1, d3 = 2, d4 = 'b') |
12 | // CHECK-NEXT: (lldb) expr b.c |
13 | // CHECK-NEXT: (char) $1 = 'a' |
14 | // CHECK-NEXT: (lldb) expr b.u.c |
15 | // CHECK-NEXT: (char[2]) $2 = "b" |
16 | // CHECK-NEXT: (lldb) expr b.u.i |
17 | // CHECK-NEXT: (int) $3 = 98 |
18 | // CHECK-NEXT: (lldb) expr c |
19 | // CHECK-NEXT: (C) $4 = { |
20 | // CHECK-NEXT: c = 'a' |
21 | // CHECK-NEXT: x = 65 |
22 | // CHECK-NEXT: = { |
23 | // CHECK-NEXT: = { |
24 | // CHECK-NEXT: c1 = 'b' |
25 | // CHECK-NEXT: = { |
26 | // CHECK-NEXT: = { |
27 | // CHECK-NEXT: s3 = { |
28 | // CHECK-NEXT: x = ([0] = 66, [1] = 67, [2] = 68) |
29 | // CHECK-NEXT: } |
30 | // CHECK-NEXT: c3 = 'c' |
31 | // CHECK-NEXT: } |
32 | // CHECK-NEXT: = { |
33 | // CHECK-NEXT: c4 = 'B' |
34 | // CHECK-NEXT: s4 = { |
35 | // CHECK-NEXT: x = ([0] = 67, [1] = 68, [2] = 99) |
36 | // CHECK-NEXT: } |
37 | // CHECK-NEXT: s1 = { |
38 | // CHECK-NEXT: x = ([0] = 69, [1] = 70, [2] = 71) |
39 | // CHECK-NEXT: } |
40 | // CHECK-NEXT: } |
41 | // CHECK-NEXT: } |
42 | // CHECK-NEXT: } |
43 | // CHECK-NEXT: = { |
44 | // CHECK-NEXT: s2 = { |
45 | // CHECK-NEXT: x = ([0] = 98, [1] = 66, [2] = 67) |
46 | // CHECK-NEXT: } |
47 | // CHECK-NEXT: c2 = 'D' |
48 | // CHECK-NEXT: } |
49 | // CHECK-NEXT: } |
50 | // CHECK-NEXT: } |
51 | // CHECK-NEXT: (lldb) type lookup C |
52 | // CHECK-NEXT: struct C { |
53 | // CHECK-NEXT: char c; |
54 | // CHECK-NEXT: int x; |
55 | // CHECK-NEXT: union { |
56 | // CHECK-NEXT: struct { |
57 | // CHECK-NEXT: char c1; |
58 | // CHECK-NEXT: union { |
59 | // CHECK-NEXT: struct { |
60 | // CHECK-NEXT: S3 s3; |
61 | // CHECK-NEXT: char c3; |
62 | // CHECK-NEXT: }; |
63 | // CHECK-NEXT: struct { |
64 | // CHECK-NEXT: char c4; |
65 | // CHECK-NEXT: S3 s4; |
66 | // CHECK-NEXT: S3 s1; |
67 | // CHECK-NEXT: }; |
68 | // CHECK-NEXT: }; |
69 | // CHECK-NEXT: }; |
70 | // CHECK-NEXT: struct { |
71 | // CHECK-NEXT: S3 s2; |
72 | // CHECK-NEXT: char c2; |
73 | // CHECK-NEXT: }; |
74 | // CHECK-NEXT: }; |
75 | // CHECK-NEXT: } |
76 | |
77 | |
78 | |
79 | // Test packed stuct layout. |
80 | struct __attribute__((packed, aligned(1))) A { |
81 | char d1; |
82 | int d2; |
83 | int d3; |
84 | char d4; |
85 | }; |
86 | |
87 | struct __attribute__((packed, aligned(1))) B { |
88 | char c; |
89 | union { |
90 | char c[2]; |
91 | int i; |
92 | } u; |
93 | }; |
94 | |
95 | // Test struct layout with anonymous union/struct. |
96 | struct S3 { |
97 | short x[3]; |
98 | }; |
99 | |
100 | struct C { |
101 | char c; |
102 | int x; |
103 | union { |
104 | struct { |
105 | char c1; |
106 | union { |
107 | struct { |
108 | S3 s3; |
109 | char c3; |
110 | }; |
111 | struct { |
112 | char c4; |
113 | S3 s4; |
114 | }; |
115 | }; |
116 | S3 s1; |
117 | }; |
118 | struct { |
119 | S3 s2; |
120 | char c2; |
121 | }; |
122 | }; |
123 | }; |
124 | |
125 | A a = {.d1: 'a', .d2: 1, .d3: 2, .d4: 'b'}; |
126 | B b = {.c: 'a', .u: {.c: "b" }}; |
127 | C c = {.c = 'a', .x = 65, .c1 = 'b', .s3 = {66, 67, 68}, .c3 = 'c', .s1={69, 70, 71}}; |
128 | |
129 | int main() { |
130 | return 0; |
131 | } |
132 | |