xref: /llvm-project/llvm/test/CodeGen/WebAssembly/lower-em-sjlj-alias.ll (revision 6420f379268e9178f9f938cef223194ad3daae4e)
1; RUN: opt < %s -wasm-lower-em-ehsjlj -enable-emscripten-sjlj -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 ptr (i32), ptr @dlmalloc
11
12; CHECK-LABEL: @malloc_test
13define void @malloc_test() {
14entry:
15  ; CHECK: alloca i32
16  %retval = alloca i32, align 4
17  %jmp = alloca [1 x %struct.__jmp_buf_tag], align 16
18  store i32 0, ptr %retval, align 4
19  %call = call i32 @setjmp(ptr %jmp) #0
20  call void @foo()
21  ret void
22}
23
24; This is a dummy dlmalloc implemenation only to make compiler pass, because an
25; alias (malloc) has to point an actual definition.
26define ptr @dlmalloc(i32) {
27  %p = inttoptr i32 0 to ptr
28  ret ptr %p
29}
30
31declare void @foo()
32; Function Attrs: returns_twice
33declare i32 @setjmp(ptr) #0
34
35attributes #0 = { returns_twice }
36