xref: /llvm-project/llvm/test/DebugInfo/X86/generate-odr-hash.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1
2; RUN: llc < %s -o %t -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu
3; RUN: llvm-dwarfdump -v %t | FileCheck --check-prefix=CHECK --check-prefix=SINGLE %s
4; RUN: llvm-readobj -S --symbols %t | FileCheck --check-prefix=OBJ_SINGLE %s
5
6; RUN: llc < %s -split-dwarf-file=foo.dwo -o %t -filetype=obj -O0 -generate-type-units -mtriple=x86_64-unknown-linux-gnu
7; RUN: llvm-dwarfdump -v %t | FileCheck --check-prefix=CHECK --check-prefix=FISSION %s
8; RUN: llvm-readobj -S --symbols %t | FileCheck --check-prefix=OBJ_FISSION %s
9
10; Generated from bar.cpp:
11
12; #line 1 "bar.h"
13; struct bar {};
14; #line 2 "bar.cpp"
15
16; struct bar b;
17
18; void foo(void) {
19;   struct baz {};
20;   baz b;
21; }
22
23; namespace echidna {
24; namespace capybara {
25; namespace mongoose {
26; class fluffy {
27;   int a;
28;   int b;
29; };
30
31; fluffy animal;
32; }
33; }
34; }
35
36; namespace {
37; struct walrus {
38;   walrus() {}
39; };
40; }
41
42; walrus w;
43
44; struct wombat {
45;   struct {
46;     int a;
47;     int b;
48;   } a_b;
49; };
50
51; wombat wom;
52
53; SINGLE-LABEL: .debug_info contents:
54; FISSION-LABEL: .debug_info.dwo contents:
55; CHECK: Compile Unit: length = [[CU_SIZE:[0-9a-f]+]]
56
57; CHECK: [[BAR:^0x........]]: DW_TAG_structure_type
58; CHECK-NEXT: DW_AT_declaration
59; CHECK-NEXT: DW_AT_signature {{.*}} (0x1d02f3be30cc5688)
60; CHECK: [[FLUFFY:^0x........]]: DW_TAG_class_type
61; CHECK-NEXT: DW_AT_declaration
62; CHECK-NEXT: DW_AT_signature {{.*}} (0xb04af47397402e77)
63
64; Ensure the CU-local type 'walrus' is not placed in a type unit.
65; CHECK: [[WALRUS:^0x........]]: DW_TAG_structure_type
66; CHECK-NEXT: DW_AT_name{{.*}}"walrus"
67; CHECK-NEXT: DW_AT_byte_size
68; CHECK-NEXT: DW_AT_decl_file
69; CHECK-NEXT: DW_AT_decl_line
70
71; CHECK: [[WOMBAT:^0x........]]: DW_TAG_structure_type
72; CHECK-NEXT: DW_AT_declaration
73; CHECK-NEXT: DW_AT_signature {{.*}} (0xfd756cee88f8a118)
74
75; SINGLE-LABEL: .debug_types contents:
76; FISSION: .debug_types.dwo contents:
77
78; Check that we generate a hash for bar and the value.
79; CHECK-NOT: type_signature
80; CHECK-LABEL: type_signature = 0x1d02f3be30cc5688
81; CHECK: DW_TAG_structure_type
82; FISSION-NEXT: DW_AT_name {{.*}} (indexed {{.*}} "bar"
83; SINGLE-NEXT: DW_AT_name {{.*}} "bar"
84
85; Check that we generate a hash for fluffy and the value.
86; CHECK-NOT: type_signature
87; CHECK-LABEL: type_signature = 0xb04af47397402e77
88; CHECK-NOT: DW_AT_GNU_odr_signature [DW_FORM_data8]   (0x9a0124d5a0c21c52)
89; CHECK: DW_TAG_namespace
90; CHECK-NEXT: DW_AT_name{{.*}}"echidna"
91; CHECK: DW_TAG_namespace
92; CHECK-NEXT: DW_AT_name{{.*}}"capybara"
93; CHECK: DW_TAG_namespace
94; CHECK-NEXT: DW_AT_name{{.*}}"mongoose"
95; CHECK: DW_TAG_class_type
96; CHECK-NEXT: DW_AT_name{{.*}}"fluffy"
97
98; Check that we generate a hash for wombat and the value, but not for the
99; anonymous type contained within.
100; CHECK-NOT: type_signature
101; CHECK-LABEL: type_signature = 0xfd756cee88f8a118
102; CHECK-NOT: DW_AT_GNU_odr_signature [DW_FORM_data8] (0x685bcc220141e9d7)
103; CHECK: DW_TAG_structure_type
104; CHECK-NEXT: DW_AT_name{{.*}}"wombat"
105
106; CHECK-NOT: type_signature
107; CHECK-LABEL: type_signature = 0xe94f6d3843e62d6b
108; CHECK: DW_TAG_type_unit
109; CHECK: DW_AT_stmt_list [DW_FORM_sec_offset] (0x00000000)
110; CHECK-NOT: NULL
111; CHECK-NOT: DW_AT_GNU_odr_signature
112; CHECK: DW_TAG_structure_type
113; The signature for the outer 'wombat' type
114; CHECK: DW_AT_signature [DW_FORM_ref_sig8] (0xfd756cee88f8a118)
115; CHECK: DW_TAG_structure_type
116; CHECK-NOT: DW_AT_name
117; CHECK-NOT: DW_AT_GNU_odr_signature
118; CHECK: DW_TAG_member
119; CHECK-NEXT: DW_AT_name{{.*}}"a"
120
121; CHECK-LABEL: .debug_line contents:
122; CHECK: Line table prologue
123; CHECK-NOT: file_names[
124; SINGLE: file_names[
125; SINGLE-NEXT: name: "bar.h"
126; CHECK: file_names[
127; CHECK-NEXT: name: "bar.cpp"
128; CHECK-NOT: file_names[
129
130; FISSION: .debug_line.dwo contents:
131; CHECK-NOT: .debug_line.dwo contents:
132; FISSION: Line table prologue
133; FISSION: opcode_base: 1
134; FISSION-NOT: standard_opcode_lengths
135; FISSION-NOT: include_directories
136; FISSION-NOT: file_names[
137; FISSION: file_names[
138; FISSION-NEXT: name: "bar.h"
139; FISSION: file_names[
140; FISSION-NEXT: name: "bar.cpp"
141; FISSION-NOT: file_names[
142
143; CHECK-LABEL: .debug_str contents:
144
145; Use the unit size as a rough hash/identifier for the unit we're dealing with
146; it happens to be unambiguous at the moment, but it's hardly ideal.
147; CHECK-LABEL: .debug_pubtypes contents:
148; Don't emit pubtype entries for type DIEs in the compile unit that just indirect to a type unit.
149; CHECK-NEXT: unit_size = [[CU_SIZE]]
150; CHECK-NEXT: Offset Name
151; CHECK-DAG: [[BAR]] "bar"
152; CHECK-DAG: [[WALRUS]] "(anonymous namespace)::walrus"
153; CHECK-DAG: [[WOMBAT]] "wombat"
154; CHECK-DAG: [[FLUFFY]] "echidna::capybara::mongoose::fluffy"
155
156; Make sure debug_types are in comdat groups. This could be more rigid to check
157; that they're the right comdat groups (each type in a separate comdat group,
158; etc)
159; OBJ_SINGLE: Name: .debug_types (
160; OBJ_SINGLE-NOT: }
161; OBJ_SINGLE: SHF_GROUP
162
163; Fission type units don't go in comdat groups, since their linker is debug
164; aware it's handled using the debug info semantics rather than raw ELF object
165; semantics.
166; OBJ_FISSION: Name: .debug_types.dwo (
167; OBJ_FISSION-NOT: SHF_GROUP
168; OBJ_FISSION: }
169
170source_filename = "test/DebugInfo/X86/generate-odr-hash.ll"
171
172%struct.bar = type { i8 }
173%"class.echidna::capybara::mongoose::fluffy" = type { i32, i32 }
174%"struct.<anonymous namespace>::walrus" = type { i8 }
175%struct.wombat = type { %struct.anon }
176%struct.anon = type { i32, i32 }
177%struct.baz = type { i8 }
178
179@b = global %struct.bar zeroinitializer, align 1, !dbg !0
180@_ZN7echidna8capybara8mongoose6animalE = global %"class.echidna::capybara::mongoose::fluffy" zeroinitializer, align 4, !dbg !6
181@w = internal global %"struct.<anonymous namespace>::walrus" zeroinitializer, align 1, !dbg !16
182@wom = global %struct.wombat zeroinitializer, align 4, !dbg !25
183@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_a, ptr null }]
184
185; Function Attrs: nounwind uwtable
186define void @_Z3foov() #0 !dbg !40 {
187entry:
188  %b = alloca %struct.baz, align 1
189  call void @llvm.dbg.declare(metadata ptr %b, metadata !43, metadata !45), !dbg !46
190  ret void, !dbg !47
191}
192
193; Function Attrs: nounwind readnone
194declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
195
196define internal void @__cxx_global_var_init() section ".text.startup" !dbg !48 {
197entry:
198  call void @_ZN12_GLOBAL__N_16walrusC2Ev(ptr @w), !dbg !49
199  ret void, !dbg !49
200}
201
202; Function Attrs: nounwind uwtable
203define internal void @_ZN12_GLOBAL__N_16walrusC2Ev(ptr %this) unnamed_addr #0 align 2 !dbg !50 {
204entry:
205  %this.addr = alloca ptr, align 8
206  store ptr %this, ptr %this.addr, align 8
207  call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !51, metadata !45), !dbg !53
208  %this1 = load ptr, ptr %this.addr
209  ret void, !dbg !54
210}
211
212define internal void @_GLOBAL__I_a() section ".text.startup" !dbg !55 {
213entry:
214  call void @__cxx_global_var_init(), !dbg !57
215  ret void, !dbg !57
216}
217
218attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
219attributes #1 = { nounwind readnone }
220
221!llvm.dbg.cu = !{!34}
222!llvm.module.flags = !{!37, !38}
223!llvm.ident = !{!39}
224
225!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
226!1 = !DIGlobalVariable(name: "b", scope: null, file: !2, line: 3, type: !3, isLocal: false, isDefinition: true)
227!2 = !DIFile(filename: "bar.cpp", directory: "/tmp/dbginfo")
228!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "bar", file: !4, line: 1, size: 8, align: 8, elements: !5, identifier: "_ZTS3bar")
229!4 = !DIFile(filename: "bar.h", directory: "/tmp/dbginfo")
230!5 = !{}
231!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
232!7 = !DIGlobalVariable(name: "animal", linkageName: "_ZN7echidna8capybara8mongoose6animalE", scope: !8, file: !2, line: 18, type: !11, isLocal: false, isDefinition: true)
233!8 = !DINamespace(name: "mongoose", scope: !9)
234!9 = !DINamespace(name: "capybara", scope: !10)
235!10 = !DINamespace(name: "echidna", scope: null)
236!11 = !DICompositeType(tag: DW_TAG_class_type, name: "fluffy", scope: !8, file: !2, line: 13, size: 64, align: 32, elements: !12, identifier: "_ZTSN7echidna8capybara8mongoose6fluffyE")
237!12 = !{!13, !15}
238!13 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !2, line: 14, baseType: !14, size: 32, align: 32, flags: DIFlagPrivate)
239!14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
240!15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !11, file: !2, line: 15, baseType: !14, size: 32, align: 32, offset: 32, flags: DIFlagPrivate)
241!16 = !DIGlobalVariableExpression(var: !17, expr: !DIExpression())
242!17 = !DIGlobalVariable(name: "w", scope: null, file: !2, line: 29, type: !18, isLocal: true, isDefinition: true)
243!18 = !DICompositeType(tag: DW_TAG_structure_type, name: "walrus", scope: !19, file: !2, line: 24, size: 8, align: 8, elements: !20)
244!19 = !DINamespace(scope: null)
245!20 = !{!21}
246!21 = !DISubprogram(name: "walrus", scope: !18, file: !2, line: 25, type: !22, isLocal: false, isDefinition: false, scopeLine: 25, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false)
247!22 = !DISubroutineType(types: !23)
248!23 = !{null, !24}
249!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
250!25 = !DIGlobalVariableExpression(var: !26, expr: !DIExpression())
251!26 = !DIGlobalVariable(name: "wom", scope: null, file: !2, line: 38, type: !27, isLocal: false, isDefinition: true)
252!27 = !DICompositeType(tag: DW_TAG_structure_type, name: "wombat", file: !2, line: 31, size: 64, align: 32, elements: !28, identifier: "_ZTS6wombat")
253!28 = !{!29}
254!29 = !DIDerivedType(tag: DW_TAG_member, name: "a_b", scope: !27, file: !2, line: 35, baseType: !30, size: 64, align: 32)
255!30 = !DICompositeType(tag: DW_TAG_structure_type, scope: !27, file: !2, line: 32, size: 64, align: 32, elements: !31, identifier: "_ZTSN6wombatUt_E")
256!31 = !{!32, !33}
257!32 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !30, file: !2, line: 33, baseType: !14, size: 32, align: 32)
258!33 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !30, file: !2, line: 34, baseType: !14, size: 32, align: 32, offset: 32)
259!34 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.5 ", isOptimized: false, runtimeVersion: 0, splitDebugFilename: "bar.dwo", emissionKind: FullDebug, enums: !5, retainedTypes: !35, globals: !36, imports: !5)
260!35 = !{!3, !11, !27, !30}
261!36 = !{!0, !6, !16, !25}
262!37 = !{i32 2, !"Dwarf Version", i32 4}
263!38 = !{i32 1, !"Debug Info Version", i32 3}
264!39 = !{!"clang version 3.5 "}
265!40 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !2, file: !2, line: 5, type: !41, isLocal: false, isDefinition: true, scopeLine: 5, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !34, retainedNodes: !5)
266!41 = !DISubroutineType(types: !42)
267!42 = !{null}
268!43 = !DILocalVariable(name: "b", scope: !40, file: !2, line: 7, type: !44)
269!44 = !DICompositeType(tag: DW_TAG_structure_type, name: "baz", scope: !40, file: !2, line: 6, size: 8, align: 8, elements: !5)
270!45 = !DIExpression()
271!46 = !DILocation(line: 7, scope: !40)
272!47 = !DILocation(line: 8, scope: !40)
273!48 = distinct !DISubprogram(name: "__cxx_global_var_init", scope: !2, file: !2, line: 29, type: !41, isLocal: true, isDefinition: true, scopeLine: 29, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !34, retainedNodes: !5)
274!49 = !DILocation(line: 29, scope: !48)
275!50 = distinct !DISubprogram(name: "walrus", linkageName: "_ZN12_GLOBAL__N_16walrusC2Ev", scope: !18, file: !2, line: 25, type: !22, isLocal: true, isDefinition: true, scopeLine: 25, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !34, declaration: !21, retainedNodes: !5)
276!51 = !DILocalVariable(name: "this", arg: 1, scope: !50, type: !52, flags: DIFlagArtificial | DIFlagObjectPointer)
277!52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64, align: 64)
278!53 = !DILocation(line: 0, scope: !50)
279!54 = !DILocation(line: 25, scope: !50)
280!55 = distinct !DISubprogram(linkageName: "_GLOBAL__I_a", scope: !2, file: !2, line: 25, type: !56, isLocal: true, isDefinition: true, scopeLine: 25, virtualIndex: 6, flags: DIFlagArtificial, isOptimized: false, unit: !34, retainedNodes: !5)
281!56 = !DISubroutineType(types: !5)
282!57 = !DILocation(line: 25, scope: !55)
283
284