xref: /llvm-project/llvm/test/tools/dsymutil/X86/odr-uniquing.cpp (revision f1fdfe6888f93b9f6dfb4689e1f3206de584ff5b)
1 /* Compile with:
2    clang -g -c  odr-uniquing.cpp -o odr-uniquing/1.o
3    cp odr-uniquing/1.o odr-uniquing/2.o
4    The aim of these test is to check that all the 'type types' that
5    should be uniqued through the ODR really are.
6 
7    The resulting object file is linked against itself using a fake
8    debug map. The end result is:
9     - with ODR uniquing: all types (expect for the union for now) in
10    the second CU should point back to the types of the first CU.
11     - without ODR uniquing: all types are re-emited in the second CU
12  */
13 
14 // RUN: dsymutil -f -oso-prepend-path=%p/../Inputs/odr-uniquing -y %p/dummy-debug-map.map -o - | llvm-dwarfdump -v -debug-info - | FileCheck -check-prefixes=ODR,CHECK %s
15 // RUN: dsymutil -f -oso-prepend-path=%p/../Inputs/odr-uniquing -y %p/dummy-debug-map.map -no-odr -o - | llvm-dwarfdump -v -debug-info - | FileCheck -check-prefixes=NOODR,CHECK %s
16 
17 // RUN: dsymutil --linker parallel -f -oso-prepend-path=%p/../Inputs/odr-uniquing -y %p/dummy-debug-map.map -no-odr -o - | llvm-dwarfdump -v -debug-info - | FileCheck -check-prefixes=NOODR,CHECK %s
18 
19 // The first compile unit contains all the types:
20 // CHECK: TAG_compile_unit
21 // CHECK-NOT: DW_TAG
22 // CHECK: AT_name{{.*}}"odr-uniquing.cpp"
23 
24 struct S {
25   struct Nested {};
26 };
27 
28 // CHECK: 0x[[S:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
29 // CHECK-NEXT: DW_AT_name{{.*}}"S"
30 // CHECK-NOT: NULL
31 // CHECK: 0x[[NESTED:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
32 // CHECK-NOT: DW_TAG
33 // CHECK: DW_AT_name{{.*}}"Nested"
34 // CHECK: NULL
35 
36 namespace N {
37 class C {};
38 }
39 
40 // CHECK: DW_TAG_namespace
41 // CHECK-NEXT: DW_AT_name{{.*}}"N"
42 // CHECK-NOT: NULL
43 // CHECK: 0x[[NC:[0-9a-f]*]]:{{.*}}DW_TAG_class_type
44 // CHECK-NEXT: DW_AT_name{{.*}}"C"
45 // CHECK: NULL
46 
47 union U {
48   class C {} C;
49   struct S {} S;
50 };
51 
52 // CHECK:  0x[[U:[0-9a-f]*]]:{{.*}}DW_TAG_union_type
53 // CHECK-NEXT: DW_AT_name{{.*}}"U"
54 // CHECK-NOT: NULL
55 // CHECK:  0x[[UC:[0-9a-f]*]]:{{.*}}DW_TAG_class_type
56 // CHECK-NOT: NULL
57 // CHECK:  0x[[US:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
58 // CHECK: NULL
59 
60 typedef S AliasForS;
61 
62 // CHECK: 0x[[ALIASFORS:[0-9a-f]*]]:{{.*}}DW_TAG_typedef
63 // CHECK-NEXT: DW_AT_type{{.*}}[[S]]
64 // CHECK-NEXT: DW_AT_name{{.*}}"AliasForS"
65 
66 namespace {
67 class AnonC {};
68 }
69 
70 // CHECK: DW_TAG_namespace
71 // CHECK-NOT: {{DW_AT_name|NULL|DW_TAG}}
72 // CHECK: 0x[[ANONC:[0-9a-f]*]]:{{.*}}DW_TAG_class_type
73 // CHECK-NEXT: DW_AT_name{{.*}}"AnonC"
74 
75 // This function is only here to hold objects that refer to the above types.
foo()76 void foo() {
77   AliasForS s;
78   S::Nested n;
79   N::C nc;
80   AnonC ac;
81   U u;
82 }
83 
84 // The second CU contents depend on whether we disabled ODR uniquing or
85 // not.
86 
87 // CHECK: TAG_compile_unit
88 // CHECK-NOT: DW_TAG
89 // CHECK: AT_name{{.*}}"odr-uniquing.cpp"
90 
91 // The union itself is not uniqued for now (for dsymutil-compatibility),
92 // but the types defined inside it should be.
93 // ODR: DW_TAG_union_type
94 // ODR-NEXT: DW_AT_name{{.*}}"U"
95 // ODR: DW_TAG_member
96 // ODR-NEXT: DW_AT_name{{.*}}"C"
97 // ODR-NOT: DW_TAG
98 // ODR: DW_AT_type{{.*}}[[UC]]
99 // ODR: DW_TAG_member
100 // ODR-NEXT: DW_AT_name{{.*}}"S"
101 // ODR-NOT: DW_TAG
102 // ODR: DW_AT_type{{.*}}[[US]]
103 
104 // Check that the variables point to the right type
105 // ODR: DW_TAG_subprogram
106 // ODR-NOT: DW_TAG
107 // ODR: DW_AT_name{{.*}}"foo"
108 // ODR-NOT: NULL
109 // ODR: DW_TAG_variable
110 // ODR-NOT: DW_TAG
111 // ODR: DW_AT_name{{.*}}"s"
112 // ODR-NOT: DW_TAG
113 // ODR: DW_AT_type{{.*}}[[ALIASFORS]]
114 // ODR: DW_AT_name{{.*}}"n"
115 // ODR-NOT: DW_TAG
116 // ODR: DW_AT_type{{.*}}[[NESTED]]
117 // ODR: DW_TAG_variable
118 // ODR-NOT: DW_TAG
119 // ODR: DW_AT_name{{.*}}"nc"
120 // ODR-NOT: DW_TAG
121 // ODR: DW_AT_type{{.*}}[[NC]]
122 // ODR: DW_TAG_variable
123 // ODR-NOT: DW_TAG
124 // ODR: DW_AT_name{{.*}}"ac"
125 // ODR-NOT: DW_TAG
126 // ODR: DW_AT_type{{.*}}[[ANONC]]
127 
128 // With no ODR uniquing, we should get copies of all the types:
129 
130 // This is "struct S"
131 // NOODR: 0x[[DUP_S:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
132 // NOODR-NEXT: DW_AT_name{{.*}}"S"
133 // NOODR-NOT: NULL
134 // NOODR: 0x[[DUP_NESTED:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
135 // NOODR-NOT: DW_TAG
136 // NOODR: DW_AT_name{{.*}}"Nested"
137 
138 // This is "class N::C"
139 // NOODR: DW_TAG_namespace
140 // NOODR-NEXT: DW_AT_name{{.*}}"N"
141 // NOODR: 0x[[DUP_NC:[0-9a-f]*]]:{{.*}}DW_TAG_class_type
142 // NOODR-NEXT: DW_AT_name{{.*}}"C"
143 
144 // This is "union U"
145 // NOODR:  0x[[DUP_U:[0-9a-f]*]]:{{.*}}DW_TAG_union_type
146 // NOODR-NEXT: DW_AT_name{{.*}}"U"
147 // NOODR-NOT: NULL
148 // NOODR:  0x[[DUP_UC:[0-9a-f]*]]:{{.*}}DW_TAG_class_type
149 // NOODR-NOT: NULL
150 // NOODR:  0x[[DUP_US:[0-9a-f]*]]:{{.*}}DW_TAG_structure_type
151 // NOODR: NULL
152 
153 // Check that the variables point to the right type
154 // NOODR: DW_TAG_subprogram
155 // NOODR-NOT: DW_TAG
156 // NOODR: DW_AT_name{{.*}}"foo"
157 // NOODR-NOT: NULL
158 // NOODR: DW_TAG_variable
159 // NOODR-NOT: DW_TAG
160 // NOODR: DW_AT_name{{.*}}"s"
161 // NOODR-NOT: DW_TAG
162 // NOODR: DW_AT_type{{.*}}0x[[DUP_ALIASFORS:[0-9a-f]*]]
163 // NOODR: DW_TAG_variable
164 // NOODR-NOT: DW_TAG
165 // NOODR: DW_AT_name{{.*}}"n"
166 // NOODR-NOT: DW_TAG
167 // NOODR: DW_AT_type{{.*}}[[DUP_NESTED]]
168 // NOODR: DW_TAG_variable
169 // NOODR-NOT: DW_TAG
170 // NOODR: DW_AT_name{{.*}}"nc"
171 // NOODR-NOT: DW_TAG
172 // NOODR: DW_AT_type{{.*}}[[DUP_NC]]
173 // NOODR: DW_TAG_variable
174 // NOODR-NOT: DW_TAG
175 // NOODR: DW_AT_name{{.*}}"ac"
176 // NOODR-NOT: DW_TAG
177 // NOODR: DW_AT_type{{.*}}0x[[DUP_ANONC:[0-9a-f]*]]
178 
179 // This is "AliasForS"
180 // NOODR: 0x[[DUP_ALIASFORS]]:{{.*}}DW_TAG_typedef
181 // NOODR-NOT: DW_TAG
182 // NOODR: DW_AT_name{{.*}}"AliasForS"
183 
184 // This is "(anonymous namespace)::AnonC"
185 // NOODR: DW_TAG_namespace
186 // NOODR-NOT: {{DW_AT_name|NULL|DW_TAG}}
187 // NOODR: 0x[[DUP_ANONC]]:{{.*}}DW_TAG_class_type
188 // NOODR-NEXT: DW_AT_name{{.*}}"AnonC"
189 
190