summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-04-21 12:40:51 -0700
committerGitHub <noreply@github.com>2021-04-21 12:40:51 -0700
commita72f5b7f440a73c23b7f1b0532446584d4da0854 (patch)
tree6043f4c06c2cb358eb940dfbfc614c0f177069d8 /test
parentb4e96d8dd6fded302b7c6be8a34b0a75773737b6 (diff)
downloadbinaryen-a72f5b7f440a73c23b7f1b0532446584d4da0854.tar.gz
binaryen-a72f5b7f440a73c23b7f1b0532446584d4da0854.tar.bz2
binaryen-a72f5b7f440a73c23b7f1b0532446584d4da0854.zip
[Wasm GC] Fix handleNonDefaultableLocals on tees (#3830)
When we change a local's type, as we do in that method when we turn a non-nullable (invalid) local into a nullable (valid) one, we must update tees as well as gets - their type must match the changed local type, and we must cast them so that their users do not see a change.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/dae-gc.wast49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/lit/passes/dae-gc.wast b/test/lit/passes/dae-gc.wast
new file mode 100644
index 000000000..87e480cc8
--- /dev/null
+++ b/test/lit/passes/dae-gc.wast
@@ -0,0 +1,49 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+;; RUN: wasm-opt %s -all --dae -S -o - | filecheck %s
+
+(module
+ ;; CHECK: (func $foo
+ ;; CHECK-NEXT: (call $bar)
+ ;; CHECK-NEXT: )
+ (func $foo
+ (call $bar
+ (i31.new
+ (i32.const 1)
+ )
+ )
+ )
+ ;; CHECK: (func $bar
+ ;; CHECK-NEXT: (local $0 (ref null i31))
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (ref.as_non_null
+ ;; CHECK-NEXT: (local.tee $0
+ ;; CHECK-NEXT: (i31.new
+ ;; CHECK-NEXT: (i32.const 2)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.tee $0
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $bar (param $0 i31ref)
+ (drop
+ ;; after the parameter is removed, we create a nullable local to replace it,
+ ;; and must update the tee's type accordingly to avoid a validation error,
+ ;; and also add a ref.as_non_null so that the outside still receives the
+ ;; same type as before
+ (local.tee $0
+ (i31.new
+ (i32.const 2)
+ )
+ )
+ )
+ ;; test for an unreachable tee, whose type must be unreachable even after
+ ;; the change (the tee would need to be dropped if it were not unreachable,
+ ;; so the correctness in this case is visible in the output)
+ (local.tee $0
+ (unreachable)
+ )
+ )
+)