xref: /llvm-project/llvm/test/Transforms/SafeStack/X86/debug-loc2.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
2; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - --try-experimental-debuginfo-iterators | FileCheck %s
3; RUN: opt -passes=safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
4; RUN: opt -passes=safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - --try-experimental-debuginfo-iterators | FileCheck %s
5
6; Test llvm.dbg.value for the local variables moved onto the unsafe stack.
7; SafeStack rewrites them relative to the unsafe stack pointer (base address of
8; the unsafe stack frame).
9
10target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11target triple = "x86_64-unknown-linux-gnu"
12
13; Function Attrs: noinline safestack uwtable
14define void @f() #0 !dbg !6 {
15entry:
16; CHECK:   %[[USP:.*]] = load ptr, ptr @__safestack_unsafe_stack_ptr
17  %x1 = alloca i32, align 4
18  %x2 = alloca i32, align 4
19
20; Unhandled dbg.value: expression does not start with OP_DW_deref
21; CHECK: #dbg_value(ptr undef, !{{.*}}, !{{.*}})
22  tail call void @llvm.dbg.value(metadata ptr %x1, metadata !10, metadata !23), !dbg !16
23
24; Unhandled dbg.value: expression does not start with OP_DW_deref
25; CHECK: #dbg_value(ptr undef, !{{.*}}, !{{.*}})
26  tail call void @llvm.dbg.value(metadata ptr %x1, metadata !10, metadata !24), !dbg !16
27
28; Supported dbg.value: rewritted based on the [[USP]] value.
29; CHECK: #dbg_value(ptr %[[USP]], ![[X1:.*]], !DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref, DW_OP_LLVM_fragment, 0, 4),
30  tail call void @llvm.dbg.value(metadata ptr %x1, metadata !10, metadata !25), !dbg !16
31
32; Supported dbg.value: rewritted based on the [[USP]] value.
33; CHECK: #dbg_value(ptr %[[USP]], ![[X1:.*]], !DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref),
34  tail call void @llvm.dbg.value(metadata ptr %x1, metadata !10, metadata !15), !dbg !16
35  call void @capture(ptr nonnull %x1), !dbg !17
36
37; An extra non-dbg.value metadata use of %x2. Replaced with undef.
38; CHECK: call void @llvm.random.metadata.use(metadata ptr undef
39  call void @llvm.random.metadata.use(metadata ptr %x2)
40
41; CHECK: #dbg_value(ptr %[[USP]], ![[X2:.*]], !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_deref),
42  call void @llvm.dbg.value(metadata ptr %x2, metadata !12, metadata !15), !dbg !18
43  call void @capture(ptr nonnull %x2), !dbg !19
44  ret void, !dbg !20
45}
46
47; Function Attrs: argmemonly nounwind
48declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
49
50declare void @capture(ptr) #2
51
52; Function Attrs: argmemonly nounwind
53declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
54
55; Function Attrs: nounwind readnone
56declare void @llvm.dbg.value(metadata, metadata, metadata) #3
57
58declare void @llvm.random.metadata.use(metadata)
59
60attributes #0 = { noinline safestack uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
61attributes #1 = { argmemonly nounwind }
62attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
63attributes #3 = { nounwind readnone }
64attributes #4 = { nounwind }
65
66!llvm.dbg.cu = !{!0}
67!llvm.module.flags = !{!3, !4}
68!llvm.ident = !{!5}
69
70!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 271022) (llvm/trunk 271027)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
71!1 = !DIFile(filename: "../llvm/2.cc", directory: "/code/build-llvm")
72
73!2 = !{}
74!3 = !{i32 2, !"Dwarf Version", i32 4}
75!4 = !{i32 2, !"Debug Info Version", i32 3}
76!5 = !{!"clang version 3.9.0 (trunk 271022) (llvm/trunk 271027)"}
77!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !9)
78!7 = !DISubroutineType(types: !8)
79!8 = !{null}
80!9 = !{!10, !12}
81
82; CHECK-DAG: ![[X1]] = !DILocalVariable(name: "x1",
83!10 = !DILocalVariable(name: "x1", scope: !6, file: !1, line: 5, type: !11)
84!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
85
86; CHECK-DAG: ![[X2]] = !DILocalVariable(name: "x2",
87!12 = !DILocalVariable(name: "x2", scope: !6, file: !1, line: 6, type: !11)
88!13 = !DILocation(line: 5, column: 3, scope: !6)
89!14 = !DILocation(line: 6, column: 3, scope: !6)
90
91!15 = !DIExpression(DW_OP_deref)
92!16 = !DILocation(line: 5, column: 7, scope: !6)
93!17 = !DILocation(line: 8, column: 3, scope: !6)
94!18 = !DILocation(line: 6, column: 7, scope: !6)
95!19 = !DILocation(line: 9, column: 3, scope: !6)
96!20 = !DILocation(line: 10, column: 1, scope: !6)
97!21 = !DILocation(line: 10, column: 1, scope: !22)
98!22 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1)
99!23 = !DIExpression()
100!24 = !DIExpression(DW_OP_constu, 42, DW_OP_minus)
101!25 = !DIExpression(DW_OP_deref, DW_OP_LLVM_fragment, 0, 4)
102