1; RUN: llc < %s -O0 -verify-machineinstrs | FileCheck %s
2
3; Test verifies if .loc is properly set for loop and block instructions --
4; the line number is not a 0 when DebugLoc is defined.
5
6; Compiled from the dbg-loop-loc.c:
7; int fib(int n) {
8;   int i, t, a = 0, b = 1;
9;   for (i = 0; i < n; i++) {
10;     t = a + b; a = b; b = t;
11;   }
12;   return b;
13; }
14
15; ModuleID = 'dbg-loop-loc.bc'
16source_filename = "dbg-loop-loc.c"
17target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
18target triple = "wasm32-unknown-unknown"
19
20; CHECK: .file 1
21; CHECK: .loc 1 1 0
22; CHECK: .loc 1 3 15
23; CHECK-NEXT: block
24; CHECK-NEXT: loop
25; CHECK: br 0
26; CHECK-NOT: .loc 1 0
27; CHECK: end_loop
28; CHECK: end_block
29; CHECK-NOT: .loc 1 0
30; CHECK: end_function
31
32; Function Attrs: noinline nounwind optnone
33define hidden i32 @fib(i32 %n) #0 !dbg !7 {
34entry:
35  %n.addr = alloca i32, align 4
36  %i = alloca i32, align 4
37  %t = alloca i32, align 4
38  %a = alloca i32, align 4
39  %b = alloca i32, align 4
40  store i32 %n, i32* %n.addr, align 4
41  call void @llvm.dbg.declare(metadata i32* %n.addr, metadata !11, metadata !DIExpression()), !dbg !12
42  call void @llvm.dbg.declare(metadata i32* %i, metadata !13, metadata !DIExpression()), !dbg !14
43  call void @llvm.dbg.declare(metadata i32* %t, metadata !15, metadata !DIExpression()), !dbg !16
44  call void @llvm.dbg.declare(metadata i32* %a, metadata !17, metadata !DIExpression()), !dbg !18
45  store i32 0, i32* %a, align 4, !dbg !18
46  call void @llvm.dbg.declare(metadata i32* %b, metadata !19, metadata !DIExpression()), !dbg !20
47  store i32 1, i32* %b, align 4, !dbg !20
48  store i32 0, i32* %i, align 4, !dbg !21
49  br label %for.cond, !dbg !23
50
51for.cond:                                         ; preds = %for.inc, %entry
52  %0 = load i32, i32* %i, align 4, !dbg !24
53  %1 = load i32, i32* %n.addr, align 4, !dbg !26
54  %cmp = icmp slt i32 %0, %1, !dbg !27
55  br i1 %cmp, label %for.body, label %for.end, !dbg !28
56
57for.body:                                         ; preds = %for.cond
58  %2 = load i32, i32* %a, align 4, !dbg !29
59  %3 = load i32, i32* %b, align 4, !dbg !31
60  %add = add nsw i32 %2, %3, !dbg !32
61  store i32 %add, i32* %t, align 4, !dbg !33
62  %4 = load i32, i32* %b, align 4, !dbg !34
63  store i32 %4, i32* %a, align 4, !dbg !35
64  %5 = load i32, i32* %t, align 4, !dbg !36
65  store i32 %5, i32* %b, align 4, !dbg !37
66  br label %for.inc, !dbg !38
67
68for.inc:                                          ; preds = %for.body
69  %6 = load i32, i32* %i, align 4, !dbg !39
70  %inc = add nsw i32 %6, 1, !dbg !39
71  store i32 %inc, i32* %i, align 4, !dbg !39
72  br label %for.cond, !dbg !40, !llvm.loop !41
73
74for.end:                                          ; preds = %for.cond
75  %7 = load i32, i32* %b, align 4, !dbg !43
76  ret i32 %7, !dbg !44
77}
78
79; Function Attrs: nounwind readnone speculatable
80declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
81
82attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
83attributes #1 = { nounwind readnone speculatable }
84
85!llvm.dbg.cu = !{!0}
86!llvm.module.flags = !{!3, !4, !5}
87!llvm.ident = !{!6}
88
89!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 326837)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
90!1 = !DIFile(filename: "dbg-loop-loc.c", directory: "/Users/yury/llvmwasm")
91!2 = !{}
92!3 = !{i32 2, !"Dwarf Version", i32 4}
93!4 = !{i32 2, !"Debug Info Version", i32 3}
94!5 = !{i32 1, !"wchar_size", i32 4}
95!6 = !{!"clang version 7.0.0 (trunk 326837)"}
96!7 = distinct !DISubprogram(name: "fib", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
97!8 = !DISubroutineType(types: !9)
98!9 = !{!10, !10}
99!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
100!11 = !DILocalVariable(name: "n", arg: 1, scope: !7, file: !1, line: 1, type: !10)
101!12 = !DILocation(line: 1, column: 13, scope: !7)
102!13 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 2, type: !10)
103!14 = !DILocation(line: 2, column: 7, scope: !7)
104!15 = !DILocalVariable(name: "t", scope: !7, file: !1, line: 2, type: !10)
105!16 = !DILocation(line: 2, column: 10, scope: !7)
106!17 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 2, type: !10)
107!18 = !DILocation(line: 2, column: 13, scope: !7)
108!19 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 2, type: !10)
109!20 = !DILocation(line: 2, column: 20, scope: !7)
110!21 = !DILocation(line: 3, column: 10, scope: !22)
111!22 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 3)
112!23 = !DILocation(line: 3, column: 8, scope: !22)
113!24 = !DILocation(line: 3, column: 15, scope: !25)
114!25 = distinct !DILexicalBlock(scope: !22, file: !1, line: 3, column: 3)
115!26 = !DILocation(line: 3, column: 19, scope: !25)
116!27 = !DILocation(line: 3, column: 17, scope: !25)
117!28 = !DILocation(line: 3, column: 3, scope: !22)
118!29 = !DILocation(line: 4, column: 9, scope: !30)
119!30 = distinct !DILexicalBlock(scope: !25, file: !1, line: 3, column: 27)
120!31 = !DILocation(line: 4, column: 13, scope: !30)
121!32 = !DILocation(line: 4, column: 11, scope: !30)
122!33 = !DILocation(line: 4, column: 7, scope: !30)
123!34 = !DILocation(line: 4, column: 20, scope: !30)
124!35 = !DILocation(line: 4, column: 18, scope: !30)
125!36 = !DILocation(line: 4, column: 27, scope: !30)
126!37 = !DILocation(line: 4, column: 25, scope: !30)
127!38 = !DILocation(line: 5, column: 3, scope: !30)
128!39 = !DILocation(line: 3, column: 23, scope: !25)
129!40 = !DILocation(line: 3, column: 3, scope: !25)
130!41 = distinct !{!41, !28, !42}
131!42 = !DILocation(line: 5, column: 3, scope: !22)
132!43 = !DILocation(line: 6, column: 10, scope: !7)
133!44 = !DILocation(line: 6, column: 3, scope: !7)
134