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
10 changes: 10 additions & 0 deletions src/passes/Heap2Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,11 @@ struct Struct2Local : PostWalker<Struct2Local> {
return;
}

if (curr->type == Type::unreachable) {
// As with RefGetDesc and StructGet, above.
return;
}

[[maybe_unused]] auto& field = fields[curr->index];
auto type = curr->type;
assert(type == field.type);
Expand Down Expand Up @@ -1108,6 +1113,11 @@ struct Struct2Local : PostWalker<Struct2Local> {
return;
}

if (curr->type == Type::unreachable) {
// As with RefGetDesc and StructGet, above.
return;
}

[[maybe_unused]] auto& field = fields[curr->index];
auto type = curr->type;
assert(type == field.type);
Expand Down
57 changes: 57 additions & 0 deletions test/lit/passes/heap2local-rmw.wast
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,61 @@
(i32.const 2)
)
)

;; CHECK: (func $rmw-unreachable-value (type $1) (result i32)
;; CHECK-NEXT: (local $0 i32)
;; CHECK-NEXT: (block ;; (replaces unreachable StructRMW we can't emit)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (block (result nullref)
;; CHECK-NEXT: (local.set $0
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $rmw-unreachable-value (result i32)
;; When the value is unreachable, the whole expression is unreachable.
;; We should not attempt to optimize this (it would hit an assertion
;; on type == field.type since unreachable != i32).
(struct.atomic.rmw.add $i32 0
(struct.new_default $i32)
(unreachable)
)
)

;; CHECK: (func $cmpxchg-unreachable-expected (type $1) (result i32)
;; CHECK-NEXT: (local $0 i32)
;; CHECK-NEXT: (block ;; (replaces unreachable StructCmpxchg we can't emit)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (block (result nullref)
;; CHECK-NEXT: (local.set $0
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $cmpxchg-unreachable-expected (result i32)
;; When the expected operand is unreachable, the whole expression is
;; unreachable. We should not attempt to optimize this.
(struct.atomic.rmw.cmpxchg $i32 0
(struct.new_default $i32)
(unreachable)
(i32.const 1)
)
)
)
Loading