1; RUN: llc -mtriple=x86_64-unknown-linux-gnu --basic-block-sections=all < %s | FileCheck %s
2;
3; Verify that AsmPrinter does not optimize debug line directives
4; across two distinct sections. Such optimization will lead
5; to incorrect debug line number if the memory layout of those
6; sections does not strictly mirror the order in the Asm file.
7;
8;    int G;
9;    void func(int x) {
10;      if (x) G=0;
11;    }
12;
13; Reduced from the above example, the IR has been modified so that
14; the store and return instructions have the same DebugLoc; in this
15; context, we should see 2 different directives for line #4 with an
16; intervening section directive.
17;
18; CHECK: .loc    0 4 1
19; CHECK: .section .text.func,"ax",@progbits,unique
20; CHECK: .loc    0 4 1
21
22define void @func(i1 %0) !dbg !8 {
23  br i1 %0, label %3, label %2
24
252:                                                ; preds = %1
26  store i32 0, ptr null, align 4, !dbg !12
27  br label %3
28
293:                                                ; preds = %2, %1
30  ret void, !dbg !12
31}
32
33!llvm.dbg.cu = !{!0}
34!llvm.module.flags = !{!6, !7}
35
36!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 16.0.2", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !2, splitDebugInlining: false, nameTableKind: None)
37!1 = !DIFile(filename: "test.c", directory: "/tmp", checksumkind: CSK_MD5, checksum: "fd2935e6157b382ad81da17a61f24bb1")
38!2 = !{!3}
39!3 = !DIGlobalVariableExpression(var: !4, expr: !DIExpression())
40!4 = distinct !DIGlobalVariable(name: "G", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true)
41!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
42!6 = !{i32 7, !"Dwarf Version", i32 5}
43!7 = !{i32 2, !"Debug Info Version", i32 3}
44!8 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 2, type: !9, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
45!9 = !DISubroutineType(types: !10)
46!10 = !{null}
47!11 = !{}
48!12 = !DILocation(line: 4, column: 1, scope: !8)
49