xref: /llvm-project/llvm/test/Transforms/SafeStack/X86/debug-loc-dynamic.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 dynamic allocas moved onto the unsafe stack.
7; In the dynamic alloca case, the dbg.value does not change with the exception
8; of the alloca pointer in the first argument being replaced with the new stack
9; top address.
10
11target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
12target triple = "x86_64-unknown-linux-gnu"
13
14define void @f(i32 %n) safestack !dbg !6 {
15entry:
16  tail call void @llvm.dbg.value(metadata i32 %n, metadata !11, metadata !14), !dbg !15
17  %0 = zext i32 %n to i64, !dbg !16
18
19; CHECK:  store ptr %[[VLA:.*]], ptr @__safestack_unsafe_stack_ptr
20; CHECK:  #dbg_value(ptr %[[VLA]], ![[TYPE:.*]], !DIExpression(DW_OP_deref),
21; CHECK:  call void @capture({{.*}} %[[VLA]])
22
23  %vla = alloca i8, i64 %0, align 16, !dbg !16
24  tail call void @llvm.dbg.value(metadata ptr %vla, metadata !12, metadata !17), !dbg !18
25  call void @capture(ptr nonnull %vla), !dbg !19
26  ret void, !dbg !20
27}
28
29declare void @capture(ptr)
30declare void @llvm.dbg.value(metadata, metadata, metadata)
31
32!llvm.dbg.cu = !{!0}
33!llvm.module.flags = !{!3, !4}
34!llvm.ident = !{!5}
35
36!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 272832) (llvm/trunk 272831)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
37!1 = !DIFile(filename: "../llvm/1.cc", directory: "/code/build-llvm")
38!2 = !{}
39!3 = !{i32 2, !"Dwarf Version", i32 4}
40!4 = !{i32 2, !"Debug Info Version", i32 3}
41!5 = !{!"clang version 3.9.0 (trunk 272832) (llvm/trunk 272831)"}
42!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fi", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !10)
43!7 = !DISubroutineType(types: !8)
44!8 = !{null, !9}
45!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
46!10 = !{!11, !12}
47!11 = !DILocalVariable(name: "n", arg: 1, scope: !6, file: !1, line: 2, type: !9)
48
49; CHECK-DAG: ![[TYPE]] = !DILocalVariable(name: "x",
50!12 = !DILocalVariable(name: "x", scope: !6, file: !1, line: 3, type: !13)
51!13 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
52!14 = !DIExpression()
53!15 = !DILocation(line: 2, column: 12, scope: !6)
54!16 = !DILocation(line: 3, column: 3, scope: !6)
55
56!17 = !DIExpression(DW_OP_deref)
57!18 = !DILocation(line: 3, column: 8, scope: !6)
58!19 = !DILocation(line: 4, column: 3, scope: !6)
59!20 = !DILocation(line: 5, column: 1, scope: !6)
60