summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/literal-utils.h14
-rw-r--r--test/passes/vacuum_all-features.txt7
-rw-r--r--test/passes/vacuum_all-features.wast28
3 files changed, 46 insertions, 3 deletions
diff --git a/src/ir/literal-utils.h b/src/ir/literal-utils.h
index fbe5b3716..498085796 100644
--- a/src/ir/literal-utils.h
+++ b/src/ir/literal-utils.h
@@ -32,9 +32,17 @@ inline Expression* makeFromInt32(int32_t x, Type type, Module& wasm) {
}
inline bool canMakeZero(Type type) {
- // We can make a "zero" - a 0, or a null, or a trivial rtt, etc. - for pretty
- // much anything except a non-nullable reference type.
- return !type.isRef() || type.isNullable();
+ if (type.isRef() && !type.isNullable()) {
+ return false;
+ }
+ if (type.isTuple()) {
+ for (auto t : type) {
+ if (!canMakeZero(t)) {
+ return false;
+ }
+ }
+ }
+ return true;
}
inline Expression* makeZero(Type type, Module& wasm) {
diff --git a/test/passes/vacuum_all-features.txt b/test/passes/vacuum_all-features.txt
index c7c22572a..7de8ffa42 100644
--- a/test/passes/vacuum_all-features.txt
+++ b/test/passes/vacuum_all-features.txt
@@ -494,3 +494,10 @@
(nop)
)
)
+(module
+ (type $none_=>_none (func))
+ (global $global$0 (mut i32) (i32.const 10))
+ (func $1
+ (nop)
+ )
+)
diff --git a/test/passes/vacuum_all-features.wast b/test/passes/vacuum_all-features.wast
index 46678bd8e..c074fe234 100644
--- a/test/passes/vacuum_all-features.wast
+++ b/test/passes/vacuum_all-features.wast
@@ -885,3 +885,31 @@
)
)
)
+(module
+ (global $global$0 (mut i32) (i32.const 10))
+ (func $1
+ (drop
+ (block $block (result funcref i32)
+ ;; we can vaccum out all parts of this block: the br_if is not taken, there
+ ;; is a nop, and the tuple at the end goes to a dropped block anyhow. this
+ ;; test specifically verifies handling of tuples containing non-nullable
+ ;; types, for which we try to create a zero in an intermediate step along
+ ;; the way.
+ (drop
+ (br_if $block
+ (tuple.make
+ (ref.func $1)
+ (i32.const 0)
+ )
+ (i32.const 0)
+ )
+ )
+ (nop)
+ (tuple.make
+ (ref.func $1)
+ (i32.const 1)
+ )
+ )
+ )
+ )
+)