1 ; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
4 target triple = "wasm32-unknown-emscripten"
6 ; Tests if an alias to a function (here malloc) is correctly handled as a
7 ; function that cannot longjmp.
9 %struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
10 @malloc = weak alias i8* (i32), i8* (i32)* @dlmalloc
12 ; CHECK-LABEL: @malloc_test
13 define void @malloc_test() {
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
28 ; CHECK-LABEL: entry.split
29 ; CHECK: call void @free
33 ; This is a dummy dlmalloc implemenation only to make compiler pass, because an
34 ; alias (malloc) has to point an actual definition.
35 define i8* @dlmalloc(i32) {
36 %p = inttoptr i32 0 to i8*
40 ; Function Attrs: returns_twice
41 declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
43 attributes #0 = { returns_twice }