Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5761,7 +5761,7 @@ struct OptimizeInstructions
}
}

if (!neverFold) {
if (!neverFold && curr->condition->type != Type::unreachable) {
// Identical code on both arms can be folded out, e.g.
//
// (select
Expand Down
3 changes: 2 additions & 1 deletion src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4340,7 +4340,8 @@ void FunctionValidator::visitContNew(ContNew* curr) {
auto cont = curr->type.getHeapType().getContinuation();
assert(cont.type.isSignature());

shouldBeTrue(HeapType::isSubType(curr->func->type.getHeapType(), cont.type),
shouldBeTrue(curr->func->type.isRef() &&
HeapType::isSubType(curr->func->type.getHeapType(), cont.type),
curr,
"cont.new function reference must be a subtype");
}
Expand Down
25 changes: 25 additions & 0 deletions test/gtest/validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,28 @@ TEST(ValidatorTest, UnreachableCastDescEq) {
WasmValidator::FlagValues::Globally | WasmValidator::FlagValues::Quiet;
EXPECT_FALSE(WasmValidator{}.validate(func.get(), module, flags));
}

TEST(ValidatorTest, ContNewUnreachable) {
Module module;
module.features = FeatureSet::All;
Builder builder(module);

auto sig = Signature(Type::none, Type::none);
module.addFunction(builder.makeFunction(
"f", {}, Signature(Type::none, Type::none), {}, builder.makeUnreachable()));

auto contType = HeapType(Continuation(sig));
auto contRefType = Type(contType, NonNullable);

// Create a cont.new with a concrete type despite an unreachable child. This
// is not valid, but we should not crash while validating it.
auto* contNew = builder.makeContNew(contType, builder.makeUnreachable());
contNew->type = contRefType;

auto testFunc = builder.makeFunction(
"test", {}, Signature(Type::none, contRefType), {}, contNew);

auto flags =
WasmValidator::FlagValues::Globally | WasmValidator::FlagValues::Quiet;
EXPECT_FALSE(WasmValidator{}.validate(testFunc.get(), module, flags));
}
6 changes: 4 additions & 2 deletions test/lit/passes/legalize-js-interface-exported-helpers.wast
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
(module
(export "get_i64" (func $get_i64))
(import "env" "imported" (func $imported (result i64)))
(export "__set_temp_ret" (func $__set_temp_ret))
(export "__get_temp_ret" (func $__get_temp_ret))
;; CHECK: (type $0 (func (result i32)))

;; CHECK: (type $1 (func (result i64)))
Expand All @@ -20,6 +18,10 @@

;; CHECK: (export "get_i64" (func $legalstub$get_i64))

;; CHECK: (export "__set_temp_ret" (func $__set_temp_ret))
(export "__set_temp_ret" (func $__set_temp_ret))
;; CHECK: (export "__get_temp_ret" (func $__get_temp_ret))
(export "__get_temp_ret" (func $__get_temp_ret))
;; CHECK: (func $get_i64 (result i64)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (call $legalfunc$imported)
Expand Down
12 changes: 7 additions & 5 deletions test/lit/passes/optimize-instructions-gc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3695,13 +3695,15 @@

;; CHECK: (func $comp-i31-struct-unreachable-if (type $4)
;; CHECK-NEXT: (ref.eq
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (if (result i32)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (if (result (ref i31))
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (ref.i31
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
Expand Down
31 changes: 31 additions & 0 deletions test/lit/passes/optimize-instructions-mvp.wast
Original file line number Diff line number Diff line change
Expand Up @@ -16046,6 +16046,37 @@
)
)
)
;; CHECK: (func $ternary-identical-arms-if-unreachable (param $x i32) (param $y i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (if (result i32)
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (i32.eqz
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (i32.eqz
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $ternary-identical-arms-if-unreachable (param $x i32) (param $y i32)
(drop
;; Leave this to DCE instead of optimizing.
(if (result i32)
(unreachable)
(then
(i32.eqz (local.get $x))
)
(else
(i32.eqz (local.get $y))
)
)
)
)
;; CHECK: (func $ternary-identical-arms-type-change (param $x f64) (param $y f64) (param $z i32)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (f32.demote_f64
Expand Down
Loading