xref: /llvm-project/llvm/test/DebugInfo/X86/single-location-inlined-param.mir (revision 3a05e01d1a76984fe1532bd237edbbb7ed9db6ea)
1# RUN: llc -start-after=livedebugvalues --filetype=obj %s -o - \
2# RUN:     | llvm-dwarfdump -v -name=param - | FileCheck %s
3#
4# Generated with opt -sroa -inline, llc -stop-after=livedebugvalues, with some
5# metadata removed by hand.
6#
7# int glob;
8# __attribute__((always_inline))
9# static void inline_me(int param) {
10#   {
11#     int local = param;
12#     glob = local;
13#   }
14# }
15# int fun(int number) {
16#   inline_me(number);
17#   if (number)
18#     return 0;
19#   return 1;
20# }
21#
22# The inlined parameter 'param' is available for the entirety of its enclosing
23# scope. We expect to see a single location entry despite the fact that the
24# final instruction in that scope belongs to a dominated scope.
25#
26# Except for 'param', all DILocalVariable metadata has been removed.
27#
28# Ignore first entry (abstract), we want to look at the concrete instance.
29# CHECK:       DW_TAG_formal_parameter [
30# CHECK:       DW_TAG_formal_parameter [
31# CHECK-NEXT:    DW_AT_location [DW_FORM_exprloc] (DW_OP_reg5 RDI)
32# CHECK-NEXT:    DW_AT_abstract_origin {{.*}} "param"
33
34--- |
35  target triple = "x86_64-unknown-linux-gnu"
36
37  @glob = dso_local global i32 0, align 4, !dbg !0
38  declare void @llvm.dbg.declare(metadata, metadata, metadata)
39  declare void @llvm.dbg.value(metadata, metadata, metadata)
40  define dso_local i32 @fun(i32 %number) !dbg !11 {
41  entry:
42    call void @llvm.dbg.value(metadata i32 %number, metadata !17, metadata !DIExpression()), !dbg !24
43    store i32 %number, ptr @glob, align 4, !dbg !27
44    %tobool = icmp ne i32 %number, 0, !dbg !32
45    br i1 %tobool, label %return, label %if.end, !dbg !34
46
47  if.end:                                           ; preds = %entry
48    br label %return, !dbg !35
49
50  return:                                           ; preds = %entry, %if.end
51    %retval.0 = phi i32 [ 1, %if.end ], [ 0, %entry ], !dbg !16
52    ret i32 %retval.0, !dbg !36
53  }
54
55  !llvm.dbg.cu = !{!2}
56  !llvm.module.flags = !{!7, !8, !9}
57  !llvm.ident = !{!10}
58
59  !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
60  !1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
61  !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
62  !3 = !DIFile(filename: "test.c", directory: "/")
63  !4 = !{}
64  !5 = !{!0}
65  !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
66  !7 = !{i32 7, !"Dwarf Version", i32 4}
67  !8 = !{i32 2, !"Debug Info Version", i32 3}
68  !9 = !{i32 1, !"wchar_size", i32 4}
69  !10 = !{!"clang version 11.0.0"}
70  !11 = distinct !DISubprogram(name: "fun", scope: !3, file: !3, line: 9, type: !12, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
71  !12 = !DISubroutineType(types: !13)
72  !13 = !{!6, !6}
73  !14 = !{}
74  !16 = !DILocation(line: 0, scope: !11)
75  !17 = !DILocalVariable(name: "param", arg: 1, scope: !18, file: !3, line: 3, type: !6)
76  !18 = distinct !DISubprogram(name: "inline_me", scope: !3, file: !3, line: 3, type: !19, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)
77  !19 = !DISubroutineType(types: !20)
78  !20 = !{null, !6}
79  !21 = !{!17}
80  !23 = distinct !DILexicalBlock(scope: !18, file: !3, line: 4, column: 3)
81  !24 = !DILocation(line: 0, scope: !18, inlinedAt: !25)
82  !25 = distinct !DILocation(line: 10, column: 3, scope: !11)
83  !26 = !DILocation(line: 0, scope: !23, inlinedAt: !25)
84  !27 = !DILocation(line: 6, column: 10, scope: !23, inlinedAt: !25)
85  !32 = !DILocation(line: 11, column: 7, scope: !33)
86  !33 = distinct !DILexicalBlock(scope: !11, file: !3, line: 11, column: 7)
87  !34 = !DILocation(line: 11, column: 7, scope: !11)
88  !35 = !DILocation(line: 13, column: 3, scope: !11)
89  !36 = !DILocation(line: 14, column: 1, scope: !11)
90
91...
92---
93name:            fun
94body:             |
95  bb.0.entry:
96    successors: %bb.2(0x50000000), %bb.1(0x30000000)
97    liveins: $edi
98
99    DBG_VALUE $edi, $noreg, !17, !DIExpression(), debug-location !24
100    MOV32mr $rip, 1, $noreg, @glob, $noreg, renamable $edi, debug-location !27 :: (store (s32) into @glob)
101    renamable $eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags
102    TEST32rr killed renamable $edi, renamable $edi, implicit-def $eflags, debug-location !32
103    JCC_1 %bb.1, 4, implicit $eflags, debug-location !34
104
105  bb.2.return:
106    liveins: $eax
107
108    RET64 $eax, debug-location !36
109
110  bb.1.if.end:
111    renamable $eax = MOV32ri 1
112    RET64 $eax, debug-location !36
113
114...
115