1; RUN: llc -mtriple=x86_64-linux-gnu -filetype=asm %s -o - | FileCheck %s
2
3; The prologue-end line record must be emitted after the last instruction that
4; is part of the function frame setup code and before the instruction that marks
5; the beginning of the function body.
6;
7; For the given test, generated from:
8;
9; 1 extern int get_arg();
10; 2 extern void func(int x);
11; 3
12; 4 int main()
13; 5 {
14; 6   int a;
15; 7   func(get_arg());
16; 8 }
17; 9
18
19; The prologue-end line record is emitted with an incorrect associated address,
20; which causes a debugger to show the beginning of function body to be inside
21; the prologue.
22
23; This can be seen in the following trimmed assembler output:
24;
25; main:
26;   ...
27; # %bb.0:
28;   .loc	1 7 0 prologue_end
29;   pushq	%rax
30;   .cfi_def_cfa_offset 16
31;   callq	_Z7get_argv
32;   ...
33;   retq
34
35; The instruction 'pushq %rax' is part of the frame setup code.
36
37; The correct location for the prologue-end line information is just before
38; the call to '_Z7get_argv', as illustrated in the following trimmed
39; assembler output:
40;
41; main:
42;   ...
43; # %bb.0:
44;   pushq  %rax
45;   .cfi_def_cfa_offset 16
46;   .loc  1 7 0 prologue_end
47;   callq  _Z7get_argv
48;   ...
49;   retq
50
51; Check that the generated assembler matches the following sequence:
52
53; CHECK:      # %bb.0:
54; CHECK-NEXT:  	pushq	%rax
55; CHECK-NEXT:  	.cfi_def_cfa_offset 16
56; CHECK-NEXT: .Ltmp0:
57; CHECK-NEXT:  	.loc	1 7 8 prologue_end {{.*}}# invalid-prologue-end.cpp:7:8
58; CHECK-NEXT:  	callq	_Z7get_argv
59
60define i32 @main() #0 !dbg !7 {
61entry:
62  %a = alloca i32, align 4
63  call void @llvm.dbg.declare(metadata i32* %a, metadata !11, metadata !DIExpression()), !dbg !12
64  %call = call i32 @_Z7get_argv(), !dbg !13
65  call void @_Z4funci(i32 %call), !dbg !14
66  ret i32 0, !dbg !15
67}
68
69declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
70declare void @_Z4funci(i32) #2
71declare i32 @_Z7get_argv() #2
72
73!llvm.dbg.cu = !{!0}
74!llvm.module.flags = !{!3, !4, !5}
75!llvm.ident = !{!6}
76
77!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk 322269)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
78!1 = !DIFile(filename: "invalid-prologue-end.cpp", directory: "/home/carlos/llvm-root/work")
79!2 = !{}
80!3 = !{i32 2, !"Dwarf Version", i32 4}
81!4 = !{i32 2, !"Debug Info Version", i32 3}
82!5 = !{i32 1, !"wchar_size", i32 4}
83!6 = !{!"clang version 7.0.0 (trunk 322269)"}
84!7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
85!8 = !DISubroutineType(types: !9)
86!9 = !{!10}
87!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
88!11 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 6, type: !10)
89!12 = !DILocation(line: 6, column: 7, scope: !7)
90!13 = !DILocation(line: 7, column: 8, scope: !7)
91!14 = !DILocation(line: 7, column: 3, scope: !7)
92!15 = !DILocation(line: 8, column: 1, scope: !7)
93
94