summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-01-04 13:47:34 -0800
committerGitHub <noreply@github.com>2023-01-04 21:47:34 +0000
commitfb434f95de125bbd1c3f145880d32395d86cfef2 (patch)
tree7b06963f405a50009bc7860024432f3ea969eb55
parenta96fe1a8422140072db7ad7db421378b87898a0d (diff)
downloadbinaryen-fb434f95de125bbd1c3f145880d32395d86cfef2.tar.gz
binaryen-fb434f95de125bbd1c3f145880d32395d86cfef2.tar.bz2
binaryen-fb434f95de125bbd1c3f145880d32395d86cfef2.zip
[Wasm GC] Ignore call.without.effects for closed world validation (#5392)
It is implemented as an import, but functionally it is a call within the module, so it does not cause types to be public.
-rw-r--r--src/ir/module-utils.cpp10
-rw-r--r--test/lit/validation/closed-world-interface-intrinsics.wast46
2 files changed, 54 insertions, 2 deletions
diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp
index 482753b87..0cdff0955 100644
--- a/src/ir/module-utils.cpp
+++ b/src/ir/module-utils.cpp
@@ -15,6 +15,7 @@
*/
#include "module-utils.h"
+#include "ir/intrinsics.h"
#include "support/insert_ordered.h"
#include "support/topological_sort.h"
@@ -245,8 +246,13 @@ InsertOrderedSet<HeapType> getPublicTypeSet(Module& wasm) {
notePublic(global->type.getHeapType());
}
});
- ModuleUtils::iterImportedFunctions(
- wasm, [&](Function* func) { notePublic(func->type); });
+ ModuleUtils::iterImportedFunctions(wasm, [&](Function* func) {
+ // We can ignore call.without.effects, which is implemented as an import but
+ // functionally is a call within the module.
+ if (!Intrinsics(wasm).isCallWithoutEffects(func)) {
+ notePublic(func->type);
+ }
+ });
for (auto& ex : wasm.exports) {
switch (ex->kind) {
case ExternalKind::Function: {
diff --git a/test/lit/validation/closed-world-interface-intrinsics.wast b/test/lit/validation/closed-world-interface-intrinsics.wast
new file mode 100644
index 000000000..0b3515acc
--- /dev/null
+++ b/test/lit/validation/closed-world-interface-intrinsics.wast
@@ -0,0 +1,46 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: foreach %s %t wasm-opt -all --closed-world -S -o - | filecheck %s
+
+;; Test that we do not error on call.without.effects despite it being an import.
+;; call.without.effects does not make the types in it public, and so it can
+;; validate with --closed-world.
+
+(module
+ ;; CHECK: (type $struct (struct (field i32)))
+ (type $struct (struct i32))
+
+ ;; CHECK: (type $ref|$struct|_funcref_=>_none (func (param (ref $struct) funcref)))
+
+ ;; CHECK: (type $none_=>_none (func))
+
+ ;; CHECK: (type $ref|$struct|_=>_none (func (param (ref $struct))))
+
+ ;; CHECK: (import "binaryen-intrinsics" "call.without.effects" (func $cwe (param (ref $struct) funcref)))
+ (import "binaryen-intrinsics" "call.without.effects" (func $cwe (param (ref $struct)) (param funcref)))
+
+ ;; CHECK: (elem declare func $func)
+
+ ;; CHECK: (func $test (type $none_=>_none)
+ ;; CHECK-NEXT: (call $cwe
+ ;; CHECK-NEXT: (struct.new $struct
+ ;; CHECK-NEXT: (i32.const 100)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (ref.func $func)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $test
+ (call $cwe
+ (struct.new $struct
+ (i32.const 100)
+ )
+ (ref.func $func)
+ )
+ )
+
+ ;; CHECK: (func $func (type $ref|$struct|_=>_none) (param $ref (ref $struct))
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: )
+ (func $func (param $ref (ref $struct))
+ )
+)