xref: /llvm-project/llvm/test/DebugInfo/X86/safestack-byval.ll (revision 5ee088134fb87f7d716c58fa65beb11fb6afcb22)
1; Test dwarf codegen for DILocalVariable of a byval function argument that
2; points to neither an argument nor an alloca. This kind of IR is generated by
3; SafeStack for unsafe byval arguments.
4; RUN: llc -mtriple=x86_64-unknown-unknown --experimental-debug-variable-locations=false -stop-after finalize-isel %s -o - | FileCheck %s --check-prefixes=CHECK,NORMAL
5; RUN: llc -mtriple=x86_64-unknown-unknown --experimental-debug-variable-locations -stop-after finalize-isel %s -o - | FileCheck %s --check-prefixes=CHECK,INSTRREF
6; RUN: llc --try-experimental-debuginfo-iterators -mtriple=x86_64-unknown-unknown --experimental-debug-variable-locations=false -stop-after finalize-isel %s -o - | FileCheck %s --check-prefixes=CHECK,NORMAL
7; RUN: llc --try-experimental-debuginfo-iterators -mtriple=x86_64-unknown-unknown --experimental-debug-variable-locations -stop-after finalize-isel %s -o - | FileCheck %s --check-prefixes=CHECK,INSTRREF
8
9; This was built by compiling the following source with SafeStack and
10; simplifying the result a little.
11; struct S {
12;   int a[100];
13; };
14;
15; int f(S zzz, unsigned long len) {
16;   return zzz.a[len];
17; }
18
19; CHECK:    ![[ZZZ:.*]] = !DILocalVariable(name: "zzz",
20; NORMAL:   DBG_VALUE {{.*}} ![[ZZZ]], !DIExpression(DW_OP_deref, DW_OP_constu, 400, DW_OP_minus)
21; INSTRREF: DBG_INSTR_REF ![[ZZZ]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref, DW_OP_constu, 400, DW_OP_minus, DW_OP_deref)
22
23%struct.S = type { [100 x i32] }
24
25@__safestack_unsafe_stack_ptr = external thread_local(initialexec) global ptr
26
27; Function Attrs: norecurse nounwind readonly safestack uwtable
28define i32 @_Z1f1Sm(ptr byval(%struct.S) nocapture readonly align 8 %zzz, i64 %len) #0 !dbg !12 {
29entry:
30  %unsafe_stack_ptr = load ptr, ptr @__safestack_unsafe_stack_ptr, !dbg !22
31  %unsafe_stack_static_top = getelementptr i8, ptr %unsafe_stack_ptr, i32 -400, !dbg !22
32  store ptr %unsafe_stack_static_top, ptr @__safestack_unsafe_stack_ptr, !dbg !22
33; !17 describes "zzz"
34  call void @llvm.dbg.declare(metadata ptr %unsafe_stack_ptr, metadata !17, metadata !23), !dbg !22
35  %0 = getelementptr i8, ptr %unsafe_stack_ptr, i32 -400, !dbg !22
36  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %zzz, i64 400, i1 false), !dbg !24
37  tail call void @llvm.dbg.value(metadata i64 %len, metadata !18, metadata !25), !dbg !24
38  %arrayidx = getelementptr inbounds %struct.S, ptr %0, i64 0, i32 0, i64 %len, !dbg !26
39  %1 = load i32, ptr %arrayidx, align 4, !dbg !26, !tbaa !27
40  store ptr %unsafe_stack_ptr, ptr @__safestack_unsafe_stack_ptr, !dbg !31
41  ret i32 %1, !dbg !31
42}
43
44; Function Attrs: nounwind readnone
45declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46
47; Function Attrs: nounwind readnone
48declare void @llvm.dbg.value(metadata, metadata, metadata) #1
49
50; Function Attrs: argmemonly nounwind
51declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture readonly, i64, i1) #2
52
53attributes #0 = { norecurse nounwind readonly safestack uwtable "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
54attributes #1 = { nounwind readnone }
55attributes #2 = { argmemonly nounwind }
56
57!llvm.dbg.cu = !{!0}
58!llvm.module.flags = !{!19, !20}
59!llvm.ident = !{!21}
60
61!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 254107) (llvm/trunk 254109)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
62!1 = !DIFile(filename: "../llvm/1.cc", directory: "/tmp/build")
63!2 = !{}
64!3 = !{!4}
65!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 4, size: 3200, align: 32, elements: !5, identifier: "_ZTS1S")
66!5 = !{!6}
67!6 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !4, file: !1, line: 5, baseType: !7, size: 3200, align: 32)
68!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 3200, align: 32, elements: !9)
69!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
70!9 = !{!10}
71!10 = !DISubrange(count: 100)
72!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1f1Sm", scope: !1, file: !1, line: 8, type: !13, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !16)
73!13 = !DISubroutineType(types: !14)
74!14 = !{!8, !4, !15}
75!15 = !DIBasicType(name: "long unsigned int", size: 64, align: 64, encoding: DW_ATE_unsigned)
76!16 = !{!17, !18}
77!17 = !DILocalVariable(name: "zzz", arg: 1, scope: !12, file: !1, line: 8, type: !4)
78!18 = !DILocalVariable(name: "len", arg: 2, scope: !12, file: !1, line: 8, type: !15)
79!19 = !{i32 2, !"Dwarf Version", i32 4}
80!20 = !{i32 2, !"Debug Info Version", i32 3}
81!21 = !{!"clang version 3.8.0 (trunk 254107) (llvm/trunk 254109)"}
82!22 = !DILocation(line: 8, column: 9, scope: !12)
83!23 = !DIExpression(DW_OP_deref, DW_OP_constu, 400, DW_OP_minus)
84!24 = !DILocation(line: 8, column: 28, scope: !12)
85!25 = !DIExpression()
86!26 = !DILocation(line: 9, column: 10, scope: !12)
87!27 = !{!28, !28, i64 0}
88!28 = !{!"int", !29, i64 0}
89!29 = !{!"omnipotent char", !30, i64 0}
90!30 = !{!"Simple C/C++ TBAA"}
91!31 = !DILocation(line: 9, column: 3, scope: !12)
92