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