1# RUN: llc -emit-call-site-info -start-before=livedebugvalues -stop-after=machineverifier -o - %s \
2# RUN:   | FileCheck %s -check-prefix=MIR
3
4# RUN: llc -emit-call-site-info -start-before=livedebugvalues -filetype=obj -o - %s \
5# RUN:   | llvm-dwarfdump - | FileCheck %s -check-prefix=DWARF -implicit-check-not=DW_OP_entry_value
6
7# // Original Source
8# struct fat_ptr {
9#   int *ptr, *low, *high;
10# };
11# extern int baz(int x);
12# int bar(struct fat_ptr f) {
13#   return baz(baz(*f.ptr));
14# }
15
16# MIR:      renamable $w0 = LDRWui killed renamable $x8
17# MIR-NEXT: DBG_VALUE $x0, 0, {{.*}}, !DIExpression(DW_OP_LLVM_entry_value, 1)
18# MIR-NEXT: BL @baz
19# MIR-NEXT: frame-destroy LDPXpost
20# MIR-NEXT: TCRETURNdi @baz
21
22# After w0 is clobbered, we should get an indirect parameter entry value for "f".
23
24# DWARF-LABEL: DW_TAG_formal_parameter
25# DWARF-NEXT: DW_AT_location
26# DWARF-NEXT: [0x0000000000000000, 0x0000000000000010): DW_OP_breg0 W0+0
27# DWARF-NEXT: [0x0000000000000010, 0x000000000000001c): DW_OP_entry_value(DW_OP_reg0 W0))
28# DWARF-NEXT: DW_AT_name    ("f")
29
30--- |
31  target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
32  target triple = "arm64-apple-ios10.0.0"
33
34  %struct.fat_ptr = type { i32*, i32*, i32* }
35
36  define i32 @bar(%struct.fat_ptr* nocapture readonly %f) local_unnamed_addr !dbg !13 {
37  entry:
38    call void @llvm.dbg.declare(metadata %struct.fat_ptr* %f, metadata !23, metadata !DIExpression()), !dbg !24
39    %ptr2 = bitcast %struct.fat_ptr* %f to i32**, !dbg !25
40    %0 = load i32*, i32** %ptr2, align 8, !dbg !25
41    %1 = load i32, i32* %0, align 4, !dbg !31
42    %call = tail call i32 @baz(i32 %1), !dbg !34
43    %call1 = tail call i32 @baz(i32 %call), !dbg !35
44    ret i32 %call1, !dbg !36
45  }
46
47  declare void @llvm.dbg.declare(metadata, metadata, metadata)
48
49  declare !dbg !4 i32 @baz(i32) local_unnamed_addr optsize
50
51  !llvm.dbg.cu = !{!0}
52  !llvm.module.flags = !{!8, !9, !10, !11}
53  !llvm.ident = !{!12}
54
55  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None, sysroot: "/")
56  !1 = !DIFile(filename: "indirect.c", directory: "/tmp/fatptr")
57  !2 = !{}
58  !3 = !{!4}
59  !4 = !DISubprogram(name: "baz", scope: !1, file: !1, line: 4, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
60  !5 = !DISubroutineType(types: !6)
61  !6 = !{!7, !7}
62  !7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
63  !8 = !{i32 7, !"Dwarf Version", i32 4}
64  !9 = !{i32 2, !"Debug Info Version", i32 3}
65  !10 = !{i32 1, !"wchar_size", i32 4}
66  !11 = !{i32 7, !"PIC Level", i32 2}
67  !12 = !{!"clang"}
68  !13 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !14, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !22)
69  !14 = !DISubroutineType(types: !15)
70  !15 = !{!7, !16}
71  !16 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "fat_ptr", file: !1, line: 1, size: 192, elements: !17)
72  !17 = !{!18, !20, !21}
73  !18 = !DIDerivedType(tag: DW_TAG_member, name: "ptr", scope: !16, file: !1, line: 2, baseType: !19, size: 64)
74  !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
75  !20 = !DIDerivedType(tag: DW_TAG_member, name: "low", scope: !16, file: !1, line: 2, baseType: !19, size: 64, offset: 64)
76  !21 = !DIDerivedType(tag: DW_TAG_member, name: "high", scope: !16, file: !1, line: 2, baseType: !19, size: 64, offset: 128)
77  !22 = !{!23}
78  !23 = !DILocalVariable(name: "f", arg: 1, scope: !13, file: !1, line: 5, type: !16)
79  !24 = !DILocation(line: 5, column: 24, scope: !13)
80  !25 = !DILocation(line: 6, column: 23, scope: !13)
81  !31 = !DILocation(line: 6, column: 20, scope: !13)
82  !34 = !DILocation(line: 6, column: 16, scope: !13)
83  !35 = !DILocation(line: 6, column: 12, scope: !13)
84  !36 = !DILocation(line: 6, column: 5, scope: !13)
85
86...
87---
88name:            bar
89stack:
90  - { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
91      stack-id: default, callee-saved-register: '$lr', callee-saved-restored: true,
92      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
93  - { id: 1, name: '', type: spill-slot, offset: -16, size: 8, alignment: 8,
94      stack-id: default, callee-saved-register: '$fp', callee-saved-restored: true,
95      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
96callSites:
97  - { bb: 0, offset: 8, fwdArgRegs:
98      - { arg: 0, reg: '$w0' } }
99  - { bb: 0, offset: 10, fwdArgRegs:
100      - { arg: 0, reg: '$w0' } }
101body:             |
102  bb.0.entry:
103    liveins: $x0, $lr
104
105    DBG_VALUE $x0, 0, !23, !DIExpression(), debug-location !24
106    early-clobber $sp = frame-setup STPXpre killed $fp, killed $lr, $sp, -2 :: (store 8 into %stack.1), (store 8 into %stack.0)
107    $fp = frame-setup ADDXri $sp, 0, 0
108    frame-setup CFI_INSTRUCTION def_cfa $w29, 16
109    frame-setup CFI_INSTRUCTION offset $w30, -8, debug-location !25
110    frame-setup CFI_INSTRUCTION offset $w29, -16, debug-location !25
111    renamable $x8 = LDRXui killed renamable $x0, 0, debug-location !25 :: (load 8 from %ir.ptr2)
112    renamable $w0 = LDRWui killed renamable $x8, 0, debug-location !31 :: (load 4 from %ir.0)
113    BL @baz, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0, debug-location !34
114    early-clobber $sp, $fp, $lr = frame-destroy LDPXpost $sp, 2, debug-location !35 :: (load 8 from %stack.1), (load 8 from %stack.0)
115    TCRETURNdi @baz, 0, csr_aarch64_aapcs, implicit $sp, implicit $w0, debug-location !35
116
117...
118