xref: /llvm-project/llvm/test/DebugInfo/X86/string-offsets-multiple-cus.ll (revision ddbde9a4add367c12b4ff8bda5e7a6b351b645c6)
1; REQUIRES: object-emission
2; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj < %s | llvm-dwarfdump -v - | \
3; RUN:    FileCheck --check-prefix=DEFAULT --check-prefix=BOTH %s
4; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -generate-type-units < %s |  \
5; RUN:    llvm-dwarfdump -v - | FileCheck --check-prefix=TYPEUNITS --check-prefix=BOTH %s
6;
7; Check that we generate the DWARF v5 string offsets section correctly when we
8; have multiple compile and type units. All units share one contribution to
9; the string offsets section.
10;
11; Constructed from the following sources with
12; clang -gdwarf-5 -emit-llvm -S a.cpp
13; clang -gdwarf-5 -emit-llvm -S b.cpp
14; clang -gdwarf-5 -emit-llvm -S c.cpp
15; llvm-link a.ll b.ll c.ll -o test.bc
16; llvm-dis test.bc -o test.ll
17;
18; a.cpp:
19; enum E1 {a, b, c};
20; E1 glob1;
21;
22; b.cpp:
23; enum E2 {d, e, f};
24; E2 glob2;
25;
26; c.cpp:
27; enum E3 {g, h, i};
28; E3 glob3;
29;
30; Check that all 3 compile units have the correct DW_AT_str_offsets_base attributes
31; with the correct offsets. Check that strings referenced by compile units 2 and 3
32; are displayed correctly.
33;
34; BOTH:        .debug_info contents:
35;
36; Verify that all 3 type units have the proper DW_AT_str_offsets_base attribute.
37; TYPEUNITS-NOT:  contents:
38; TYPEUNITS:      DW_TAG_type_unit
39; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
40; TYPEUNITS:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF:[0-9a-f]+]])
41; TYPEUNITS-NOT:  NULL
42; TYPEUNITS:      DW_TAG_enumerator
43; TYPEUNITS-NOT:  NULL
44; TYPEUNITS:      DW_TAG_enumerator
45; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
46; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] ( indexed (00000005) string = "b")
47; TYPEUNITS-NOT:  contents:
48; TYPEUNITS:      DW_TAG_type_unit
49; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
50; TYPEUNITS:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
51; TYPEUNITS-NOT:  NULL
52; TYPEUNITS:      DW_TAG_enumeration_type
53; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] ( indexed (0000000d) string = "E2")
54; TYPEUNITS-NOT:  contents:
55; TYPEUNITS:      DW_TAG_type_unit
56; TYPEUNITS-NOT:  {{DW_TAG|NULL}}
57; TYPEUNITS:      DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
58; TYPEUNITS-NOT:  NULL
59; TYPEUNITS:      DW_TAG_enumeration_type
60; TYPEUNITS:      DW_AT_name [DW_FORM_strx1] ( indexed (00000013) string = "E3")
61
62; CU 1
63; BOTH-NOT:    .contents:
64; BOTH:        DW_TAG_compile_unit
65; BOTH-NOT:    {{DW_TAG|NULL}}
66; DEFAULT:     DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF:[0-9a-f]+]])
67; TYPEUNITS:   DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
68;
69; CU 2
70; BOTH-NOT:    contents:
71; BOTH:        DW_TAG_compile_unit
72; BOTH-NOT:    {{DW_TAG|NULL}}
73; BOTH:        DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
74; BOTH-NOT:    NULL
75; BOTH:        DW_TAG_variable
76; BOTH-NOT:    {{DW_TAG|NULL}}
77; BOTH:        DW_AT_name [DW_FORM_strx1] ( indexed (00000009) string = "glob2")
78;
79; CU 3
80; BOTH-NOT:    contents:
81; BOTH:        DW_TAG_compile_unit
82; BOTH-NOT:    {{DW_TAG|NULL}}
83; BOTH:        DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x[[CU1_STROFF]])
84; BOTH-NOT:    NULL
85; BOTH:        DW_TAG_variable
86; BOTH-NOT:    {{DW_TAG|NULL}}
87; BOTH:        DW_AT_name [DW_FORM_strx1] ( indexed (0000000f) string = "glob3")
88;
89; Extract the offset of a string to verify that it is referenced in the string
90; offsets section.
91; BOTH:           .debug_str contents:
92; BOTH-NOT:       contents:
93; BOTH:           0x[[GLOB2OFF:[0-9a-f]+]]: "glob2"
94;
95; Check the .debug_str_offsets section header and make sure the referenced string
96; has the correct offset.
97; BOTH:           .debug_str_offsets contents:
98; BOTH-NEXT:      0x00000000: Contribution size = 84, Format = DWARF32, Version = 5
99; BOTH-NEXT:      0x[[CU1_STROFF]]:
100; BOTH-NEXT:      {{.*:}}
101; BOTH-NEXT:      {{.*:}}
102; BOTH-NEXT:      {{.*:}}
103; BOTH-NEXT:      {{.*:}}
104; BOTH-NEXT:      {{.*:}}
105; BOTH-NEXT:      {{.*:}}
106; BOTH-NEXT:      {{.*:}}
107; BOTH-NEXT:      {{.*:}}
108; The string with index 9 should be "glob2"
109; BOTH-NEXT:      {{.*:}} [[GLOB2OFF]]
110;
111; ModuleID = 'test.bc'
112source_filename = "llvm-link"
113
114@glob1 = global i32 0, align 4, !dbg !0
115@glob2 = global i32 0, align 4, !dbg !11
116@glob3 = global i32 0, align 4, !dbg !22
117
118!llvm.dbg.cu = !{!2, !13, !24}
119!llvm.ident = !{!33, !33, !33}
120!llvm.module.flags = !{!34, !35, !36}
121
122!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
123!1 = distinct !DIGlobalVariable(name: "glob1", scope: !2, file: !3, line: 2, type: !5, isLocal: false, isDefinition: true)
124!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 322415)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !10)
125!3 = !DIFile(filename: "a1.cpp", directory: "/home/test", checksumkind: CSK_MD5, checksum: "2ca3eeed18355d6ebbae671eafda5aae")
126!4 = !{!5}
127!5 = distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "E1", file: !3, line: 1, size: 32, elements: !6, identifier: "_ZTS2E1")
128!6 = !{!7, !8, !9}
129!7 = !DIEnumerator(name: "a", value: 0)
130!8 = !DIEnumerator(name: "b", value: 1)
131!9 = !DIEnumerator(name: "c", value: 2)
132!10 = !{!0}
133!11 = !DIGlobalVariableExpression(var: !12, expr: !DIExpression())
134!12 = distinct !DIGlobalVariable(name: "glob2", scope: !13, file: !14, line: 2, type: !16, isLocal: false, isDefinition: true)
135!13 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !14, producer: "clang version 7.0.0 (trunk 322415)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !15, globals: !21)
136!14 = !DIFile(filename: "b.cpp", directory: "/home/test", checksumkind: CSK_MD5, checksum: "0e254f89617ecb6c4e5473546a99435c")
137!15 = !{!16}
138!16 = distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "E2", file: !14, line: 1, size: 32, elements: !17, identifier: "_ZTS2E2")
139!17 = !{!18, !19, !20}
140!18 = !DIEnumerator(name: "d", value: 0)
141!19 = !DIEnumerator(name: "e", value: 1)
142!20 = !DIEnumerator(name: "f", value: 2)
143!21 = !{!11}
144!22 = !DIGlobalVariableExpression(var: !23, expr: !DIExpression())
145!23 = distinct !DIGlobalVariable(name: "glob3", scope: !24, file: !25, line: 2, type: !27, isLocal: false, isDefinition: true)
146!24 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !25, producer: "clang version 7.0.0 (trunk 322415)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !26, globals: !32)
147!25 = !DIFile(filename: "c.cpp", directory: "/home/test", checksumkind: CSK_MD5, checksum: "7835aaaa683fa09d295adef0e934d392")
148!26 = !{!27}
149!27 = distinct !DICompositeType(tag: DW_TAG_enumeration_type, name: "E3", file: !25, line: 1, size: 32, elements: !28, identifier: "_ZTS2E3")
150!28 = !{!29, !30, !31}
151!29 = !DIEnumerator(name: "g", value: 0)
152!30 = !DIEnumerator(name: "h", value: 1)
153!31 = !DIEnumerator(name: "i", value: 2)
154!32 = !{!22}
155!33 = !{!"clang version 7.0.0 (trunk 322415)"}
156!34 = !{i32 2, !"Dwarf Version", i32 5}
157!35 = !{i32 2, !"Debug Info Version", i32 3}
158!36 = !{i32 1, !"wchar_size", i32 4}
159