xref: /llvm-project/llvm/test/DebugInfo/X86/dbg_value_list_emission.mir (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1# RUN: llc %s --start-after=livedebugvalues -filetype=obj -o - \
2# RUN:     | llvm-dwarfdump - -name local* -regex \
3# RUN:     | FileCheck %s
4#
5# Test that we produce correct DWARF from DBG_VALUE_LIST instructions.
6# Comments and test directives inline.
7
8--- |
9  target triple = "x86_64-unknown-linux-gnu"
10  define dso_local i32 @fun() local_unnamed_addr !dbg !7 {
11  entry:
12    ret i32 0
13  }
14
15  !llvm.dbg.cu = !{!0}
16  !llvm.module.flags = !{!3, !4, !5}
17  !llvm.ident = !{!6}
18
19  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
20  !1 = !DIFile(filename: "example.c", directory: "/")
21  !2 = !{}
22  !3 = !{i32 7, !"Dwarf Version", i32 4}
23  !4 = !{i32 2, !"Debug Info Version", i32 3}
24  !5 = !{i32 1, !"wchar_size", i32 4}
25  !6 = !{!"clang version 11.0.0"}
26  !8 = !DISubroutineType(types: !9)
27  !9 = !{!10}
28  !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
29  !11 = !{!12, !13, !25}
30  !22 = !DISubroutineType(types: !23)
31  !23 = !{!10, !10}
32  ; --- Important metadata ---
33  !7 = distinct !DISubprogram(name: "fun", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
34  !15 = !DILocation(line: 1, column: 1, scope: !7)
35  !12 = !DILocalVariable(name: "locala", scope: !7, file: !1, line: 1, type: !10)
36  !13 = !DILocalVariable(name: "localb", scope: !7, file: !1, line: 2, type: !10)
37  !25 = !DILocalVariable(name: "localc", scope: !7, file: !1, line: 3, type: !10)
38  !26 = !DILocalVariable(name: "locald", scope: !7, file: !1, line: 4, type: !10)
39  !27 = !DILocalVariable(name: "locale", scope: !7, file: !1, line: 5, type: !10)
40  !28 = !DILocalVariable(name: "localf", scope: !7, file: !1, line: 6, type: !10)
41  !29 = !DILocalVariable(name: "localg", scope: !7, file: !1, line: 6, type: !10)
42  !30 = !DILocalVariable(name: "localh", scope: !7, file: !1, line: 6, type: !10)
43  !31 = !DILocalVariable(name: "locali", scope: !7, file: !1, line: 6, type: !10)
44
45...
46---
47name:            fun
48body:             |
49  bb.0.entry:
50    ; NOTE: By design, all DBG_VALUE_LIST instructions describe stack_value
51    ;       locations, so they are always created with a DW_OP_stack_value op.
52    ;
53    ; (1) Check a single reg arg works.
54    DBG_VALUE_LIST !12, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_stack_value), $eax, debug-location !15
55    ; CHECK:      DW_TAG_variable
56    ;  CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_stack_value)
57    ;  CHECK-NEXT:   DW_AT_name ("locala")
58
59    ; (2) Check multiple reg args work.
60    DBG_VALUE_LIST !13, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value), $eax, $edi, debug-location !15
61    ; CHECK:      DW_TAG_variable
62    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_breg5 RDI+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_plus, DW_OP_stack_value)
63    ; CHECK-NEXT:   DW_AT_name ("localb")
64
65    ; (3) Check that multiple references to one reg arg works.
66    DBG_VALUE_LIST !25, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 0, DW_OP_minus, DW_OP_stack_value), $eax, debug-location !15
67    ; CHECK:      DW_TAG_variable
68    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_minus, DW_OP_stack_value)
69    ; CHECK-NEXT:   DW_AT_name ("localc")
70
71    ; (4) Check constant and reg args work together.
72    DBG_VALUE_LIST !26, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_mul, DW_OP_stack_value), $eax, 5, debug-location !15
73    ; CHECK:      DW_TAG_variable
74    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_lit5, DW_OP_mul, DW_OP_stack_value)
75    ; CHECK-NEXT:   DW_AT_name ("locald")
76
77    ; (5) Check that arg deref works.
78    DBG_VALUE_LIST !27, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref, DW_OP_stack_value), $eax, debug-location !15
79    ; CHECK:      DW_TAG_variable
80    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_deref, DW_OP_stack_value)
81    ; CHECK-NEXT:   DW_AT_name ("locale")
82
83    ; (6) Check that fragments work.
84    DBG_VALUE_LIST !28, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 16), $eax, debug-location !15
85    ; CHECK:      DW_TAG_variable
86    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_stack_value, DW_OP_piece 0x2)
87    ; CHECK-NEXT:   DW_AT_name ("localf")
88
89    ; (7) Check that constant register offsets are correctly folded.
90    DBG_VALUE_LIST !29, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 5, DW_OP_LLVM_arg, 1, DW_OP_plus_uconst, 17, DW_OP_plus, DW_OP_stack_value), $eax, $edi, debug-location !15
91    ; CHECK:      DW_TAG_variable
92    ; CHECK-NEXT:   (DW_OP_breg0 RAX+5, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_breg5 RDI+17, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_plus, DW_OP_stack_value)
93    ; CHECK-NEXT:   DW_AT_name ("localg")
94
95    ; (8) Check that a single $noreg location invalidates the entire entry.
96    DBG_VALUE_LIST !30, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value), $eax, $noreg, debug-location !15
97    ; CHECK-NOT:   DW_AT_name ("localh")
98
99    ; (9) Check that relational operators work
100    DBG_VALUE_LIST !31, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_eq, DW_OP_LLVM_arg, 0, DW_OP_ne, DW_OP_LLVM_arg, 1, DW_OP_gt, DW_OP_LLVM_arg, 0, DW_OP_lt, DW_OP_LLVM_arg, 1, DW_OP_le, DW_OP_stack_value), $eax, $edi, debug-location !15
101    ; CHECK:      DW_TAG_variable
102    ; CHECK-NEXT:   (DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_breg5 RDI+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_eq, DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_ne, DW_OP_breg5 RDI+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_gt, DW_OP_breg0 RAX+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_lt, DW_OP_breg5 RDI+0, DW_OP_constu 0xffffffff, DW_OP_and, DW_OP_le, DW_OP_stack_value)
103    ; CHECK-NEXT:   DW_AT_name ("locali")
104
105
106    RET64 debug-location !15
107...
108