summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h17
-rw-r--r--test/dot_s/basics.wast3
-rw-r--r--test/dot_s/bcp-1.wast72
-rw-r--r--test/llvm_autogenerated/call.wast6
4 files changed, 47 insertions, 51 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index f4c83fe65..5460bf467 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -752,16 +752,7 @@ class S2WasmBuilder {
indirect->operands.push_back(inputs[i]);
}
setOutput(indirect, assign);
- auto typeName = cashew::IString((std::string("FUNCSIG_") + getSig(indirect)).c_str(), false);
- if (wasm.functionTypesMap.count(typeName) == 0) {
- auto type = allocator.alloc<FunctionType>();
- *type = sigToFunctionType(getSig(indirect));
- type->name = typeName;
- wasm.addFunctionType(type);
- indirect->fullType = type;
- } else {
- indirect->fullType = wasm.functionTypesMap[typeName];
- }
+ indirect->fullType = wasm.functionTypesMap[ensureFunctionType(getSig(indirect), &wasm, allocator)->name];
} else {
// non-indirect call
CallBase* curr;
@@ -1314,6 +1305,12 @@ class S2WasmBuilder {
block->finalize();
}
}
+
+ // ensure an explicit function type for indirect call targets
+ for (auto& name : wasm.table.names) {
+ auto* func = wasm.functionsMap[name];
+ func->type = ensureFunctionType(getSig(func), &wasm, allocator)->name;
+ }
}
template<class C>
diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast
index 8fc8c3d67..91620910c 100644
--- a/test/dot_s/basics.wast
+++ b/test/dot_s/basics.wast
@@ -6,10 +6,11 @@
)
(export "memory" memory)
(type $FUNCSIG$vi (func (param i32)))
+ (type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(import $puts "env" "puts" (param i32))
(export "main" $main)
(table $main)
- (func $main (param $$0 i32) (param $$1 i32) (result i32)
+ (func $main (type $FUNCSIG$iii) (param $$0 i32) (param $$1 i32) (result i32)
(call_import $puts
(i32.const 16)
)
diff --git a/test/dot_s/bcp-1.wast b/test/dot_s/bcp-1.wast
index f558e06e0..091dff695 100644
--- a/test/dot_s/bcp-1.wast
+++ b/test/dot_s/bcp-1.wast
@@ -9,8 +9,8 @@
(segment 100 "\00\00\00\00")
)
(export "memory" memory)
- (type $FUNCSIG_i (func (result i32)))
- (type $FUNCSIG_ii (func (param i32) (result i32)))
+ (type $FUNCSIG$i (func (result i32)))
+ (type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$vi (func (param i32)))
(type $FUNCSIG$v (func))
(import $exit "env" "exit" (param i32))
@@ -34,87 +34,87 @@
(export "opt2" $opt2)
(export "main" $main)
(table $bad0 $bad1 $bad5 $bad7 $bad8 $bad10 $bad2 $bad3 $bad6 $bad4 $bad9 $good0 $good1 $good2 $opt0 $opt1 $opt2)
- (func $bad0 (result i32)
+ (func $bad0 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $bad1 (result i32)
+ (func $bad1 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $bad2 (param $$0 i32) (result i32)
+ (func $bad2 (type $FUNCSIG$ii) (param $$0 i32) (result i32)
(return
(i32.const 0)
)
)
- (func $bad3 (param $$0 i32) (result i32)
+ (func $bad3 (type $FUNCSIG$ii) (param $$0 i32) (result i32)
(return
(i32.const 0)
)
)
- (func $bad4 (param $$0 i32) (result i32)
+ (func $bad4 (type $FUNCSIG$ii) (param $$0 i32) (result i32)
(return
(i32.const 0)
)
)
- (func $bad5 (result i32)
+ (func $bad5 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $bad6 (param $$0 i32) (result i32)
+ (func $bad6 (type $FUNCSIG$ii) (param $$0 i32) (result i32)
(return
(i32.const 0)
)
)
- (func $bad7 (result i32)
+ (func $bad7 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $bad8 (result i32)
+ (func $bad8 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $bad9 (param $$0 i32) (result i32)
+ (func $bad9 (type $FUNCSIG$ii) (param $$0 i32) (result i32)
(return
(i32.const 0)
)
)
- (func $bad10 (result i32)
+ (func $bad10 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $good0 (result i32)
+ (func $good0 (type $FUNCSIG$i) (result i32)
(return
(i32.const 1)
)
)
- (func $good1 (result i32)
+ (func $good1 (type $FUNCSIG$i) (result i32)
(return
(i32.const 1)
)
)
- (func $good2 (result i32)
+ (func $good2 (type $FUNCSIG$i) (result i32)
(return
(i32.const 1)
)
)
- (func $opt0 (result i32)
+ (func $opt0 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $opt1 (result i32)
+ (func $opt1 (type $FUNCSIG$i) (result i32)
(return
(i32.const 0)
)
)
- (func $opt2 (result i32)
+ (func $opt2 (type $FUNCSIG$i) (result i32)
(return
(i32.const 1)
)
@@ -128,42 +128,42 @@
)
(block $label$0
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=16
(get_local $$0)
)
)
)
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=20
(get_local $$0)
)
)
)
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=24
(get_local $$0)
)
)
)
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=28
(get_local $$0)
)
)
)
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=32
(get_local $$0)
)
)
)
(br_if $label$0
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=36
(get_local $$0)
)
@@ -179,13 +179,13 @@
)
(block $label$1
(br_if $label$1
- (call_indirect $FUNCSIG_ii
+ (call_indirect $FUNCSIG$ii
(get_local $$1)
(get_local $$2)
)
)
(br_if $label$1
- (call_indirect $FUNCSIG_ii
+ (call_indirect $FUNCSIG$ii
(i32.load offset=44
(get_local $$0)
)
@@ -193,7 +193,7 @@
)
)
(br_if $label$1
- (call_indirect $FUNCSIG_ii
+ (call_indirect $FUNCSIG$ii
(i32.load offset=48
(get_local $$0)
)
@@ -210,13 +210,13 @@
)
(block $label$2
(br_if $label$2
- (call_indirect $FUNCSIG_ii
+ (call_indirect $FUNCSIG$ii
(get_local $$1)
(get_local $$2)
)
)
(br_if $label$2
- (call_indirect $FUNCSIG_ii
+ (call_indirect $FUNCSIG$ii
(i32.load offset=56
(get_local $$0)
)
@@ -226,7 +226,7 @@
(block $label$3
(br_if $label$3
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=60
(get_local $$0)
)
@@ -236,7 +236,7 @@
)
(br_if $label$3
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=64
(get_local $$0)
)
@@ -246,7 +246,7 @@
)
(br_if $label$3
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=68
(get_local $$0)
)
@@ -257,7 +257,7 @@
(block $label$4
(br_if $label$4
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=72
(get_local $$0)
)
@@ -267,7 +267,7 @@
)
(br_if $label$4
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=76
(get_local $$0)
)
@@ -277,7 +277,7 @@
)
(br_if $label$4
(i32.eq
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(i32.load offset=80
(get_local $$0)
)
diff --git a/test/llvm_autogenerated/call.wast b/test/llvm_autogenerated/call.wast
index cebd9dd6e..9f6c3dfb8 100644
--- a/test/llvm_autogenerated/call.wast
+++ b/test/llvm_autogenerated/call.wast
@@ -8,8 +8,6 @@
(type $FUNCSIG$v (func))
(type $FUNCSIG$ii (func (param i32) (result i32)))
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
- (type $FUNCSIG_v (func))
- (type $FUNCSIG_i (func (result i32)))
(import $i32_nullary "env" "i32_nullary" (result i32))
(import $i64_nullary "env" "i64_nullary" (result i64))
(import $float_nullary "env" "float_nullary" (result f32))
@@ -69,14 +67,14 @@
)
)
(func $call_indirect_void (param $$0 i32)
- (call_indirect $FUNCSIG_v
+ (call_indirect $FUNCSIG$v
(get_local $$0)
)
(return)
)
(func $call_indirect_i32 (param $$0 i32) (result i32)
(return
- (call_indirect $FUNCSIG_i
+ (call_indirect $FUNCSIG$i
(get_local $$0)
)
)