1# RUN: llc %s -o - -run-pass=livedebugvalues \ 2# RUN: -experimental-debug-variable-locations \ 3# RUN: | FileCheck %s 4# 5## Copy of DebugInfo/COFF/types-array-advanced.ll, altered to test its behaviour 6## in MIR when fed to LiveDebugValues. The matter of interest is that on win32, 7## calls to _chkstk will modify $esp, where we would normally ignore defs of the 8## stack pointer on calls. 9## 10## Check that on win32, for this specific symbol, when the stack is adjusted, 11## that we track the modified $esp from _chkstk like any other value in 12## LiveDebugValues, where it can be recovered after a clobber or moved around. 13## Check lines written inline. 14--- | 15 target datalayout = "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:32-n8:16:32-a:0:32-S32" 16 target triple = "i686-pc-windows-msvc18.0.31101" 17 18 %struct.incomplete_struct = type { i32 } 19 20 @"\01?multi_dim_arr@@3PAY146DA" = global [2 x [5 x [7 x i8]]] zeroinitializer, align 1, !dbg !0 21 @"\01?p_incomplete_struct_arr@@3PAY02Uincomplete_struct@@A" = global ptr null, align 4, !dbg !6 22 @"\01?incomplete_struct_arr@@3PAUincomplete_struct@@A" = global [3 x %struct.incomplete_struct] zeroinitializer, align 4, !dbg !16 23 @"\01?typedef_arr@@3SDHD" = constant [4 x i32] zeroinitializer, align 4, !dbg !18 24 25 define void @"\01?foo@@YAXH@Z"(i32 %x) !dbg !35 { 26 entry: 27 %x.addr = alloca i32, align 4 28 %saved_stack = alloca ptr, align 4 29 store i32 %x, ptr %x.addr, align 4 30 call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !38, metadata !DIExpression()), !dbg !39 31 %0 = load i32, ptr %x.addr, align 4, !dbg !40 32 %1 = call ptr @llvm.stacksave(), !dbg !41 33 store ptr %1, ptr %saved_stack, align 4, !dbg !41 34 %vla = alloca i32, i32 %0, align 4, !dbg !41 35 call void @llvm.dbg.declare(metadata ptr %vla, metadata !42, metadata !DIExpression(DW_OP_deref)), !dbg !46 36 %arrayidx1 = bitcast ptr %vla to ptr, !dbg !47 37 store i32 0, ptr %arrayidx1, align 4, !dbg !48 38 %2 = load ptr, ptr %saved_stack, align 4, !dbg !49 39 call void @llvm.stackrestore(ptr %2), !dbg !49 40 ret void, !dbg !49 41 } 42 43 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 44 declare void @llvm.dbg.declare(metadata, metadata, metadata) 45 46 ; Function Attrs: nofree nosync nounwind willreturn 47 declare ptr @llvm.stacksave() 48 49 ; Function Attrs: nofree nosync nounwind willreturn 50 declare void @llvm.stackrestore(ptr) 51 52 !llvm.dbg.cu = !{!2} 53 !llvm.module.flags = !{!32, !33} 54 !llvm.ident = !{!34} 55 56 !0 = distinct !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 57 !1 = !DIGlobalVariable(name: "multi_dim_arr", linkageName: "\01?multi_dim_arr@@3PAY146DA", scope: !2, file: !3, line: 1, type: !26, isLocal: false, isDefinition: true) 58 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.9.0 (trunk 273874)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) 59 !3 = !DIFile(filename: "t.cpp", directory: "/") 60 !4 = !{} 61 !5 = !{!0, !6, !16, !18} 62 !6 = distinct !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 63 !7 = !DIGlobalVariable(name: "p_incomplete_struct_arr", linkageName: "\01?p_incomplete_struct_arr@@3PAY02Uincomplete_struct@@A", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true) 64 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 32, align: 32) 65 !9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, elements: !14) 66 !10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete_struct", file: !3, line: 4, size: 32, align: 32, elements: !11, identifier: ".?AUincomplete_struct@@") 67 !11 = !{!12} 68 !12 = !DIDerivedType(tag: DW_TAG_member, name: "s1", scope: !10, file: !3, line: 5, baseType: !13, size: 32, align: 32) 69 !13 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 70 !14 = !{!15} 71 !15 = !DISubrange(count: 3) 72 !16 = distinct !DIGlobalVariableExpression(var: !17, expr: !DIExpression()) 73 !17 = !DIGlobalVariable(name: "incomplete_struct_arr", linkageName: "\01?incomplete_struct_arr@@3PAUincomplete_struct@@A", scope: !2, file: !3, line: 6, type: !9, isLocal: false, isDefinition: true) 74 !18 = distinct !DIGlobalVariableExpression(var: !19, expr: !DIExpression()) 75 !19 = !DIGlobalVariable(name: "typedef_arr", linkageName: "\01?typedef_arr@@3SDHD", scope: !2, file: !3, line: 14, type: !20, isLocal: false, isDefinition: true) 76 !20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !21, size: 128, align: 32, elements: !24) 77 !21 = !DIDerivedType(tag: DW_TAG_typedef, name: "T_INT", file: !3, line: 13, baseType: !22) 78 !22 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !23) 79 !23 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13) 80 !24 = !{!25} 81 !25 = !DISubrange(count: 4) 82 !26 = !DICompositeType(tag: DW_TAG_array_type, baseType: !27, size: 560, align: 8, elements: !28) 83 !27 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) 84 !28 = !{!29, !30, !31} 85 !29 = !DISubrange(count: 2) 86 !30 = !DISubrange(count: 5) 87 !31 = !DISubrange(count: 7) 88 !32 = !{i32 2, !"CodeView", i32 1} 89 !33 = !{i32 2, !"Debug Info Version", i32 3} 90 !34 = !{!"clang version 3.9.0 (trunk 273874)"} 91 !35 = distinct !DISubprogram(name: "foo", linkageName: "\01?foo@@YAXH@Z", scope: !3, file: !3, line: 8, type: !36, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4) 92 !36 = !DISubroutineType(types: !37) 93 !37 = !{null, !13} 94 !38 = !DILocalVariable(name: "x", arg: 1, scope: !35, file: !3, line: 8, type: !13) 95 !39 = !DILocation(line: 8, column: 14, scope: !35) 96 !40 = !DILocation(line: 9, column: 21, scope: !35) 97 !41 = !DILocation(line: 9, column: 4, scope: !35) 98 !42 = !DILocalVariable(name: "dyn_size_arr", scope: !35, file: !3, line: 9, type: !43) 99 !43 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, align: 32, elements: !44) 100 !44 = !{!45} 101 !45 = !DISubrange(count: -1) 102 !46 = !DILocation(line: 9, column: 8, scope: !35) 103 !47 = !DILocation(line: 10, column: 4, scope: !35) 104 !48 = !DILocation(line: 10, column: 20, scope: !35) 105 !49 = !DILocation(line: 11, column: 1, scope: !35) 106 107... 108--- 109name: "\x01?foo@@YAXH@Z" 110alignment: 16 111tracksRegLiveness: true 112debugInstrRef: true 113hasWinCFI: true 114frameInfo: 115 stackSize: 8 116 offsetAdjustment: -8 117 maxAlignment: 4 118 adjustsStack: true 119 maxCallFrameSize: 0 120fixedStack: 121 - { id: 0, type: spill-slot, offset: -8, size: 4, alignment: 4 } 122 - { id: 1, size: 4, alignment: 4, debug-info-variable: '!38', debug-info-expression: '!DIExpression()', 123 debug-info-location: '!39' } 124stack: 125 - { id: 1, name: saved_stack, offset: -12, size: 4, alignment: 4 } 126 - { id: 2, name: vla, type: variable-sized, offset: -12, alignment: 1 } 127machineFunctionInfo: {} 128body: | 129 bb.0.entry: 130 frame-setup PUSH32r killed $ebp, implicit-def $esp, implicit $esp 131 CFI_INSTRUCTION def_cfa_offset 8 132 CFI_INSTRUCTION offset $ebp, -8 133 frame-setup SEH_PushReg 23 134 $ebp = frame-setup MOV32rr $esp 135 CFI_INSTRUCTION def_cfa_register $ebp 136 frame-setup SEH_SetFrame 23, 0 137 frame-setup PUSH32r undef $eax, implicit-def $esp, implicit $esp 138 frame-setup SEH_StackAlloc 4 139 frame-setup SEH_EndPrologue 140 renamable $eax = MOV32rm $ebp, 1, $noreg, 8, $noreg, debug-location !40 :: (dereferenceable load (s32) from %ir.x.addr) 141 MOV32mr $ebp, 1, $noreg, -4, $noreg, $esp, debug-location !41 :: (store (s32) into %ir.saved_stack) 142 renamable $eax = SHL32ri killed renamable $eax, 2, implicit-def dead $eflags, debug-location !41 143 CALLpcrel32 &_chkstk, implicit $esp, implicit $ssp, implicit $eax, implicit $esp, implicit-def dead $eax, implicit-def $esp, implicit-def dead $eflags, debug-instr-number 2, debug-location !41 144 $ebx = MOV32rr $esp, debug-location !41 145 $eax = MOV32ri 0 146 DBG_INSTR_REF !42, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(2, 6), debug-location !46 147 ; CHECK-LABEL: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 6) 148 ; CHECK: DBG_VALUE_LIST {{.+}}, $esp 149 150 ;; Variable value is $esp / $ebx, will be based on $esp initially. We'll now 151 ;; allocate more stack space, and several things should happen: 152 ;; * We recognise it as modifying $esp, and move the variable location to 153 ;; be based on $ebx, 154 ;; * We recognise the modified $esp as a new value, and if we assign it to 155 ;; the variable location, will base the variable on $esp, 156 ;; * Clobbering the second modified $esp won't re-locate the variable to 157 ;; $ebx, which comes from the first modified $esp. 158 CALLpcrel32 &_chkstk, implicit $esp, implicit $ssp, implicit $eax, implicit $esp, implicit-def dead $eax, implicit-def $esp, implicit-def dead $eflags, debug-instr-number 3, debug-location !41 159 ; CHECK-NEXT: CALLpcrel32 160 ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $ebx 161 162 DBG_INSTR_REF !42, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(3, 6), debug-location !46 163 ; CHECK-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 6) 164 ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $esp 165 166 $esp = ADD32ri killed $esp, 0, implicit-def dead $eflags 167 ; CHECK-NEXT: ADD32ri 168 169 DBG_INSTR_REF !42, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(3, 6), debug-location !46 170 ; CHECK-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 6) 171 ; CHECK-NEXT: DBG_VALUE_LIST {{.+}}, $noreg 172 173 $esp = MOV32rr $ebp, debug-location !49 174 $ebp = frame-destroy POP32r implicit-def $esp, implicit $esp, debug-location !49 175 RET32 debug-location !49 176 177... 178