1*9880d681SAndroid Build Coastguard Worker; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s 2*9880d681SAndroid Build Coastguard Worker 3*9880d681SAndroid Build Coastguard Worker; Test debug location for the local variables moved onto the unsafe stack. 4*9880d681SAndroid Build Coastguard Worker 5*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 6*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu" 7*9880d681SAndroid Build Coastguard Worker 8*9880d681SAndroid Build Coastguard Worker%struct.S = type { [100 x i8] } 9*9880d681SAndroid Build Coastguard Worker 10*9880d681SAndroid Build Coastguard Worker; Function Attrs: safestack uwtable 11*9880d681SAndroid Build Coastguard Workerdefine void @f(%struct.S* byval align 8 %zzz) #0 !dbg !12 { 12*9880d681SAndroid Build Coastguard Worker; CHECK: define void @f 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Workerentry: 15*9880d681SAndroid Build Coastguard Worker; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker %xxx = alloca %struct.S, align 1 18*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.declare(metadata %struct.S* %zzz, metadata !18, metadata !19), !dbg !20 19*9880d681SAndroid Build Coastguard Worker call void @llvm.dbg.declare(metadata %struct.S* %xxx, metadata !21, metadata !19), !dbg !22 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker; dbg.declare for %zzz and %xxx are gone; replaced with dbg.declare based off the unsafe stack pointer 22*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @llvm.dbg.declare 23*9880d681SAndroid Build Coastguard Worker; CHECK: call void @llvm.dbg.declare(metadata i8* %[[USP]], metadata ![[VAR_ARG:.*]], metadata ![[EXPR_ARG:.*]]) 24*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @llvm.dbg.declare 25*9880d681SAndroid Build Coastguard Worker; CHECK: call void @llvm.dbg.declare(metadata i8* %[[USP]], metadata ![[VAR_LOCAL:.*]], metadata ![[EXPR_LOCAL:.*]]) 26*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: call void @llvm.dbg.declare 27*9880d681SAndroid Build Coastguard Worker 28*9880d681SAndroid Build Coastguard Worker call void @Capture(%struct.S* %zzz), !dbg !23 29*9880d681SAndroid Build Coastguard Worker call void @Capture(%struct.S* %xxx), !dbg !24 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker; dbg.declare appears before the first use 32*9880d681SAndroid Build Coastguard Worker; CHECK: call void @Capture 33*9880d681SAndroid Build Coastguard Worker; CHECK: call void @Capture 34*9880d681SAndroid Build Coastguard Worker 35*9880d681SAndroid Build Coastguard Worker ret void, !dbg !25 36*9880d681SAndroid Build Coastguard Worker} 37*9880d681SAndroid Build Coastguard Worker 38*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[VAR_ARG]] = !DILocalVariable(name: "zzz" 39*9880d681SAndroid Build Coastguard Worker; 100 aligned up to 8 40*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[EXPR_ARG]] = !DIExpression(DW_OP_deref, DW_OP_minus, 104 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[VAR_LOCAL]] = !DILocalVariable(name: "xxx" 43*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: ![[EXPR_LOCAL]] = !DIExpression(DW_OP_deref, DW_OP_minus, 208 44*9880d681SAndroid Build Coastguard Worker 45*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone 46*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Workerdeclare void @Capture(%struct.S*) #2 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Workerattributes #0 = { safestack uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 51*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone } 52*9880d681SAndroid Build Coastguard Workerattributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" } 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0} 55*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!15, !16} 56*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!17} 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 254019) (llvm/trunk 254036)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3) 59*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "../llvm/2.cc", directory: "/code/build-llvm") 60*9880d681SAndroid Build Coastguard Worker!2 = !{} 61*9880d681SAndroid Build Coastguard Worker!3 = !{!4} 62*9880d681SAndroid Build Coastguard Worker!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 4, size: 800, align: 8, elements: !5, identifier: "_ZTS1S") 63*9880d681SAndroid Build Coastguard Worker!5 = !{!6} 64*9880d681SAndroid Build Coastguard Worker!6 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !4, file: !1, line: 5, baseType: !7, size: 800, align: 8) 65*9880d681SAndroid Build Coastguard Worker!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 800, align: 8, elements: !9) 66*9880d681SAndroid Build Coastguard Worker!8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) 67*9880d681SAndroid Build Coastguard Worker!9 = !{!10} 68*9880d681SAndroid Build Coastguard Worker!10 = !DISubrange(count: 100) 69*9880d681SAndroid Build Coastguard Worker!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1f1S", scope: !1, file: !1, line: 10, type: !13, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) 70*9880d681SAndroid Build Coastguard Worker!13 = !DISubroutineType(types: !14) 71*9880d681SAndroid Build Coastguard Worker!14 = !{null, !4} 72*9880d681SAndroid Build Coastguard Worker!15 = !{i32 2, !"Dwarf Version", i32 4} 73*9880d681SAndroid Build Coastguard Worker!16 = !{i32 2, !"Debug Info Version", i32 3} 74*9880d681SAndroid Build Coastguard Worker!17 = !{!"clang version 3.8.0 (trunk 254019) (llvm/trunk 254036)"} 75*9880d681SAndroid Build Coastguard Worker!18 = !DILocalVariable(name: "zzz", arg: 1, scope: !12, file: !1, line: 10, type: !4) 76*9880d681SAndroid Build Coastguard Worker!19 = !DIExpression() 77*9880d681SAndroid Build Coastguard Worker!20 = !DILocation(line: 10, column: 10, scope: !12) 78*9880d681SAndroid Build Coastguard Worker!21 = !DILocalVariable(name: "xxx", scope: !12, file: !1, line: 11, type: !4) 79*9880d681SAndroid Build Coastguard Worker!22 = !DILocation(line: 11, column: 5, scope: !12) 80*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 12, column: 3, scope: !12) 81*9880d681SAndroid Build Coastguard Worker!24 = !DILocation(line: 13, column: 3, scope: !12) 82*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 14, column: 1, scope: !12) 83