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-emscripten"
5
6; Tests if an alias to a function (here malloc) is correctly handled as a
7; function that cannot longjmp.
8
9%struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
10@malloc = weak alias i8* (i32), i8* (i32)* @dlmalloc
11
12; CHECK-LABEL: @malloc_test
13define void @malloc_test() {
14entry:
15; CHECK-LABEL: entry
16  ; All setjmp table preparations have to happen within the entry block. These
17  ; check lines list only some of the instructions for that.
18  ; CHECK: call i8* @malloc
19  ; CHECK: call i32* @saveSetjmp
20  ; CHECK: call i32 @getTempRet0
21  %retval = alloca i32, align 4
22  %jmp = alloca [1 x %struct.__jmp_buf_tag], align 16
23  store i32 0, i32* %retval, align 4
24  %arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %jmp, i32 0, i32 0
25  %call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
26  ret void
27
28; CHECK-LABEL: entry.split
29  ; CHECK: call void @free
30  ; CHECK: ret void
31}
32
33; This is a dummy dlmalloc implemenation only to make compiler pass, because an
34; alias (malloc) has to point an actual definition.
35define i8* @dlmalloc(i32) {
36  %p = inttoptr i32 0 to i8*
37  ret i8* %p
38}
39
40; Function Attrs: returns_twice
41declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
42
43attributes #0 = { returns_twice }
44