1; RUN: opt -debugify -S -o - < %s | FileCheck %s
2; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s
3
4; RUN: opt -debugify -debugify -S -o - < %s 2>&1 | \
5; RUN:   FileCheck %s -check-prefix=CHECK-REPEAT
6; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \
7; RUN:   FileCheck %s -check-prefix=CHECK-REPEAT
8
9; RUN: opt -debugify -check-debugify -S -o - < %s | \
10; RUN:   FileCheck %s -implicit-check-not="CheckModuleDebugify: FAIL"
11; RUN: opt -passes=debugify,check-debugify -S -o - < %s | \
12; RUN:   FileCheck %s -implicit-check-not="CheckModuleDebugify: FAIL"
13; RUN: opt -enable-debugify -passes=verify -S -o - < %s | \
14; RUN:   FileCheck %s -implicit-check-not="CheckModuleDebugify: FAIL"
15
16; RUN: opt -debugify -strip -check-debugify -S -o - < %s 2>&1 | \
17; RUN:   FileCheck %s -check-prefix=CHECK-FAIL
18
19; RUN: opt -enable-debugify -strip -S -o - < %s 2>&1 | \
20; RUN:   FileCheck %s -check-prefix=CHECK-FAIL
21
22; RUN: opt -enable-debugify -S -o - < %s 2>&1 | FileCheck %s -check-prefix=PASS
23
24; Verify that debugify can be safely used with piping
25; RUN: opt -enable-debugify -O1 < %s | opt -O2 -o /dev/null
26; RUN: opt -debugify -mem2reg -check-debugify < %s | opt -O2 -o /dev/null
27
28; CHECK-LABEL: define void @foo
29define void @foo() {
30; CHECK: ret void, !dbg ![[RET1:.*]]
31  ret void
32}
33
34; CHECK-LABEL: define i32 @bar
35define i32 @bar() {
36; CHECK: call void @foo(), !dbg ![[CALL1:.*]]
37  call void @foo()
38
39; CHECK: add i32 0, 1, !dbg ![[ADD1:.*]]
40  %sum = add i32 0, 1
41
42; CHECK: ret i32 0, !dbg ![[RET2:.*]]
43  ret i32 0
44}
45
46; CHECK-LABEL: define weak_odr zeroext i1 @baz
47define weak_odr zeroext i1 @baz() {
48; CHECK-NOT: !dbg
49  ret i1 false
50}
51
52; CHECK-LABEL: define i32 @boom
53define i32 @boom() {
54; CHECK: [[result:%.*]] = musttail call i32 @bar(), !dbg ![[musttail:.*]]
55  %retval = musttail call i32 @bar()
56; CHECK-NEXT: ret i32 [[result]], !dbg ![[musttailRes:.*]]
57  ret i32 %retval
58}
59
60; CHECK-DAG: !llvm.dbg.cu = !{![[CU:.*]]}
61; CHECK-DAG: !llvm.debugify = !{![[NUM_INSTS:.*]], ![[NUM_VARS:.*]]}
62; CHECK-DAG: "Debug Info Version"
63
64; CHECK-DAG: ![[CU]] = distinct !DICompileUnit(language: DW_LANG_C, file: {{.*}}, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: {{.*}})
65; CHECK-DAG: !DIFile(filename: "<stdin>", directory: "/")
66; CHECK-DAG: distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: {{.*}}, line: 1, type: {{.*}}, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
67; CHECK-DAG: distinct !DISubprogram(name: "bar", linkageName: "bar", scope: null, file: {{.*}}, line: 2, type: {{.*}}, scopeLine: 2, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: {{.*}}, retainedNodes: {{.*}})
68
69; --- DILocations
70; CHECK-DAG: ![[RET1]] = !DILocation(line: 1, column: 1
71; CHECK-DAG: ![[CALL1]] = !DILocation(line: 2, column: 1
72; CHECK-DAG: ![[ADD1]] = !DILocation(line: 3, column: 1
73; CHECK-DAG: ![[RET2]] = !DILocation(line: 4, column: 1
74; CHECK-DAG: ![[musttail]] = !DILocation(line: 5, column: 1
75; CHECK-DAG: ![[musttailRes]] = !DILocation(line: 6, column: 1
76
77; --- DILocalVariables
78; CHECK-DAG: ![[TY32:.*]] = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
79; CHECK-DAG: !DILocalVariable(name: "1", scope: {{.*}}, file: {{.*}}, line: 3, type: ![[TY32]])
80
81; --- Metadata counts
82; CHECK-DAG: ![[NUM_INSTS]] = !{i32 6}
83; CHECK-DAG: ![[NUM_VARS]] = !{i32 1}
84
85; --- Repeat case
86; CHECK-REPEAT: ModuleDebugify: Skipping module with debug info
87
88; --- Failure case
89; CHECK-FAIL: ERROR: Instruction with empty DebugLoc in function foo --   ret void
90; CHECK-FAIL: ERROR: Instruction with empty DebugLoc in function bar --   call void @foo()
91; CHECK-FAIL: ERROR: Instruction with empty DebugLoc in function bar --   {{.*}} add i32 0, 1
92; CHECK-FAIL: ERROR: Instruction with empty DebugLoc in function bar --   ret i32 0
93; CHECK-FAIL: WARNING: Missing line 1
94; CHECK-FAIL: WARNING: Missing line 2
95; CHECK-FAIL: WARNING: Missing line 3
96; CHECK-FAIL: WARNING: Missing line 4
97; CHECK-FAIL: WARNING: Missing variable 1
98; CHECK-FAIL: CheckModuleDebugify: FAIL
99
100; PASS: CheckModuleDebugify: PASS
101