xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/declare-to-assign/vla.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -S %s -passes=declare-to-assign -o - | FileCheck %s
2; RUN: opt --try-experimental-debuginfo-iterators -S %s -passes=declare-to-assign -o - | FileCheck %s
3
4;; Check declare-to-assign ignores VLA-backed variables (for now).
5;; From C++ source:
6;; __attribute__ ((nodebug)) int sz;
7;; void fun() {
8;;   int x[sz];
9;; }
10
11; CHECK: #dbg_declare(ptr %vla, ![[#]], !DIExpression(),
12
13@sz = dso_local global i32 0, align 4
14
15define dso_local void @_Z3funv() #0 !dbg !10 {
16entry:
17  %saved_stack = alloca ptr, align 8
18  %__vla_expr0 = alloca i64, align 8
19  %0 = load i32, ptr @sz, align 4, !dbg !14
20  %1 = zext i32 %0 to i64, !dbg !15
21  %2 = call ptr @llvm.stacksave(), !dbg !15
22  store ptr %2, ptr %saved_stack, align 8, !dbg !15
23  %vla = alloca i32, i64 %1, align 16, !dbg !15
24  store i64 %1, ptr %__vla_expr0, align 8, !dbg !15
25  ;; Ignore this artificial variable for the purpose of the test.
26  ; call void @llvm.dbg.declare(metadata ptr %__vla_expr0, metadata !16, metadata !DIExpression()), !dbg !18
27  call void @llvm.dbg.declare(metadata ptr %vla, metadata !19, metadata !DIExpression()), !dbg !24
28  %3 = load ptr, ptr %saved_stack, align 8, !dbg !25
29  call void @llvm.stackrestore(ptr %3), !dbg !25
30  ret void, !dbg !25
31}
32
33declare ptr @llvm.stacksave() #1
34declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
35declare void @llvm.stackrestore(ptr) #1
36
37!llvm.dbg.cu = !{!0}
38!llvm.module.flags = !{!2, !3}
39!llvm.ident = !{!9}
40
41!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
42!1 = !DIFile(filename: "test.cpp", directory: "/")
43!2 = !{i32 7, !"Dwarf Version", i32 5}
44!3 = !{i32 2, !"Debug Info Version", i32 3}
45!8 = !{i32 7, !"frame-pointer", i32 2}
46!9 = !{!"clang version 17.0.0"}
47!10 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
48!11 = !DISubroutineType(types: !12)
49!12 = !{null}
50!13 = !{}
51!14 = !DILocation(line: 3, column: 9, scope: !10)
52!15 = !DILocation(line: 3, column: 3, scope: !10)
53!16 = !DILocalVariable(name: "__vla_expr0", scope: !10, type: !17, flags: DIFlagArtificial)
54!17 = !DIBasicType(name: "unsigned long", size: 64, encoding: DW_ATE_unsigned)
55!18 = !DILocation(line: 0, scope: !10)
56!19 = !DILocalVariable(name: "x", scope: !10, file: !1, line: 3, type: !20)
57!20 = !DICompositeType(tag: DW_TAG_array_type, baseType: !21, elements: !22)
58!21 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
59!22 = !{!23}
60!23 = !DISubrange(count: !16)
61!24 = !DILocation(line: 3, column: 7, scope: !10)
62!25 = !DILocation(line: 4, column: 1, scope: !10)
63