xref: /llvm-project/llvm/test/DebugInfo/X86/instr-ref-dyn-alloca-win32.ll (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1; RUN: llc %s -o - -stop-after=machine-sink \
2; RUN:     -experimental-debug-variable-locations=true \
3; RUN:    | FileCheck %s --check-prefixes=DYN_LABEL
4; RUN: llc %s -o - -stop-before=phi-node-elimination \
5; RUN:     -experimental-debug-variable-locations=true \
6; RUN:    | FileCheck %s --check-prefixes=DYN_LOWERED
7
8;; This is a copy of DebugInfo/COFF/types-array-advanced.ll, checking that
9;; DYN_ALLOCAs correctly have instruction references updated. This is compiled
10;; from LLVM-IR because the "hasDynAlloca" flag isn't serialised to MIR, for
11;; complicated reasons, that means we can't store as MIR.
12
13;; The alloca instruction should be labelled, and we should refer to operand 2,
14;; which happens to be a def of $esp
15; DYN_LABEL: DYN_ALLOCA_32 {{.*}} debug-instr-number 1,
16; DYN_LABEL: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 2)
17
18;; Once lowered, on win32 _chkstk alters the stack pointer. We should label the
19;; call and it's SP operand, plus check for a value substitution.
20; DYN_LOWERED:      debugValueSubstitutions:
21; DYN_LOWERED-NEXT: - { srcinst: 1, srcop: 2, dstinst: 2, dstop: 6, subreg: 0 }
22;; Test that it's operand six, and labelled.
23; DYN_LOWERED:      CALLpcrel32 &_chkstk, implicit $esp, implicit $ssp,
24; DYN_LOWERED-SAME: implicit killed $eax, implicit $esp, implicit-def dead $eax,
25; DYN_LOWERED-SAME: implicit-def $esp, implicit-def dead $eflags,
26; DYN_LOWERED-SAME:  debug-instr-number 2,
27
28source_filename = "test/DebugInfo/COFF/types-array-advanced.ll"
29target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
30target triple = "i686-pc-windows-msvc18.0.31101"
31
32%struct.incomplete_struct = type { i32 }
33
34@"\01?multi_dim_arr@@3PAY146DA" = global [2 x [5 x [7 x i8]]] zeroinitializer, align 1, !dbg !0
35@"\01?p_incomplete_struct_arr@@3PAY02Uincomplete_struct@@A" = global ptr null, align 4, !dbg !6
36@"\01?incomplete_struct_arr@@3PAUincomplete_struct@@A" = global [3 x %struct.incomplete_struct] zeroinitializer, align 4, !dbg !16
37@"\01?typedef_arr@@3SDHD" = constant [4 x i32] zeroinitializer, align 4, !dbg !18
38
39; Function Attrs: nounwind
40define void @"\01?foo@@YAXH@Z"(i32 %x) #0 !dbg !35 {
41entry:
42  %x.addr = alloca i32, align 4
43  %saved_stack = alloca ptr, align 4
44  store i32 %x, ptr %x.addr, align 4
45  call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !38, metadata !39), !dbg !40
46  %0 = load i32, ptr %x.addr, align 4, !dbg !41
47  %1 = call ptr @llvm.stacksave(), !dbg !42
48  store ptr %1, ptr %saved_stack, align 4, !dbg !42
49  %vla = alloca i32, i32 %0, align 4, !dbg !42
50  call void @llvm.dbg.declare(metadata ptr %vla, metadata !43, metadata !47), !dbg !48
51  store i32 0, ptr %vla, align 4, !dbg !50
52  %2 = load ptr, ptr %saved_stack, align 4, !dbg !51
53  call void @llvm.stackrestore(ptr %2), !dbg !51
54  ret void, !dbg !51
55}
56
57; Function Attrs: nounwind readnone
58declare void @llvm.dbg.declare(metadata, metadata, metadata)
59
60; Function Attrs: nounwind
61declare ptr @llvm.stacksave()
62
63; Function Attrs: nounwind
64declare void @llvm.stackrestore(ptr)
65
66!llvm.dbg.cu = !{!2}
67!llvm.module.flags = !{!32, !33}
68!llvm.ident = !{!34}
69
70!0 = distinct !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
71!1 = !DIGlobalVariable(name: "multi_dim_arr", linkageName: "\01?multi_dim_arr@@3PAY146DA", scope: !2, file: !3, line: 1, type: !26, isLocal: false, isDefinition: true)
72!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.9.0 (trunk 273874)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
73!3 = !DIFile(filename: "t.cpp", directory: "/")
74!4 = !{}
75!5 = !{!0, !6, !16, !18}
76!6 = distinct !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
77!7 = !DIGlobalVariable(name: "p_incomplete_struct_arr", linkageName: "\01?p_incomplete_struct_arr@@3PAY02Uincomplete_struct@@A", scope: !2, file: !3, line: 3, type: !8, isLocal: false, isDefinition: true)
78!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 32, align: 32)
79!9 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, elements: !14)
80!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete_struct", file: !3, line: 4, size: 32, align: 32, elements: !11, identifier: ".?AUincomplete_struct@@")
81!11 = !{!12}
82!12 = !DIDerivedType(tag: DW_TAG_member, name: "s1", scope: !10, file: !3, line: 5, baseType: !13, size: 32, align: 32)
83!13 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
84!14 = !{!15}
85!15 = !DISubrange(count: 3)
86!16 = distinct !DIGlobalVariableExpression(var: !17, expr: !DIExpression())
87!17 = !DIGlobalVariable(name: "incomplete_struct_arr", linkageName: "\01?incomplete_struct_arr@@3PAUincomplete_struct@@A", scope: !2, file: !3, line: 6, type: !9, isLocal: false, isDefinition: true)
88!18 = distinct !DIGlobalVariableExpression(var: !19, expr: !DIExpression())
89!19 = !DIGlobalVariable(name: "typedef_arr", linkageName: "\01?typedef_arr@@3SDHD", scope: !2, file: !3, line: 14, type: !20, isLocal: false, isDefinition: true)
90!20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !21, size: 128, align: 32, elements: !24)
91!21 = !DIDerivedType(tag: DW_TAG_typedef, name: "T_INT", file: !3, line: 13, baseType: !22)
92!22 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !23)
93!23 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !13)
94!24 = !{!25}
95!25 = !DISubrange(count: 4)
96!26 = !DICompositeType(tag: DW_TAG_array_type, baseType: !27, size: 560, align: 8, elements: !28)
97!27 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
98!28 = !{!29, !30, !31}
99!29 = !DISubrange(count: 2)
100!30 = !DISubrange(count: 5)
101!31 = !DISubrange(count: 7)
102!32 = !{i32 2, !"CodeView", i32 1}
103!33 = !{i32 2, !"Debug Info Version", i32 3}
104!34 = !{!"clang version 3.9.0 (trunk 273874)"}
105!35 = distinct !DISubprogram(name: "foo", linkageName: "\01?foo@@YAXH@Z", scope: !3, file: !3, line: 8, type: !36, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4)
106!36 = !DISubroutineType(types: !37)
107!37 = !{null, !13}
108!38 = !DILocalVariable(name: "x", arg: 1, scope: !35, file: !3, line: 8, type: !13)
109!39 = !DIExpression()
110!40 = !DILocation(line: 8, column: 14, scope: !35)
111!41 = !DILocation(line: 9, column: 21, scope: !35)
112!42 = !DILocation(line: 9, column: 4, scope: !35)
113!43 = !DILocalVariable(name: "dyn_size_arr", scope: !35, file: !3, line: 9, type: !44)
114!44 = !DICompositeType(tag: DW_TAG_array_type, baseType: !13, align: 32, elements: !45)
115!45 = !{!46}
116!46 = !DISubrange(count: -1)
117!47 = !DIExpression(DW_OP_deref)
118!48 = !DILocation(line: 9, column: 8, scope: !35)
119!49 = !DILocation(line: 10, column: 4, scope: !35)
120!50 = !DILocation(line: 10, column: 20, scope: !35)
121!51 = !DILocation(line: 11, column: 1, scope: !35)
122
123