summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-06-21 08:30:55 -0700
committerGitHub <noreply@github.com>2024-06-21 08:30:55 -0700
commit02625158ebd0a15eaa6524fdbbc3af23497bb34f (patch)
treec9b8261ec5b71c2561ccdefa0739ed25c3d2f069 /test
parentc3089b3b553536ece3b1d6a9cffe82cda1b813e5 (diff)
downloadbinaryen-02625158ebd0a15eaa6524fdbbc3af23497bb34f.tar.gz
binaryen-02625158ebd0a15eaa6524fdbbc3af23497bb34f.tar.bz2
binaryen-02625158ebd0a15eaa6524fdbbc3af23497bb34f.zip
wasm2js: Fix the names of temp vars with named reference types (#6689)
We were missing code to mangle such names for JS. Without that, the name of a temp var for the type `(ref $foo)` would end up with `(`, `)` in the name, which is not valid in JS.
Diffstat (limited to 'test')
-rw-r--r--test/wasm2js/refs.2asm.js10
-rw-r--r--test/wasm2js/refs.2asm.js.opt8
-rw-r--r--test/wasm2js/refs.wast22
3 files changed, 38 insertions, 2 deletions
diff --git a/test/wasm2js/refs.2asm.js b/test/wasm2js/refs.2asm.js
index f4c08408f..45e510e37 100644
--- a/test/wasm2js/refs.2asm.js
+++ b/test/wasm2js/refs.2asm.js
@@ -61,6 +61,12 @@ function asmFunc(imports) {
funcref_temps(funcref_temps, +(+((wasm2js_funcref$0 = $2, wasm2js_funcref$1 = $3 || wasm2js_trap(), wasm2js_i32$0 = 0, wasm2js_i32$0 ? wasm2js_funcref$0 : wasm2js_funcref$1) == null | 0)));
}
+ function named_type_temps() {
+ var $0 = null, wasm2js__ref_null_$func_0_$0_1 = null, wasm2js__ref_null_$func_0_$1_1 = null, wasm2js_i32$0 = 0;
+ $0 = named_type_temps;
+ return wasm2js__ref_null_$func_0_$0 = null, wasm2js__ref_null_$func_0_$1 = $0 || wasm2js_trap(), wasm2js_i32$0 = 0, wasm2js_i32$0 ? wasm2js__ref_null_$func_0_$0 : wasm2js__ref_null_$func_0_$1;
+ }
+
return {
"null_": null_,
"is_null": is_null,
@@ -69,7 +75,8 @@ function asmFunc(imports) {
"ref_as": ref_as,
"use_global": use_global,
"use_global_ref": use_global_ref,
- "funcref_temps": funcref_temps
+ "funcref_temps": funcref_temps,
+ "named_type_temps": named_type_temps
};
}
@@ -83,3 +90,4 @@ export var ref_as = retasmFunc.ref_as;
export var use_global = retasmFunc.use_global;
export var use_global_ref = retasmFunc.use_global_ref;
export var funcref_temps = retasmFunc.funcref_temps;
+export var named_type_temps = retasmFunc.named_type_temps;
diff --git a/test/wasm2js/refs.2asm.js.opt b/test/wasm2js/refs.2asm.js.opt
index 0071a15b5..ee8c25a7c 100644
--- a/test/wasm2js/refs.2asm.js.opt
+++ b/test/wasm2js/refs.2asm.js.opt
@@ -53,6 +53,10 @@ function asmFunc(imports) {
funcref_temps(funcref_temps, 0.0);
}
+ function named_type_temps() {
+ return named_type_temps;
+ }
+
return {
"null_": null_,
"is_null": is_null,
@@ -61,7 +65,8 @@ function asmFunc(imports) {
"ref_as": ref_as,
"use_global": use_global,
"use_global_ref": use_global_ref,
- "funcref_temps": funcref_temps
+ "funcref_temps": funcref_temps,
+ "named_type_temps": named_type_temps
};
}
@@ -75,3 +80,4 @@ export var ref_as = retasmFunc.ref_as;
export var use_global = retasmFunc.use_global;
export var use_global_ref = retasmFunc.use_global_ref;
export var funcref_temps = retasmFunc.funcref_temps;
+export var named_type_temps = retasmFunc.named_type_temps;
diff --git a/test/wasm2js/refs.wast b/test/wasm2js/refs.wast
index 087567e8c..57eec8fff 100644
--- a/test/wasm2js/refs.wast
+++ b/test/wasm2js/refs.wast
@@ -1,4 +1,6 @@
(module
+ (type $func (func (result funcref)))
+
(global $global (mut anyref) (ref.null any))
(global $global-ref (mut funcref) (ref.func $use-global-ref))
@@ -81,4 +83,24 @@
)
)
)
+
+ (func $named_type_temps (export "named_type_temps") (result funcref)
+ ;; This nested expression ends up needing to use temp vars, and one such
+ ;; name contains the type $func. We should emit that in form that is
+ ;; mangled for JS, without '(' which appears in the stringified name of the
+ ;; type, "(ref null $func)".
+ (select (result (ref null $func))
+ (ref.null nofunc)
+ (if (result (ref $func))
+ (i32.const 1)
+ (then
+ (ref.func $named_type_temps)
+ )
+ (else
+ (unreachable)
+ )
+ )
+ (i32.const 0)
+ )
+ )
)