diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-06-29 14:22:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 07:22:54 -0700 |
commit | 6ab05d914bbee87dd4a26f218a04e7ea918a2271 (patch) | |
tree | 33b529093b0a9ec1dab8390e4d938bcad4d02445 /test | |
parent | 6a2d7f989065820476268a2382db2eccf72aadd7 (diff) | |
download | binaryen-6ab05d914bbee87dd4a26f218a04e7ea918a2271.tar.gz binaryen-6ab05d914bbee87dd4a26f218a04e7ea918a2271.tar.bz2 binaryen-6ab05d914bbee87dd4a26f218a04e7ea918a2271.zip |
Only set `supertype` if nominal typing is enabled (#3958)
The code for printing and emitting the experimental nominal type constructors
added in #3933 assumes that supertypes were only returned from `getSuperType`
when nominal typing was enabled. `getSuperType` in turn was assuming that the
supertype field would only be set if nominal typing was enabled, but this was
not the case. This bug caused use-after-free errors because equirecursive
canonicalization left the supertype field pointing to a temporary HeapTypeInfo
that would be freed at the end of parsing but then accessed during module
writing.
To fix the issue, only set `supertype` if nominal typing is enabled, as
originally intended.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/nominal-good.wast | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/test/lit/nominal-good.wast b/test/lit/nominal-good.wast index 8fff43d6a..4110fb96b 100644 --- a/test/lit/nominal-good.wast +++ b/test/lit/nominal-good.wast @@ -1,46 +1,66 @@ ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. -;; RUN: wasm-opt %s -all --nominal -S -o - | filecheck %s -;; RUN: wasm-opt %s -all --nominal --roundtrip -S -o - | filecheck %s +;; RUN: wasm-opt %s -all --nominal -S -o - | filecheck %s --check-prefix NOMINAL +;; RUN: wasm-opt %s -all --nominal --roundtrip -S -o - | filecheck %s --check-prefix NOMINAL +;; RUN: wasm-opt %s -all -S -o - | filecheck %s --check-prefix EQUIREC +;; RUN: wasm-opt %s -all --roundtrip -S -o - | filecheck %s --check-prefix EQUIREC (module - ;; CHECK: (type $super-struct (struct (field i32))) - ;; CHECK: (type $sub-struct (struct (field i32) (field i64)) (extends $super-struct)) - (type $sub-struct (struct i32 i64) (extends $super-struct)) + ;; NOMINAL: (type $super-struct (struct (field i32))) + ;; EQUIREC: (type $super-struct (struct (field i32))) (type $super-struct (struct i32)) - ;; CHECK: (type $super-array (array (ref $super-struct))) - ;; CHECK: (type $sub-array (array (ref $sub-struct)) (extends $super-array)) - (type $sub-array (array (ref $sub-struct)) (extends $super-array)) + ;; NOMINAL: (type $sub-struct (struct (field i32) (field i64)) (extends $super-struct)) + ;; EQUIREC: (type $sub-struct (struct (field i32) (field i64))) + (type $sub-struct (struct i32 i64) (extends $super-struct)) + + ;; NOMINAL: (type $super-array (array (ref $super-struct))) + ;; EQUIREC: (type $super-array (array (ref $super-struct))) (type $super-array (array (ref $super-struct))) - ;; TODO: signature types as well, once functions store their HeapTypes. + ;; NOMINAL: (type $sub-array (array (ref $sub-struct)) (extends $super-array)) + ;; EQUIREC: (type $sub-array (array (ref $sub-struct))) + (type $sub-array (array (ref $sub-struct)) (extends $super-array)) - ;; CHECK: (func $make-sub-struct (result (ref $sub-struct)) - ;; CHECK-NEXT: (unreachable) - ;; CHECK-NEXT: ) - (func $make-sub-struct (result (ref $sub-struct)) - (unreachable) - ) + ;; TODO: signature types as well, once functions store their HeapTypes. - ;; CHECK: (func $make-super-struct (result (ref $super-struct)) - ;; CHECK-NEXT: (call $make-sub-struct) - ;; CHECK-NEXT: ) + ;; NOMINAL: (func $make-super-struct (result (ref $super-struct)) + ;; NOMINAL-NEXT: (call $make-sub-struct) + ;; NOMINAL-NEXT: ) + ;; EQUIREC: (func $make-super-struct (result (ref $super-struct)) + ;; EQUIREC-NEXT: (call $make-sub-struct) + ;; EQUIREC-NEXT: ) (func $make-super-struct (result (ref $super-struct)) (call $make-sub-struct) ) - ;; CHECK: (func $make-sub-array (result (ref $sub-array)) - ;; CHECK-NEXT: (unreachable) - ;; CHECK-NEXT: ) - (func $make-sub-array (result (ref $sub-array)) + ;; NOMINAL: (func $make-sub-struct (result (ref $sub-struct)) + ;; NOMINAL-NEXT: (unreachable) + ;; NOMINAL-NEXT: ) + ;; EQUIREC: (func $make-sub-struct (result (ref $sub-struct)) + ;; EQUIREC-NEXT: (unreachable) + ;; EQUIREC-NEXT: ) + (func $make-sub-struct (result (ref $sub-struct)) (unreachable) ) - ;; CHECK: (func $make-super-array (result (ref $super-array)) - ;; CHECK-NEXT: (call $make-sub-array) - ;; CHECK-NEXT: ) + ;; NOMINAL: (func $make-super-array (result (ref $super-array)) + ;; NOMINAL-NEXT: (call $make-sub-array) + ;; NOMINAL-NEXT: ) + ;; EQUIREC: (func $make-super-array (result (ref $super-array)) + ;; EQUIREC-NEXT: (call $make-sub-array) + ;; EQUIREC-NEXT: ) (func $make-super-array (result (ref $super-array)) (call $make-sub-array) ) + + ;; NOMINAL: (func $make-sub-array (result (ref $sub-array)) + ;; NOMINAL-NEXT: (unreachable) + ;; NOMINAL-NEXT: ) + ;; EQUIREC: (func $make-sub-array (result (ref $sub-array)) + ;; EQUIREC-NEXT: (unreachable) + ;; EQUIREC-NEXT: ) + (func $make-sub-array (result (ref $sub-array)) + (unreachable) + ) ) |