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.
4 # This was built by compiling the following source with SafeStack and
5 # simplifying the result a little.
13 # The interesting part is !DIExpression(DW_OP_constu, 400, DW_OP_minus)
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
21 # RCX is clobbered in call @Capture, but there is a spilled copy.
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
32 @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global i8*
34 define void @f() !dbg !5 {
36 %unsafe_stack_ptr = load i8*, i8** @__safestack_unsafe_stack_ptr
37 %unsafe_stack_static_top = getelementptr i8, i8* %unsafe_stack_ptr, i32 -400
38 store i8* %unsafe_stack_static_top, i8** @__safestack_unsafe_stack_ptr
39 %0 = getelementptr i8, i8* %unsafe_stack_ptr, i32 -400
40 %buf = bitcast i8* %0 to [100 x i32]*
41 %1 = bitcast [100 x i32]* %buf to i8*, !dbg !14
42 call void @llvm.dbg.declare(metadata i8* %unsafe_stack_ptr, metadata !9, metadata !DIExpression(DW_OP_constu, 400, DW_OP_minus)), !dbg !15
43 %arraydecay = getelementptr inbounds [100 x i32], [100 x i32]* %buf, i64 0, i64 0, !dbg !16
44 call void @Capture(i32* %arraydecay), !dbg !17
45 store i8* %unsafe_stack_ptr, i8** @__safestack_unsafe_stack_ptr, !dbg !18
49 ; Function Attrs: nounwind readnone speculatable
50 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
52 declare void @Capture(i32*)
54 ; Function Attrs: nounwind
55 declare void @llvm.stackprotector(i8*, i8**) #1
57 attributes #0 = { nounwind readnone speculatable }
58 attributes #1 = { nounwind }
61 !llvm.module.flags = !{!3, !4}
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")
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)
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)
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)
87 tracksRegLiveness: true
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 }
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 8 from got)
102 renamable $rcx = MOV64rm renamable $rax, 1, $noreg, 0, $fs :: (dereferenceable load 8 from @__safestack_unsafe_stack_ptr)
103 DBG_VALUE renamable $rcx, 0, !9, !DIExpression(DW_OP_constu, 400, DW_OP_minus), debug-location !15
105 renamable $rdx = ADD64ri32 renamable $rdx, -400, implicit-def dead $eflags
106 MOV64mr renamable $rax, 1, $noreg, 0, $fs, renamable $rdx :: (store 8 into @__safestack_unsafe_stack_ptr)
107 $rdi = MOV64rr killed $rdx, debug-location !17
108 MOV64mr $rsp, 1, $noreg, 16, $noreg, killed $rax :: (store 8 into %stack.0)
109 MOV64mr $rsp, 1, $noreg, 8, $noreg, killed $rcx :: (store 8 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 8 from %stack.0)
113 $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load 8 from %stack.1)
114 MOV64mr killed renamable $rax, 1, $noreg, 0, $fs, killed renamable $rcx, debug-location !18 :: (store 8 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 RETQ debug-location !18