1# RUN: llc -o - %s -start-after=patchable-function -O0 -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 2# Test dwarf codegen of DW_OP_minus. 3# 4# This was built by compiling the following source with SafeStack and 5# simplifying the result a little. 6# extern "C" { 7# void Capture(int *); 8# void f() { 9# int buf[100]; 10# Capture(buf); 11# } 12# } 13# The interesting part is !DIExpression(DW_OP_constu, 400, DW_OP_minus) 14# 15# RCX - 400 16# CHECK: .short 3 # Loc expr size 17# CHECK-NEXT: .byte 114 # DW_OP_breg2 18# CHECK-NEXT: .byte 240 # -400 19# CHECK-NEXT: .byte 124 20# 21# RCX is clobbered in call @Capture, but there is a spilled copy. 22# *(RSP + 8) - 400 23# CHECK: .short 7 # Loc expr size 24# CHECK-NEXT: .byte 119 # DW_OP_breg7 25# CHECK-NEXT: .byte 8 # 8 26# CHECK-NEXT: .byte 6 # DW_OP_deref 27# CHECK-NEXT: .byte 16 # DW_OP_constu 28# CHECK-NEXT: .byte 144 # 400 29# CHECK-NEXT: .byte 3 # 30# CHECK-NEXT: .byte 28 # DW_OP_minus 31--- | 32 @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global ptr 33 34 define void @f() !dbg !5 { 35 entry: 36 %unsafe_stack_ptr = load ptr, ptr @__safestack_unsafe_stack_ptr 37 %unsafe_stack_static_top = getelementptr i8, ptr %unsafe_stack_ptr, i32 -400 38 store ptr %unsafe_stack_static_top, ptr @__safestack_unsafe_stack_ptr 39 %0 = getelementptr i8, ptr %unsafe_stack_ptr, i32 -400 40 %buf = bitcast ptr %0 to ptr 41 %1 = bitcast ptr %buf to ptr, !dbg !14 42 call void @llvm.dbg.declare(metadata ptr %unsafe_stack_ptr, metadata !9, metadata !DIExpression(DW_OP_constu, 400, DW_OP_minus)), !dbg !15 43 %arraydecay = getelementptr inbounds [100 x i32], ptr %buf, i64 0, i64 0, !dbg !16 44 call void @Capture(ptr %arraydecay), !dbg !17 45 store ptr %unsafe_stack_ptr, ptr @__safestack_unsafe_stack_ptr, !dbg !18 46 ret void, !dbg !18 47 } 48 49 ; Function Attrs: nounwind readnone speculatable 50 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 51 52 declare void @Capture(ptr) 53 54 ; Function Attrs: nounwind 55 declare void @llvm.stackprotector(ptr, ptr) #1 56 57 attributes #0 = { nounwind readnone speculatable } 58 attributes #1 = { nounwind } 59 60 !llvm.dbg.cu = !{!0} 61 !llvm.module.flags = !{!3, !4} 62 63 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 248518) (llvm/trunk 248512)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 64 !1 = !DIFile(filename: "1.cc", directory: "/tmp") 65 !2 = !{} 66 !3 = !{i32 2, !"Dwarf Version", i32 4} 67 !4 = !{i32 2, !"Debug Info Version", i32 3} 68 !5 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 4, type: !6, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !8) 69 !6 = !DISubroutineType(types: !7) 70 !7 = !{null} 71 !8 = !{!9} 72 !9 = !DILocalVariable(name: "buf", scope: !5, file: !1, line: 5, type: !10) 73 !10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 3200, align: 32, elements: !12) 74 !11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 75 !12 = !{!13} 76 !13 = !DISubrange(count: 100) 77 !14 = !DILocation(line: 5, column: 3, scope: !5) 78 !15 = !DILocation(line: 5, column: 7, scope: !5) 79 !16 = !DILocation(line: 6, column: 11, scope: !5) 80 !17 = !DILocation(line: 6, column: 3, scope: !5) 81 !18 = !DILocation(line: 7, column: 1, scope: !5) 82 83... 84--- 85name: f 86alignment: 16 87tracksRegLiveness: true 88frameInfo: 89 stackSize: 24 90 maxAlignment: 8 91 adjustsStack: true 92 hasCalls: true 93 maxCallFrameSize: 0 94stack: 95 - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 8, stack-id: default } 96 - { id: 1, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default } 97body: | 98 bb.0.entry: 99 $rsp = frame-setup SUB64ri8 $rsp, 24, implicit-def dead $eflags 100 CFI_INSTRUCTION def_cfa_offset 32 101 renamable $rax = MOV64rm $rip, 1, $noreg, target-flags(x86-gottpoff) @__safestack_unsafe_stack_ptr, $noreg :: (load (s64) from got) 102 renamable $rcx = MOV64rm renamable $rax, 1, $noreg, 0, $fs :: (dereferenceable load (s64) from @__safestack_unsafe_stack_ptr) 103 DBG_VALUE renamable $rcx, 0, !9, !DIExpression(DW_OP_constu, 400, DW_OP_minus), debug-location !15 104 $rdx = MOV64rr $rcx 105 renamable $rdx = ADD64ri32 renamable $rdx, -400, implicit-def dead $eflags 106 MOV64mr renamable $rax, 1, $noreg, 0, $fs, renamable $rdx :: (store (s64) into @__safestack_unsafe_stack_ptr) 107 $rdi = MOV64rr killed $rdx, debug-location !17 108 MOV64mr $rsp, 1, $noreg, 16, $noreg, killed $rax :: (store (s64) into %stack.0) 109 MOV64mr $rsp, 1, $noreg, 8, $noreg, killed $rcx :: (store (s64) into %stack.1) 110 DBG_VALUE $rsp, 0, !9, !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref, DW_OP_constu, 400, DW_OP_minus), debug-location !15 111 CALL64pcrel32 @Capture, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp, debug-location !17 112 $rax = MOV64rm $rsp, 1, $noreg, 16, $noreg :: (load (s64) from %stack.0) 113 $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load (s64) from %stack.1) 114 MOV64mr killed renamable $rax, 1, $noreg, 0, $fs, killed renamable $rcx, debug-location !18 :: (store (s64) into @__safestack_unsafe_stack_ptr) 115 $rsp = frame-destroy ADD64ri8 $rsp, 24, implicit-def dead $eflags, debug-location !18 116 CFI_INSTRUCTION def_cfa_offset 8, debug-location !18 117 RET64 debug-location !18 118 119... 120