Compiler projects using llvm
# RUN: llc -o - %s -start-after=patchable-function -O0 -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
# Test dwarf codegen of DW_OP_minus.
#
# This was built by compiling the following source with SafeStack and
# simplifying the result a little.
# extern "C" {
# void Capture(int *);
# void f() {
#   int buf[100];
#   Capture(buf);
# }
# }
# The interesting part is !DIExpression(DW_OP_constu, 400, DW_OP_minus)
#
# RCX - 400
# CHECK:      .short    3                       # Loc expr size
# CHECK-NEXT: .byte     114                     # DW_OP_breg2
# CHECK-NEXT: .byte     240                     # -400
# CHECK-NEXT: .byte     124
#
# RCX is clobbered in call @Capture, but there is a spilled copy.
# *(RSP + 8) - 400
# CHECK:      .short    7                       # Loc expr size
# CHECK-NEXT: .byte     119                     # DW_OP_breg7
# CHECK-NEXT: .byte     8                       # 8
# CHECK-NEXT: .byte     6                       # DW_OP_deref
# CHECK-NEXT: .byte     16                      # DW_OP_constu
# CHECK-NEXT: .byte     144                     # 400
# CHECK-NEXT: .byte     3                       #
# CHECK-NEXT: .byte     28                      # DW_OP_minus
--- |
  @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global i8*
  
  define void @f() !dbg !5 {
  entry:
    %unsafe_stack_ptr = load i8*, i8** @__safestack_unsafe_stack_ptr
    %unsafe_stack_static_top = getelementptr i8, i8* %unsafe_stack_ptr, i32 -400
    store i8* %unsafe_stack_static_top, i8** @__safestack_unsafe_stack_ptr
    %0 = getelementptr i8, i8* %unsafe_stack_ptr, i32 -400
    %buf = bitcast i8* %0 to [100 x i32]*
    %1 = bitcast [100 x i32]* %buf to i8*, !dbg !14
    call void @llvm.dbg.declare(metadata i8* %unsafe_stack_ptr, metadata !9, metadata !DIExpression(DW_OP_constu, 400, DW_OP_minus)), !dbg !15
    %arraydecay = getelementptr inbounds [100 x i32], [100 x i32]* %buf, i64 0, i64 0, !dbg !16
    call void @Capture(i32* %arraydecay), !dbg !17
    store i8* %unsafe_stack_ptr, i8** @__safestack_unsafe_stack_ptr, !dbg !18
    ret void, !dbg !18
  }
  
  ; Function Attrs: nounwind readnone speculatable
  declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
  
  declare void @Capture(i32*)
  
  ; Function Attrs: nounwind
  declare void @llvm.stackprotector(i8*, i8**) #1
  
  attributes #0 = { nounwind readnone speculatable }
  attributes #1 = { nounwind }
  
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!3, !4}
  
  !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)
  !1 = !DIFile(filename: "1.cc", directory: "/tmp")
  !2 = !{}
  !3 = !{i32 2, !"Dwarf Version", i32 4}
  !4 = !{i32 2, !"Debug Info Version", i32 3}
  !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)
  !6 = !DISubroutineType(types: !7)
  !7 = !{null}
  !8 = !{!9}
  !9 = !DILocalVariable(name: "buf", scope: !5, file: !1, line: 5, type: !10)
  !10 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 3200, align: 32, elements: !12)
  !11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
  !12 = !{!13}
  !13 = !DISubrange(count: 100)
  !14 = !DILocation(line: 5, column: 3, scope: !5)
  !15 = !DILocation(line: 5, column: 7, scope: !5)
  !16 = !DILocation(line: 6, column: 11, scope: !5)
  !17 = !DILocation(line: 6, column: 3, scope: !5)
  !18 = !DILocation(line: 7, column: 1, scope: !5)

...
---
name:            f
alignment:       16
tracksRegLiveness: true
frameInfo:       
  stackSize:       24
  maxAlignment:    8
  adjustsStack:    true
  hasCalls:        true
  maxCallFrameSize: 0
stack:           
  - { id: 0, type: spill-slot, offset: -16, size: 8, alignment: 8, stack-id: default }
  - { id: 1, type: spill-slot, offset: -24, size: 8, alignment: 8, stack-id: default }
body:             |
  bb.0.entry:
    $rsp = frame-setup SUB64ri8 $rsp, 24, implicit-def dead $eflags
    CFI_INSTRUCTION def_cfa_offset 32
    renamable $rax = MOV64rm $rip, 1, $noreg, target-flags(x86-gottpoff) @__safestack_unsafe_stack_ptr, $noreg :: (load (s64) from got)
    renamable $rcx = MOV64rm renamable $rax, 1, $noreg, 0, $fs :: (dereferenceable load (s64) from @__safestack_unsafe_stack_ptr)
    DBG_VALUE renamable $rcx, 0, !9, !DIExpression(DW_OP_constu, 400, DW_OP_minus), debug-location !15
    $rdx = MOV64rr $rcx
    renamable $rdx = ADD64ri32 renamable $rdx, -400, implicit-def dead $eflags
    MOV64mr renamable $rax, 1, $noreg, 0, $fs, renamable $rdx :: (store (s64) into @__safestack_unsafe_stack_ptr)
    $rdi = MOV64rr killed $rdx, debug-location !17
    MOV64mr $rsp, 1, $noreg, 16, $noreg, killed $rax :: (store (s64) into %stack.0)
    MOV64mr $rsp, 1, $noreg, 8, $noreg, killed $rcx :: (store (s64) into %stack.1)
    DBG_VALUE $rsp, 0, !9, !DIExpression(DW_OP_plus_uconst, 8, DW_OP_deref, DW_OP_constu, 400, DW_OP_minus), debug-location !15
    CALL64pcrel32 @Capture, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp, debug-location !17
    $rax = MOV64rm $rsp, 1, $noreg, 16, $noreg :: (load (s64) from %stack.0)
    $rcx = MOV64rm $rsp, 1, $noreg, 8, $noreg :: (load (s64) from %stack.1)
    MOV64mr killed renamable $rax, 1, $noreg, 0, $fs, killed renamable $rcx, debug-location !18 :: (store (s64) into @__safestack_unsafe_stack_ptr)
    $rsp = frame-destroy ADD64ri8 $rsp, 24, implicit-def dead $eflags, debug-location !18
    CFI_INSTRUCTION def_cfa_offset 8, debug-location !18
    RET64 debug-location !18

...