Skip to content

Commit ef4cbbe

Browse files
authored
Validate descriptor clause forward references (#8611)
When the descriptor clause on a type definition was a forward reference to a future rec group, we previously failed an assertion that it was not a temporary type. Replace this assertion with a validation check. Fixes #8606.
1 parent a7d3f18 commit ef4cbbe

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/wasm-type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ struct TypeBuilder {
917917
NonStructDescribes,
918918
// The described type is an invalid forward reference.
919919
ForwardDescribesReference,
920+
// The descriptor type is an invalid forward reference.
921+
ForwardDescriptorReference,
920922
// The described type does not have this type as a descriptor.
921923
MismatchedDescribes,
922924
// A descriptor clause on a non-struct type.

src/wasm/wasm-type.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,8 @@ std::ostream& operator<<(std::ostream& os,
15281528
return os << "Describes clause on a non-struct type";
15291529
case TypeBuilder::ErrorReasonKind::ForwardDescribesReference:
15301530
return os << "Describes clause is a forward reference";
1531+
case TypeBuilder::ErrorReasonKind::ForwardDescriptorReference:
1532+
return os << "Descriptor clause is a forward reference";
15311533
case TypeBuilder::ErrorReasonKind::MismatchedDescribes:
15321534
return os << "Described type is not a matching descriptor";
15331535
case TypeBuilder::ErrorReasonKind::NonStructDescriptor:
@@ -2509,7 +2511,6 @@ validateTypeInfo(HeapTypeInfo& info,
25092511
if (info.kind != HeapTypeKind::Struct) {
25102512
return TypeBuilder::ErrorReasonKind::NonStructDescribes;
25112513
}
2512-
assert(desc->isTemp && "unexpected canonical described type");
25132514
if (!seenTypes.contains(HeapType(uintptr_t(desc)))) {
25142515
return TypeBuilder::ErrorReasonKind::ForwardDescribesReference;
25152516
}
@@ -2654,6 +2655,14 @@ buildRecGroup(std::unique_ptr<RecGroupInfo>&& groupInfo,
26542655
i, TypeBuilder::ErrorReasonKind::ForwardChildReference}};
26552656
}
26562657
}
2658+
if (auto desc = type.getDescriptorType()) {
2659+
if (isTemp(*desc) && !seenTypes.contains(*desc)) {
2660+
return {TypeBuilder::Error{
2661+
i, TypeBuilder::ErrorReasonKind::ForwardDescriptorReference}};
2662+
}
2663+
}
2664+
// Describes clauses were already checked as we validated each type in the
2665+
// group.
26572666
}
26582667

26592668
// The rec group is valid, so we can try to move the group into the global rec
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
;; RUN: not wasm-opt -all %s 2>&1 | filecheck %s
2+
3+
(module
4+
;; These types should be in the same rec group!
5+
;; CHECK: invalid type: Descriptor clause is a forward reference
6+
(type $Default (descriptor $Default.desc) (struct (field i32)))
7+
(type $Default.desc (describes $Default) (struct (field (ref extern))))
8+
)

0 commit comments

Comments
 (0)