1; RUN: opt -passes=declare-to-assign -S %s -o - \
2; RUN: | FileCheck %s --check-prefix=WITHOUT-INTRINSIC
3; RUN: opt --try-experimental-debuginfo-iterators -passes=declare-to-assign -S %s -o - \
4; RUN: | FileCheck %s --check-prefix=WITHOUT-INTRINSIC
5
6; RUN: sed 's/;Uncomment-with-sed//g' < %s \
7; RUN: | opt -passes=declare-to-assign -S - -o - \
8; RUN: | FileCheck %s --check-prefix=WITH-INTRINSIC
9
10; WITHOUT-INTRINSIC-NOT: "debug-info-assignment-tracking"
11; WITH-INTRINSIC: "debug-info-assignment-tracking"
12
13;; Check that the module flag "debug-info-assignment-tracking" is only added if
14;; declare-to-assign actually modifies the function. In the first run the
15;; dbg.declare is commented out and the pass leaves the function unmodified.
16;; In the second run sed is used to uncomment the dbg.declare and
17;; declare-to-assign replaces it with a dbg.assign.
18
19define dso_local void @f() !dbg !9 {
20entry:
21  %a = alloca i32, align 4
22;Uncomment-with-sed  call void @llvm.dbg.declare(metadata ptr %a, metadata !13, metadata !DIExpression()), !dbg !16
23  ret void, !dbg !17
24}
25
26declare void @llvm.dbg.declare(metadata, metadata, metadata)
27
28!llvm.dbg.cu = !{!0}
29!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
30!llvm.ident = !{!8}
31
32!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
33!1 = !DIFile(filename: "test.c", directory: "/")
34!2 = !{i32 7, !"Dwarf Version", i32 5}
35!3 = !{i32 2, !"Debug Info Version", i32 3}
36!4 = !{i32 1, !"wchar_size", i32 4}
37!5 = !{i32 8, !"PIC Level", i32 2}
38!6 = !{i32 7, !"PIE Level", i32 2}
39!7 = !{i32 7, !"uwtable", i32 2}
40!8 = !{!"clang version 17.0.0"}
41!9 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
42!10 = !DISubroutineType(types: !11)
43!11 = !{null}
44!12 = !{!13}
45!13 = !DILocalVariable(name: "a", scope: !9, file: !1, line: 1, type: !14)
46!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
47!15 = !DILocation(line: 1, column: 12, scope: !9)
48!16 = !DILocation(line: 1, column: 16, scope: !9)
49!17 = !DILocation(line: 1, column: 19, scope: !9)
50