1; $ clang++ -S -emit-llvm -o - -gdwarf-5 -o - -O1 tail2.cc 2; volatile int sink; 3; void __attribute__((noinline)) bat() { sink++; } 4; void __attribute__((noinline)) bar() { sink++; } 5; void __attribute__((noinline)) foo() { 6; bar(); bat(); 7; bar(); bat(); 8; } 9; int __attribute__((disable_tail_calls)) main() { foo(); } 10 11; On Windows, we don't handle the relocations needed for AT_return_pc properly 12; and fail with "failed to compute relocation: IMAGE_REL_AMD64_ADDR32". 13; UNSUPPORTED: cygwin,windows-gnu,windows-msvc 14 15; RUN: llc -mtriple=x86_64 < %s -o - | FileCheck %s -check-prefix=ASM 16; RUN: llc -mtriple=x86_64 -debugger-tune=lldb < %s -filetype=obj -o %t.o 17; RUN: llvm-dwarfdump %t.o -o - | FileCheck %s -check-prefix=OBJ -implicit-check-not=DW_TAG_call -implicit-check-not=DW_AT_call 18; RUN: llvm-dwarfdump -verify %t.o 2>&1 | FileCheck %s -check-prefix=VERIFY 19; RUN: llvm-dwarfdump -statistics %t.o | FileCheck %s -check-prefix=STATS 20; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis -o /dev/null 21 22; VERIFY: No errors. 23; STATS: "#call site DIEs": 6, 24 25@sink = global i32 0, align 4, !dbg !0 26 27define void @__has_no_subprogram() { 28entry: 29 %0 = load volatile i32, i32* @sink, align 4 30 %inc = add nsw i32 %0, 1 31 store volatile i32 %inc, i32* @sink, align 4 32 ret void 33} 34 35; ASM: DW_TAG_subprogram 36; ASM: DW_AT_call_all_calls 37; OBJ: [[bat_sp:.*]]: DW_TAG_subprogram 38; OBJ: DW_AT_call_all_calls (true) 39; OBJ: DW_AT_name ("bat") 40define void @_Z3batv() !dbg !13 { 41entry: 42 %0 = load volatile i32, i32* @sink, align 4, !dbg !16, !tbaa !17 43 %inc = add nsw i32 %0, 1, !dbg !16 44 store volatile i32 %inc, i32* @sink, align 4, !dbg !16, !tbaa !17 45 ret void, !dbg !21 46} 47 48; ASM: DW_TAG_subprogram 49; ASM: DW_AT_call_all_calls 50; OBJ: [[bar_sp:.*]]: DW_TAG_subprogram 51; OBJ: DW_AT_call_all_calls (true) 52; OBJ: DW_AT_name ("bar") 53define void @_Z3barv() !dbg !22 { 54entry: 55 %0 = load volatile i32, i32* @sink, align 4, !dbg !23, !tbaa !17 56 %inc = add nsw i32 %0, 1, !dbg !23 57 store volatile i32 %inc, i32* @sink, align 4, !dbg !23, !tbaa !17 58 ret void, !dbg !24 59} 60 61; ASM: DW_TAG_subprogram 62; ASM: DW_AT_call_all_calls 63; OBJ: [[foo_sp:.*]]: DW_TAG_subprogram 64; OBJ: DW_AT_call_all_calls (true) 65; OBJ: DW_AT_name ("foo") 66; OBJ: DW_TAG_call_site 67; OBJ: DW_AT_call_origin ([[bar_sp]]) 68; OBJ: DW_AT_call_return_pc 69; OBJ: DW_TAG_call_site 70; OBJ: DW_AT_call_origin ([[bat_sp]]) 71; OBJ: DW_AT_call_return_pc 72; OBJ: DW_TAG_call_site 73; OBJ: DW_AT_call_origin ([[bar_sp]]) 74; OBJ: DW_AT_call_return_pc 75; OBJ: DW_TAG_call_site 76; OBJ: DW_AT_call_origin ([[bat_sp]]) 77; OBJ: DW_AT_call_tail_call 78; OBJ: DW_AT_call_pc 79define void @_Z3foov() !dbg !25 { 80entry: 81 tail call void @__has_no_subprogram() 82 tail call void @_Z3barv(), !dbg !26 83 tail call void @_Z3batv(), !dbg !27 84 tail call void @_Z3barv(), !dbg !26 85 tail call void @_Z3batv(), !dbg !27 86 ret void, !dbg !28 87} 88 89; ASM: DW_TAG_subprogram 90; ASM: DW_AT_call_all_calls 91; OBJ: DW_TAG_subprogram 92; OBJ: DW_AT_call_all_calls (true) 93; OBJ: DW_AT_name ("main") 94; OBJ: DW_TAG_call_site 95; OBJ: DW_AT_call_origin ([[foo_sp]]) 96; OBJ: DW_AT_call_return_pc 97; OBJ: DW_TAG_call_site 98; OBJ: DW_AT_call_target 99; OBJ: DW_AT_call_return_pc 100define i32 @main() !dbg !29 { 101entry: 102 call void @_Z3foov(), !dbg !32 103 104 %indirect_target = load void ()*, void ()** undef 105 call void %indirect_target() 106 107 call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"() 108 109 ret i32 0, !dbg !33 110} 111 112!llvm.dbg.cu = !{!2} 113!llvm.module.flags = !{!8, !9, !10, !11} 114!llvm.ident = !{!12} 115 116!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 117!1 = distinct !DIGlobalVariable(name: "sink", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true) 118!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) 119!3 = !DIFile(filename: "/Users/vsk/src/llvm.org-tailcall/tail2.cc", directory: "/Users/vsk/src/builds/llvm-project-tailcall-RA", checksumkind: CSK_MD5, checksum: "3b61952c21b7f657ddb7c0ad44cf5529") 120!4 = !{} 121!5 = !{!0} 122!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) 123!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 124!8 = !{i32 2, !"Dwarf Version", i32 5} 125!9 = !{i32 2, !"Debug Info Version", i32 3} 126!10 = !{i32 1, !"wchar_size", i32 4} 127!11 = !{i32 7, !"PIC Level", i32 2} 128!12 = !{!"clang version 7.0.0 "} 129!13 = distinct !DISubprogram(name: "bat", linkageName: "_Z3batv", scope: !3, file: !3, line: 2, type: !14, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, isOptimized: true, unit: !2, retainedNodes: !4) 130!14 = !DISubroutineType(types: !15) 131!15 = !{null} 132!16 = !DILocation(line: 2, column: 44, scope: !13) 133!17 = !{!18, !18, i64 0} 134!18 = !{!"int", !19, i64 0} 135!19 = !{!"omnipotent char", !20, i64 0} 136!20 = !{!"Simple C++ TBAA"} 137!21 = !DILocation(line: 2, column: 48, scope: !13) 138!22 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !3, file: !3, line: 3, type: !14, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, isOptimized: true, unit: !2, retainedNodes: !4) 139!23 = !DILocation(line: 3, column: 44, scope: !22) 140!24 = !DILocation(line: 3, column: 48, scope: !22) 141!25 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !3, file: !3, line: 4, type: !14, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, isOptimized: true, unit: !2, retainedNodes: !4) 142!26 = !DILocation(line: 5, column: 3, scope: !25) 143!27 = !DILocation(line: 6, column: 3, scope: !25) 144!28 = !DILocation(line: 7, column: 1, scope: !25) 145!29 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 8, type: !30, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, isOptimized: true, unit: !2, retainedNodes: !4) 146!30 = !DISubroutineType(types: !31) 147!31 = !{!7} 148!32 = !DILocation(line: 8, column: 50, scope: !29) 149!33 = !DILocation(line: 8, column: 57, scope: !29) 150