summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-06-25 09:35:17 -0700
committerGitHub <noreply@github.com>2024-06-25 09:35:17 -0700
commit4cd8b61c5d4817f753a54ef9f501db66969e310f (patch)
tree288d6df8bdbeeb7c4cb62ea92f36d8fabbe0d8ea /test
parent0a0ee6fe67f10a22503a964c31161c4584286d87 (diff)
downloadbinaryen-4cd8b61c5d4817f753a54ef9f501db66969e310f.tar.gz
binaryen-4cd8b61c5d4817f753a54ef9f501db66969e310f.tar.bz2
binaryen-4cd8b61c5d4817f753a54ef9f501db66969e310f.zip
[threads] Validate shared-to-unshared edges in heap types (#6698)
Add spec tests checking validation for structs and arrays.
Diffstat (limited to 'test')
-rw-r--r--test/lit/passes/type-merging-shared.wast8
-rw-r--r--test/spec/shared-array.wast69
-rw-r--r--test/spec/shared-struct.wast69
3 files changed, 142 insertions, 4 deletions
diff --git a/test/lit/passes/type-merging-shared.wast b/test/lit/passes/type-merging-shared.wast
index 2457cd572..e02815079 100644
--- a/test/lit/passes/type-merging-shared.wast
+++ b/test/lit/passes/type-merging-shared.wast
@@ -79,11 +79,11 @@
(module
;; Shared and unshared basic heap types similarly cannot be merged.
;; CHECK: (rec
- ;; CHECK-NEXT: (type $A' (shared (struct (field anyref))))
+ ;; CHECK-NEXT: (type $A' (struct (field anyref)))
- ;; CHECK: (type $A (shared (struct (field (ref null (shared any))))))
- (type $A (shared (struct (ref null (shared any)))))
- (type $A' (shared (struct (ref null any))))
+ ;; CHECK: (type $A (struct (field (ref null (shared any)))))
+ (type $A (struct (ref null (shared any))))
+ (type $A' (struct (ref null any)))
;; CHECK: (type $2 (func))
diff --git a/test/spec/shared-array.wast b/test/spec/shared-array.wast
new file mode 100644
index 000000000..a687c1d36
--- /dev/null
+++ b/test/spec/shared-array.wast
@@ -0,0 +1,69 @@
+;; Shared array declaration syntax
+(module
+ (type (shared (array i8)))
+ (type (sub final (shared (array i8))))
+ (rec
+ (type (sub final (shared (array i8))))
+ )
+
+ (global (ref 0) (array.new_default 1 (i32.const 1)))
+ (global (ref 1) (array.new_default 2 (i32.const 1)))
+ (global (ref 2) (array.new_default 0 (i32.const 1)))
+)
+
+;; Shared arrays are distinct from non-shared arrays
+(assert_invalid
+ (module
+ (type (shared (array i8)))
+ (type (array i8))
+
+ (global (ref 0) (array.new_default 1 (i32.const 1)))
+ )
+ "not a subtype"
+)
+
+(assert_invalid
+ (module
+ (type (shared (array i8)))
+ (type (array i8))
+
+ (global (ref 1) (array.new 0))
+ )
+ "not a subtype"
+)
+
+;; Shared arrays may not be subtypes of non-shared arrays
+(assert_invalid
+ (module
+ (type (sub (array i8)))
+ (type (sub 0 (shared (array i8))))
+ )
+ "invalid supertype"
+)
+
+;; Non-shared arrays may not be subtypes of shared arrays
+(assert_invalid
+ (module
+ (type (sub (shared (array i8))))
+ (type (sub 0 (array i8)))
+ )
+ "invalid supertype"
+)
+
+;; Shared arrays may not contain non-shared references
+(assert_invalid
+ (module
+ (type (shared (array anyref)))
+ )
+ "invalid field"
+)
+
+;; But they may contain shared references
+(module
+ (type (shared (array (ref null (shared any)))))
+)
+
+;; Non-shared arrays may contain shared references
+(module
+ (type (array (ref null (shared any))))
+)
diff --git a/test/spec/shared-struct.wast b/test/spec/shared-struct.wast
new file mode 100644
index 000000000..b2c82caff
--- /dev/null
+++ b/test/spec/shared-struct.wast
@@ -0,0 +1,69 @@
+;; Shared struct declaration syntax
+(module
+ (type (shared (struct)))
+ (type (sub final (shared (struct))))
+ (rec
+ (type (sub final (shared (struct))))
+ )
+
+ (global (ref 0) (struct.new 1))
+ (global (ref 1) (struct.new 2))
+ (global (ref 2) (struct.new 0))
+)
+
+;; Shared structs are distinct from non-shared structs
+(assert_invalid
+ (module
+ (type (shared (struct)))
+ (type (struct))
+
+ (global (ref 0) (struct.new 1))
+ )
+ "not a subtype"
+)
+
+(assert_invalid
+ (module
+ (type (shared (struct)))
+ (type (struct))
+
+ (global (ref 1) (struct.new 0))
+ )
+ "not a subtype"
+)
+
+;; Shared structs may not be subtypes of non-shared structs
+(assert_invalid
+ (module
+ (type (sub (struct)))
+ (type (sub 0 (shared (struct))))
+ )
+ "invalid supertype"
+)
+
+;; Non-shared structs may not be subtypes of shared structs
+(assert_invalid
+ (module
+ (type (sub (shared (struct))))
+ (type (sub 0 (struct)))
+ )
+ "invalid supertype"
+)
+
+;; Shared structs may not contain non-shared references
+(assert_invalid
+ (module
+ (type (shared (struct anyref)))
+ )
+ "invalid field"
+)
+
+;; But they may contain shared references
+(module
+ (type (shared (struct (ref null (shared any)))))
+)
+
+;; Non-shared structs may contain shared references
+(module
+ (type (struct (ref null (shared any))))
+)