• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc -mtriple=x86_64-apple-darwin -filetype=obj < %s -o %t.o
2; RUN: llvm-dwarfdump %t.o | FileCheck %s -implicit-check-not=DW_TAG_subprogram
3; RUN: llvm-dwarfdump --verify %t.o
4
5; This test checks that cross-CU references within call site tags to subprogram
6; definitions are well-formed. There are 5 cases checked in this test. Each set
7; of checks is numbered and has a brief summary.
8
9; Instructions to regenerate the IR:
10; clang -O1 -g -emit-llvm -o a.bc -c a.c
11; clang -O1 -g -emit-llvm -o b.bc -c b.c
12; llvm-link -o linked.bc a.bc b.bc
13; opt -O1 linked.bc -o merged.bc
14
15; Source:
16; // a.c
17; __attribute__((optnone)) void noinline_func_in_a() {}
18;
19; __attribute__((optnone)) static void foo() {}
20; __attribute__((always_inline)) void always_inline_helper_in_a_that_calls_foo() {
21;   foo();
22; }
23;
24; extern void func_from_b();
25; void call_func_in_b_from_a() {
26;   func_from_b();
27; }
28;
29; // b.c
30; extern void noinline_func_in_a();
31; void call_noinline_func_in_a_from_b() {
32;   noinline_func_in_a();
33; }
34;
35; __attribute__((optnone)) void foo() {}
36; extern void always_inline_helper_in_a_that_calls_foo();
37; void call_both_foos_from_b() {
38;   foo();
39;   always_inline_helper_in_a_that_calls_foo();
40; }
41;
42; __attribute__((optnone)) void func_from_b() {}
43; void call_func_in_b_from_b() {
44;   func_from_b();
45; }
46
47; === CU for a.c ===
48
49; CHECK: DW_TAG_compile_unit
50; CHECK:   DW_AT_name ("a.c")
51
52; CHECK: 0x{{0+}}[[NOINLINE_FUNC_IN_A:.*]]: DW_TAG_subprogram
53; CHECK:   DW_AT_name ("noinline_func_in_a")
54
55; 1) Check that "always_inline_helper_in_a_that_calls_foo" calls the "foo" in
56; a.c, and *not* the "foo" in b.c.
57; CHECK: 0x{{0+}}[[ALWAYS_INLINE_HELPER_IN_A:.*]]: DW_TAG_subprogram
58; CHECK:   DW_AT_abstract_origin ({{.*}} "always_inline_helper_in_a_that_calls_foo")
59; CHECK:   DW_TAG_call_site
60; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[FOO_IN_A:.*]])
61
62; CHECK: 0x{{0+}}[[FOO_IN_A]]: DW_TAG_subprogram
63; CHECK:   DW_AT_name ("foo")
64
65; 2) Check that "call_func_in_b_from_a" has a cross-CU ref into b.c.
66; CHECK: DW_TAG_subprogram
67; CHECK:   DW_AT_name ("call_func_in_b_from_a")
68; CHECK:   DW_TAG_call_site
69; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[FUNC_FROM_B:.*]])
70
71; CHECK: DW_TAG_subprogram
72; CHECK:   DW_AT_name ("always_inline_helper_in_a_that_calls_foo")
73; CHECK:   DW_AT_inline (DW_INL_inlined)
74
75; === CU for b.c ===
76
77; CHECK: DW_TAG_compile_unit
78; CHECK:   DW_AT_name ("b.c")
79
80; 3) Validate the cross-CU ref from "call_func_in_b_from_a" in a.c.
81; CHECK: 0x{{0+}}[[FUNC_FROM_B]]: DW_TAG_subprogram
82; CHECK:   DW_AT_name ("func_from_b")
83
84; 4) Validate the cross-CU ref from "call_noinline_func_in_a_from_b" in b.c.
85; CHECK: DW_TAG_subprogram
86; CHECK:   DW_AT_name ("call_noinline_func_in_a_from_b")
87; CHECK:   DW_TAG_call_site
88; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[NOINLINE_FUNC_IN_A]])
89
90; CHECK: 0x{{0+}}[[FOO_IN_B:.*]]: DW_TAG_subprogram
91; CHECK:   DW_AT_name ("foo")
92
93; 5) Validate that we correctly emit a cross-CU ref when the call is inlined
94; from another CU.
95; CHECK: DW_TAG_subprogram
96; CHECK:   DW_AT_name ("call_both_foos_from_b")
97; CHECK:   DW_TAG_call_site
98; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[FOO_IN_B]])
99; CHECK:   DW_TAG_call_site
100; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[FOO_IN_A]])
101
102; CHECK: DW_TAG_subprogram
103; CHECK:   DW_AT_name ("call_func_in_b_from_b")
104; CHECK:   DW_TAG_call_site
105; CHECK-NEXT: DW_AT_call_origin (0x{{0+}}[[FUNC_FROM_B]])
106
107target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
108target triple = "x86_64-apple-macosx10.14.0"
109
110define void @noinline_func_in_a() local_unnamed_addr #0 !dbg !17 {
111entry:
112  ret void, !dbg !20
113}
114
115define void @always_inline_helper_in_a_that_calls_foo() local_unnamed_addr #1 !dbg !21 {
116entry:
117  tail call fastcc void @foo.2(), !dbg !22
118  ret void, !dbg !23
119}
120
121define internal fastcc void @foo.2() unnamed_addr #0 !dbg !24 {
122entry:
123  ret void, !dbg !25
124}
125
126define void @call_func_in_b_from_a() local_unnamed_addr !dbg !26 {
127entry:
128  tail call void @func_from_b() #3, !dbg !27
129  ret void, !dbg !28
130}
131
132define void @call_noinline_func_in_a_from_b() local_unnamed_addr !dbg !29 {
133entry:
134  tail call void @noinline_func_in_a() #3, !dbg !30
135  ret void, !dbg !31
136}
137
138define void @foo() local_unnamed_addr #0 !dbg !32 {
139entry:
140  ret void, !dbg !33
141}
142
143define void @call_both_foos_from_b() local_unnamed_addr !dbg !34 {
144entry:
145  tail call void @foo(), !dbg !35
146  tail call fastcc void @foo.2() #3, !dbg !36
147  ret void, !dbg !38
148}
149
150define void @func_from_b() local_unnamed_addr #0 !dbg !39 {
151entry:
152  ret void, !dbg !40
153}
154
155define void @call_func_in_b_from_b() local_unnamed_addr !dbg !41 {
156entry:
157  tail call void @func_from_b(), !dbg !42
158  ret void, !dbg !43
159}
160
161attributes #0 = { noinline }
162attributes #1 = { alwaysinline }
163
164!llvm.dbg.cu = !{!0, !7}
165!llvm.ident = !{!12, !12}
166!llvm.module.flags = !{!13, !14, !15, !16}
167
168!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 310e85309f870ee7347ef979d7d8da9bf28e92ea)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
169!1 = !DIFile(filename: "a.c", directory: "/Users/vsk/tmp/lto-entry-vals")
170!2 = !{}
171!3 = !{!4}
172!4 = !DISubprogram(name: "func_from_b", scope: !1, file: !1, line: 8, type: !5, spFlags: DISPFlagOptimized, retainedNodes: !2)
173!5 = !DISubroutineType(types: !6)
174!6 = !{null, null}
175!7 = distinct !DICompileUnit(language: DW_LANG_C99, file: !8, producer: "clang version 10.0.0 (git@github.com:llvm/llvm-project.git 310e85309f870ee7347ef979d7d8da9bf28e92ea)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !9, nameTableKind: None)
176!8 = !DIFile(filename: "b.c", directory: "/Users/vsk/tmp/lto-entry-vals")
177!9 = !{!10, !11}
178!10 = !DISubprogram(name: "noinline_func_in_a", scope: !8, file: !8, line: 1, type: !5, spFlags: DISPFlagOptimized, retainedNodes: !2)
179!11 = !DISubprogram(name: "always_inline_helper_in_a_that_calls_foo", scope: !8, file: !8, line: 7, type: !5, spFlags: DISPFlagOptimized, retainedNodes: !2)
180!12 = !{!"clang version 10.0.0 (git@github.com:llvm/llvm-project.git 310e85309f870ee7347ef979d7d8da9bf28e92ea)"}
181!13 = !{i32 7, !"Dwarf Version", i32 4}
182!14 = !{i32 2, !"Debug Info Version", i32 3}
183!15 = !{i32 1, !"wchar_size", i32 4}
184!16 = !{i32 7, !"PIC Level", i32 2}
185!17 = distinct !DISubprogram(name: "noinline_func_in_a", scope: !1, file: !1, line: 1, type: !18, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
186!18 = !DISubroutineType(types: !19)
187!19 = !{null}
188!20 = !DILocation(line: 1, column: 53, scope: !17)
189!21 = distinct !DISubprogram(name: "always_inline_helper_in_a_that_calls_foo", scope: !1, file: !1, line: 4, type: !18, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
190!22 = !DILocation(line: 5, column: 3, scope: !21)
191!23 = !DILocation(line: 6, column: 1, scope: !21)
192!24 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 3, type: !18, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
193!25 = !DILocation(line: 3, column: 45, scope: !24)
194!26 = distinct !DISubprogram(name: "call_func_in_b_from_a", scope: !1, file: !1, line: 9, type: !18, scopeLine: 9, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
195!27 = !DILocation(line: 10, column: 3, scope: !26)
196!28 = !DILocation(line: 11, column: 1, scope: !26)
197!29 = distinct !DISubprogram(name: "call_noinline_func_in_a_from_b", scope: !8, file: !8, line: 2, type: !18, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !2)
198!30 = !DILocation(line: 3, column: 3, scope: !29)
199!31 = !DILocation(line: 4, column: 1, scope: !29)
200!32 = distinct !DISubprogram(name: "foo", scope: !8, file: !8, line: 6, type: !18, scopeLine: 6, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !2)
201!33 = !DILocation(line: 6, column: 38, scope: !32)
202!34 = distinct !DISubprogram(name: "call_both_foos_from_b", scope: !8, file: !8, line: 8, type: !18, scopeLine: 8, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !2)
203!35 = !DILocation(line: 9, column: 3, scope: !34)
204!36 = !DILocation(line: 5, column: 3, scope: !21, inlinedAt: !37)
205!37 = distinct !DILocation(line: 10, column: 3, scope: !34)
206!38 = !DILocation(line: 11, column: 1, scope: !34)
207!39 = distinct !DISubprogram(name: "func_from_b", scope: !8, file: !8, line: 13, type: !18, scopeLine: 13, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !2)
208!40 = !DILocation(line: 13, column: 46, scope: !39)
209!41 = distinct !DISubprogram(name: "call_func_in_b_from_b", scope: !8, file: !8, line: 14, type: !18, scopeLine: 14, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !7, retainedNodes: !2)
210!42 = !DILocation(line: 15, column: 3, scope: !41)
211!43 = !DILocation(line: 16, column: 1, scope: !41)
212