1; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
2
3target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4target triple = "wasm32-unknown-unknown"
5
6%struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
7
8; Basic debug info test. All existing instructions have debug info and inserted
9; 'malloc' and 'free' calls take debug info from the next instruction.
10define void @setjmp_debug_info0() !dbg !3 {
11; CHECK-LABEL: @setjmp_debug_info0
12entry:
13  %buf = alloca [1 x %struct.__jmp_buf_tag], align 16, !dbg !4
14  %arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0, !dbg !5
15  %call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0, !dbg !6
16  call void @foo(), !dbg !7
17  ret void, !dbg !8
18; CHECK: entry:
19  ; CHECK-NEXT: call i8* @malloc(i32 40), !dbg ![[DL0:.*]]
20  ; CHECK-NEXT: bitcast {{.*}}, !dbg ![[DL0]]
21  ; CHECK: alloca {{.*}}, !dbg ![[DL0]]
22  ; CHECK: call i32* @saveSetjmp{{.*}}, !dbg ![[DL1:.*]]
23  ; CHECK-NEXT: call i32 @getTempRet0{{.*}}, !dbg ![[DL1]]
24  ; CHECK-NEXT: br {{.*}}, !dbg ![[DL2:.*]]
25
26; CHECK: entry.split:
27  ; CHECK: call {{.*}} void @__invoke_void{{.*}}, !dbg ![[DL2]]
28
29; CHECK: entry.split.split:
30  ; CHECK-NEXT: bitcast {{.*}}, !dbg ![[DL3:.*]]
31  ; CHECK-NEXT: call void @free{{.*}}, !dbg ![[DL3]]
32
33; CHECK: if.then1:
34  ; CHECK: call i32 @testSetjmp{{.*}}, !dbg ![[DL2]]
35
36; CHECK: if.end:
37  ; CHECK: call i32 @getTempRet0{{.*}}, !dbg ![[DL2]]
38
39; CHECK: if.then2:
40  ; CHECK: call void @emscripten_longjmp{{.*}}, !dbg ![[DL2]]
41
42; CHECK: if.end2:
43  ; CHECK: call void @setTempRet0{{.*}}, !dbg ![[DL2]]
44}
45
46; No instruction has debug info but the current function (setjmp_debug_info2)
47; and the called function (malloc / free) have DISubprograms, so the newly
48; generated calls should have debug info attached. We don't have an instruction
49; to take debug info from, so we create dummy debug info.
50define void @setjmp_debug_info1() !dbg !9 {
51; CHECK-LABEL: @setjmp_debug_info1
52entry:
53  %buf = alloca [1 x %struct.__jmp_buf_tag], align 16
54  %arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
55  %call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
56  call void @foo()
57  ret void
58  ; CHECK: call i8* @malloc(i32 40), !dbg ![[DL_DUMMY:.*]]
59  ; CHECK: call void @free{{.*}}, !dbg ![[DL_DUMMY]]
60}
61
62; Note that these functions have DISubprograms.
63declare !dbg !10 i8* @malloc(i32)
64declare !dbg !11 void @free(i8*)
65
66declare void @foo()
67; Function Attrs: returns_twice
68declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
69
70!llvm.dbg.cu = !{!2}
71!llvm.module.flags = !{!0}
72
73!0 = !{i32 2, !"Debug Info Version", i32 3}
74!1 = !DIFile(filename: "lower-em-sjlj.c", directory: "test")
75!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1)
76!3 = distinct !DISubprogram(name: "setjmp_debug_info0", unit:!2, file: !1, line: 1)
77!4 = !DILocation(line:2, scope: !3)
78!5 = !DILocation(line:3, scope: !3)
79!6 = !DILocation(line:4, scope: !3)
80!7 = !DILocation(line:5, scope: !3)
81!8 = !DILocation(line:6, scope: !3)
82!9 = distinct !DISubprogram(name: "setjmp_debug_info1", unit:!2, file: !1, line: 50)
83!10 = !DISubprogram(name: "malloc", file: !1, line: 10, isDefinition: false)
84!11 = !DISubprogram(name: "free", file: !1, line: 20, isDefinition: false)
85
86; Dummy debug info generated
87; CHECK: ![[DL_DUMMY]] = !DILocation(line: 50, column: 1, scope: !9)
88