diff options
author | Alon Zakai <azakai@google.com> | 2024-12-04 12:47:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-04 12:47:15 -0800 |
commit | 47f9a78e5d423638a3dceeed2cb6449766f6f75e (patch) | |
tree | 4b20ccb218ce2cc3de682ad9fde7b3201c4ac312 /test | |
parent | 87f9dac127b387715d8d96ac7ec8fd469d8c2dab (diff) | |
download | binaryen-47f9a78e5d423638a3dceeed2cb6449766f6f75e.tar.gz binaryen-47f9a78e5d423638a3dceeed2cb6449766f6f75e.tar.bz2 binaryen-47f9a78e5d423638a3dceeed2cb6449766f6f75e.zip |
Fix GUFA on calls to function refs in open world (#7135)
In open world we must assume that a funcref that escapes to the outside
might be called.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/gufa-closed-open.wast | 68 | ||||
-rw-r--r-- | test/lit/passes/gufa-refs.wast | 5 | ||||
-rw-r--r-- | test/lit/passes/gufa.wast | 5 |
3 files changed, 76 insertions, 2 deletions
diff --git a/test/lit/passes/gufa-closed-open.wast b/test/lit/passes/gufa-closed-open.wast new file mode 100644 index 000000000..47add9df5 --- /dev/null +++ b/test/lit/passes/gufa-closed-open.wast @@ -0,0 +1,68 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-opt -all --gufa -S -o - | filecheck %s --check-prefix OPEND +;; RUN: foreach %s %t wasm-opt -all --gufa --closed-world -S -o - | filecheck %s --check-prefix CLOSE + +;; Compare behavior on closed and open world. In open world we must assume that +;; funcrefs, for example, can be called from outside. + +(module + ;; OPEND: (type $0 (func (param funcref))) + + ;; OPEND: (type $1 (func)) + + ;; OPEND: (type $2 (func (param i32))) + + ;; OPEND: (import "fuzzing-support" "call-ref-catch" (func $external-caller (type $0) (param funcref))) + ;; CLOSE: (type $0 (func (param funcref))) + + ;; CLOSE: (type $1 (func)) + + ;; CLOSE: (type $2 (func (param i32))) + + ;; CLOSE: (import "fuzzing-support" "call-ref-catch" (func $external-caller (type $0) (param funcref))) + (import "fuzzing-support" "call-ref-catch" (func $external-caller (param funcref))) + + ;; OPEND: (elem declare func $func) + + ;; OPEND: (export "call-import" (func $call-import)) + + ;; OPEND: (func $call-import (type $1) + ;; OPEND-NEXT: (call $external-caller + ;; OPEND-NEXT: (ref.func $func) + ;; OPEND-NEXT: ) + ;; OPEND-NEXT: ) + ;; CLOSE: (elem declare func $func) + + ;; CLOSE: (export "call-import" (func $call-import)) + + ;; CLOSE: (func $call-import (type $1) + ;; CLOSE-NEXT: (call $external-caller + ;; CLOSE-NEXT: (ref.func $func) + ;; CLOSE-NEXT: ) + ;; CLOSE-NEXT: ) + (func $call-import (export "call-import") + ;; Send a reference to $func to the outside, which may call it. + (call $external-caller + (ref.func $func) + ) + ) + + ;; OPEND: (func $func (type $2) (param $0 i32) + ;; OPEND-NEXT: (drop + ;; OPEND-NEXT: (local.get $0) + ;; OPEND-NEXT: ) + ;; OPEND-NEXT: ) + ;; CLOSE: (func $func (type $2) (param $0 i32) + ;; CLOSE-NEXT: (drop + ;; CLOSE-NEXT: (unreachable) + ;; CLOSE-NEXT: ) + ;; CLOSE-NEXT: ) + (func $func (param $0 i32) + ;; This is called from the outside, so this is not dead code, and nothing + ;; should change here in open world. In closed world, this can become an + ;; unreachable, since nothing can call it. + (drop + (local.get $0) + ) + ) +) diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index 9772745bc..80fd32386 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -1,5 +1,8 @@ ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; RUN: foreach %s %t wasm-opt -all --gufa -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt -all --gufa --closed-world -S -o - | filecheck %s + +;; Closed-world is applied here to avoid treating all ref.funcs as callable +;; from outside (and this is the more important mode to test on). (module ;; CHECK: (type $struct (struct)) diff --git a/test/lit/passes/gufa.wast b/test/lit/passes/gufa.wast index fcb60310a..721c27eeb 100644 --- a/test/lit/passes/gufa.wast +++ b/test/lit/passes/gufa.wast @@ -1,5 +1,8 @@ ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. -;; RUN: foreach %s %t wasm-opt -all --gufa -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt -all --gufa --closed-world -S -o - | filecheck %s + +;; Closed-world is applied here to avoid treating all ref.funcs as callable +;; from outside (and this is the more important mode to test on). (module ;; CHECK: (type $0 (func (result i32))) |