Skip to content

Commit c64410a

Browse files
authored
GUFA: Ignore unreachable packed reads (#8564)
Without this early return, we'd try to find the packed size in bits of the unreachable type, which asserts.
1 parent 88a07e0 commit c64410a

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/ir/possible-contents.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,31 +3136,33 @@ void Flower::filterPackedDataReads(PossibleContents& contents,
31363136
Expression* ref;
31373137
Index index;
31383138
unsigned bytes = 0;
3139-
Type resultType = Type::none;
31403139
if (auto* get = expr->dynCast<StructGet>()) {
31413140
signed_ = get->signed_;
31423141
ref = get->ref;
31433142
index = get->index;
3144-
resultType = get->type;
31453143
} else if (auto* get = expr->dynCast<ArrayGet>()) {
31463144
signed_ = get->signed_;
31473145
ref = get->ref;
31483146
// Arrays are treated as having a single field.
31493147
index = 0;
3150-
resultType = get->type;
31513148
} else if (auto* load = expr->dynCast<ArrayLoad>()) {
31523149
signed_ = load->signed_;
31533150
ref = load->ref;
31543151
index = 0;
31553152
bytes = load->bytes;
3156-
resultType = load->type;
31573153
} else {
31583154
WASM_UNREACHABLE("bad packed read");
31593155
}
31603156
if (!signed_) {
31613157
return;
31623158
}
31633159

3160+
Type resultType = expr->type;
3161+
if (resultType == Type::unreachable) {
3162+
// This read never executes.
3163+
return;
3164+
}
3165+
31643166
// If there is no struct or array to read, no value will ever be returned.
31653167
if (ref->type.isNull()) {
31663168
contents = PossibleContents::none();

test/lit/passes/gufa-refs.wast

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6141,6 +6141,25 @@
61416141
)
61426142
)
61436143
)
6144+
6145+
;; CHECK: (func $unreachable (type $1)
6146+
;; CHECK-NEXT: (array.get_s $array
6147+
;; CHECK-NEXT: (array.new_default $array
6148+
;; CHECK-NEXT: (i32.const 0)
6149+
;; CHECK-NEXT: )
6150+
;; CHECK-NEXT: (unreachable)
6151+
;; CHECK-NEXT: )
6152+
;; CHECK-NEXT: )
6153+
(func $unreachable
6154+
;; This array.get is unreachable, and when handling packing we should not
6155+
;; error.
6156+
(array.get_s $array
6157+
(array.new_default $array
6158+
(i32.const 0)
6159+
)
6160+
(unreachable)
6161+
)
6162+
)
61446163
)
61456164

61466165
;; Atomic accesses require special handling

0 commit comments

Comments
 (0)