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
6 changes: 5 additions & 1 deletion src/ir/subtype-exprs.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
return;
}
const auto& fields = curr->ref->type.getHeapType().getStruct().fields;
self()->noteSubtype(curr->expected, fields[curr->index].type);
auto expectedType = fields[curr->index].type;
if (expectedType.isRef()) {
expectedType = Type(HeapTypes::eq.getBasic(Shared), Nullable);
}
self()->noteSubtype(curr->expected, expectedType);
}
void visitWaitqueueNew(WaitqueueNew* curr) {}
void visitWaitqueueNotify(WaitqueueNotify* curr) {
Expand Down
13 changes: 0 additions & 13 deletions src/passes/TypeRefining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,19 +568,6 @@ struct TypeRefining : public Pass {
curr->replacement = fixType(curr->replacement, fieldType);
}

void visitStructWait(StructWait* curr) {
if (curr->ref->type == Type::unreachable) {
return;
}
auto type = curr->ref->type.getHeapType();
if (type.isBottom()) {
return;
}

auto fieldType = type.getStruct().fields[curr->index].type;
curr->expected = fixType(curr->expected, fieldType);
}

bool refinalize = false;

// Fix up a given value so it fits into the type the location it is
Expand Down
5 changes: 4 additions & 1 deletion src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3739,8 +3739,11 @@ void FunctionValidator::visitStructWait(StructWait* curr) {
return;
}

auto expectedType = field.type.isRef()
? Type(HeapTypes::eq.getBasic(Shared), Nullable)
: field.type;
shouldBeSubType(curr->expected->type,
field.type,
expectedType,
curr,
"struct.wait expected value must match the field immediate");
}
Expand Down
49 changes: 42 additions & 7 deletions test/lit/passes/type-refining-gufa-rmw.wast
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@
;; NRML-NEXT: )
;; NRML-NEXT: )
;; NRML-NEXT: (drop
;; NRML-NEXT: (block ;; (replaces unreachable StructCmpxchg we can't emit)
;; NRML-NEXT: (drop
;; NRML-NEXT: (unreachable)
;; NRML-NEXT: )
;; NRML-NEXT: (drop
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: )
;; NRML-NEXT: (drop
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: )
;; NRML-NEXT: (unreachable)
;; NRML-NEXT: )
;; NRML-NEXT: )
;; NRML-NEXT: (drop
;; NRML-NEXT: (struct.wait $struct 0
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: (unreachable)
Expand Down Expand Up @@ -463,15 +477,24 @@
;; GUFA-NEXT: )
;; GUFA-NEXT: )
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (block ;; (replaces unreachable StructCmpxchg we can't emit)
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (unreachable)
;; GUFA-NEXT: )
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: )
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: )
;; GUFA-NEXT: (unreachable)
;; GUFA-NEXT: )
;; GUFA-NEXT: )
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (struct.wait $struct 0
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: (unreachable)
;; GUFA-NEXT: (block (result (ref null (shared none)))
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: )
;; GUFA-NEXT: (ref.null (shared none))
;; GUFA-NEXT: )
;; GUFA-NEXT: (local.get $struct)
Comment thread
stevenfontanella marked this conversation as resolved.
;; GUFA-NEXT: (i64.const -1)
;; GUFA-NEXT: )
;; GUFA-NEXT: )
Expand All @@ -492,7 +515,19 @@
(local.get $struct)
)
)
;; Likewise with struct.wait.
;; The fixup to null does *not* happen for the `expected` ref of a cmpxchg,
;; because the expected value is allowed to be a supertype of the field's
;; type. i.e. (local.get $struct) remains valid here even after the field's
;; type is refined.
(drop
(struct.atomic.rmw.cmpxchg acqrel acqrel $struct 0
(unreachable)
(local.get $struct)
(local.get $struct)
)
)
;; Ditto for struct.wait, the `expected` ref may remain a supertype and
;; doesn't need to be fixed up.
(drop
(struct.wait $struct 0
(local.get $struct)
Expand Down
Loading