Skip to content

Commit 72c4841

Browse files
committed
Add test
1 parent 074844e commit 72c4841

File tree

5 files changed

+376
-3
lines changed

5 files changed

+376
-3
lines changed

scripts/test/generate_lld_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def generate_wast_files(llvm_bin, emscripten_root):
5050

5151
compile_cmd = [
5252
os.path.join(llvm_bin, 'clang'), src_path, '-o', obj_path,
53-
'--target=wasm32-unknown-unknown-wasm',
53+
'--target=wasm32-emscripten',
54+
'-mllvm', '-enable-emscripten-sjlj',
5455
'-c',
5556
'-nostdinc',
5657
'-Xclang', '-nobuiltininc',

scripts/test/shared.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def parse_args(args):
4343
action='store_false',
4444
help=('If set, the whole test suite will run to completion independent of'
4545
' earlier errors.'))
46-
4746
parser.add_argument(
4847
'--interpreter', dest='interpreter', default='',
4948
help='Specifies the wasm interpreter executable to run tests on.')
@@ -60,7 +59,7 @@ def parse_args(args):
6059
parser.add_argument(
6160
'--out-dir', dest='out_dir', default='',
6261
help=('Specifies a path to the output directory for temp files, which '
63-
'is also where the test runner changes directory into.',
62+
'is also where the test runner changes directory into.'
6463
' Default:. out/test under the binaryen root.'))
6564
parser.add_argument(
6665
'--valgrind', dest='valgrind', default='',

test/lld/shared_longjmp.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
typedef struct jmp_buf_buf {
2+
int thing;
3+
} jmp_buf;
4+
5+
void longjmp(jmp_buf env, int val);
6+
int setjmp(jmp_buf env);
7+
8+
int __THREW__;
9+
int __threwValue;
10+
11+
void _start() {
12+
jmp_buf jmp;
13+
if (setjmp(jmp) == 0) {
14+
longjmp(jmp, 1);
15+
}
16+
}

test/lld/shared_longjmp.wast

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
(module
2+
(type $0 (func (param i32) (result i32)))
3+
(type $1 (func (param i32 i32 i32 i32) (result i32)))
4+
(type $2 (func (result i32)))
5+
(type $3 (func (param i32 i32)))
6+
(type $4 (func (param i32 i32 i32)))
7+
(type $5 (func (param i32 i32 i32) (result i32)))
8+
(type $6 (func (param i32)))
9+
(type $7 (func))
10+
(import "env" "memory" (memory $0 0))
11+
(data (global.get $gimport$2) "\00\00\00\00\00\00\00\00")
12+
(import "env" "__indirect_function_table" (table $timport$1 0 funcref))
13+
(import "env" "__memory_base" (global $gimport$2 i32))
14+
(import "env" "__table_base" (global $gimport$3 i32))
15+
(import "GOT.mem" "__THREW__" (global $gimport$13 (mut i32)))
16+
(import "GOT.func" "emscripten_longjmp_jmpbuf" (global $gimport$14 (mut i32)))
17+
(import "GOT.mem" "__threwValue" (global $gimport$15 (mut i32)))
18+
(import "env" "malloc" (func $malloc (param i32) (result i32)))
19+
(import "env" "saveSetjmp" (func $saveSetjmp (param i32 i32 i32 i32) (result i32)))
20+
(import "env" "getTempRet0" (func $getTempRet0 (result i32)))
21+
(import "env" "emscripten_longjmp_jmpbuf" (func $emscripten_longjmp_jmpbuf (param i32 i32)))
22+
(import "env" "__invoke_void_i32_i32" (func $__invoke_void_i32_i32 (param i32 i32 i32)))
23+
(import "env" "testSetjmp" (func $testSetjmp (param i32 i32 i32) (result i32)))
24+
(import "env" "setTempRet0" (func $setTempRet0 (param i32)))
25+
(import "env" "free" (func $free (param i32)))
26+
(import "env" "emscripten_longjmp" (func $emscripten_longjmp (param i32 i32)))
27+
(global $global$0 i32 (i32.const 0))
28+
(global $global$1 i32 (i32.const 4))
29+
(export "__wasm_call_ctors" (func $__wasm_call_ctors))
30+
(export "_start" (func $_start))
31+
(export "__THREW__" (global $global$0))
32+
(export "__threwValue" (global $global$1))
33+
(func $__wasm_call_ctors (; 9 ;) (type $7)
34+
(call $__wasm_apply_relocs)
35+
)
36+
(func $__wasm_apply_relocs (; 10 ;) (type $7)
37+
)
38+
(func $_start (; 11 ;) (type $7)
39+
(local $0 i32)
40+
(local $1 i32)
41+
(local $2 i32)
42+
(local $3 i32)
43+
(i32.store
44+
(local.tee $0
45+
(call $malloc
46+
(i32.const 40)
47+
)
48+
)
49+
(i32.const 0)
50+
)
51+
(local.set $1
52+
(call $saveSetjmp
53+
(local.get $0)
54+
(i32.const 1)
55+
(local.get $0)
56+
(i32.const 4)
57+
)
58+
)
59+
(local.set $2
60+
(call $getTempRet0)
61+
)
62+
(local.set $0
63+
(i32.const 0)
64+
)
65+
(block $label$1
66+
(block $label$2
67+
(loop $label$3
68+
(br_if $label$2
69+
(local.get $0)
70+
)
71+
(i32.store
72+
(local.tee $0
73+
(global.get $gimport$13)
74+
)
75+
(i32.const 0)
76+
)
77+
(call $__invoke_void_i32_i32
78+
(global.get $gimport$14)
79+
(local.get $0)
80+
(i32.const 1)
81+
)
82+
(local.set $3
83+
(i32.load
84+
(local.get $0)
85+
)
86+
)
87+
(i32.store
88+
(local.get $0)
89+
(i32.const 0)
90+
)
91+
(local.set $0
92+
(global.get $gimport$15)
93+
)
94+
(block $label$4
95+
(br_if $label$4
96+
(i32.eqz
97+
(local.get $3)
98+
)
99+
)
100+
(br_if $label$4
101+
(i32.eqz
102+
(local.tee $0
103+
(i32.load
104+
(local.get $0)
105+
)
106+
)
107+
)
108+
)
109+
(br_if $label$1
110+
(i32.eqz
111+
(call $testSetjmp
112+
(i32.load
113+
(local.get $3)
114+
)
115+
(local.get $1)
116+
(local.get $2)
117+
)
118+
)
119+
)
120+
(call $setTempRet0
121+
(local.get $0)
122+
)
123+
)
124+
(local.set $0
125+
(call $getTempRet0)
126+
)
127+
(br $label$3)
128+
)
129+
)
130+
(call $free
131+
(local.get $1)
132+
)
133+
(return)
134+
)
135+
(call $emscripten_longjmp
136+
(local.get $3)
137+
(local.get $0)
138+
)
139+
(unreachable)
140+
)
141+
;; custom section "dylink", size 5
142+
;; custom section "producers", size 112
143+
)
144+

0 commit comments

Comments
 (0)