diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index 905349f1c68..10b01f986dc 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -3136,24 +3136,20 @@ void Flower::filterPackedDataReads(PossibleContents& contents, Expression* ref; Index index; unsigned bytes = 0; - Type resultType = Type::none; if (auto* get = expr->dynCast()) { signed_ = get->signed_; ref = get->ref; index = get->index; - resultType = get->type; } else if (auto* get = expr->dynCast()) { signed_ = get->signed_; ref = get->ref; // Arrays are treated as having a single field. index = 0; - resultType = get->type; } else if (auto* load = expr->dynCast()) { signed_ = load->signed_; ref = load->ref; index = 0; bytes = load->bytes; - resultType = load->type; } else { WASM_UNREACHABLE("bad packed read"); } @@ -3161,6 +3157,12 @@ void Flower::filterPackedDataReads(PossibleContents& contents, return; } + Type resultType = expr->type; + if (resultType == Type::unreachable) { + // This read never executes. + return; + } + // If there is no struct or array to read, no value will ever be returned. if (ref->type.isNull()) { contents = PossibleContents::none(); diff --git a/test/lit/passes/gufa-refs.wast b/test/lit/passes/gufa-refs.wast index 9907fd90c23..14f362f5e3d 100644 --- a/test/lit/passes/gufa-refs.wast +++ b/test/lit/passes/gufa-refs.wast @@ -6141,6 +6141,25 @@ ) ) ) + + ;; CHECK: (func $unreachable (type $1) + ;; CHECK-NEXT: (array.get_s $array + ;; CHECK-NEXT: (array.new_default $array + ;; CHECK-NEXT: (i32.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (unreachable) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $unreachable + ;; This array.get is unreachable, and when handling packing we should not + ;; error. + (array.get_s $array + (array.new_default $array + (i32.const 0) + ) + (unreachable) + ) + ) ) ;; Atomic accesses require special handling