Skip to content

Commit 9b8f59a

Browse files
committed
Improve logic for avoiding cont.new in globals
1 parent 64ab851 commit 9b8f59a

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

src/tools/fuzzing/fuzzing.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,6 @@ void TranslateToFuzzReader::setupTables() {
616616
}
617617
}
618618

619-
static bool canCreateContentWithoutFunctionScope(Type type) {
620-
for (auto t : type) {
621-
if (t.isContinuation()) {
622-
// There is no way to make a continuation in a global. TODO: We could
623-
// allow null ones, at least, that are always set to null.
624-
return false;
625-
}
626-
}
627-
return true;
628-
}
629-
630619
void TranslateToFuzzReader::setupGlobals() {
631620
// If there were initial wasm contents, there may be imported globals. That
632621
// would be a problem in the fuzzer harness as we'd error if we do not
@@ -685,9 +674,6 @@ void TranslateToFuzzReader::setupGlobals() {
685674
// Create new random globals.
686675
for (size_t index = upTo(fuzzParams->MAX_GLOBALS); index > 0; --index) {
687676
auto type = getConcreteType();
688-
if (!canCreateContentWithoutFunctionScope(type)) {
689-
continue;
690-
}
691677

692678
// Prefer immutable ones as they can be used in global.gets in other
693679
// globals, for more interesting patterns.
@@ -697,12 +683,16 @@ void TranslateToFuzzReader::setupGlobals() {
697683
// initializer.
698684
auto* init = makeTrivial(type);
699685

700-
if (!FindAll<RefAs>(init).list.empty()) {
686+
if (!FindAll<RefAs>(init).list.empty() ||
687+
!FindAll<ContNew>(init).list.empty()) {
701688
// When creating this initial value we ended up emitting a RefAs, which
702689
// means we had to stop in the middle of an overly-nested struct or array,
703690
// which we can break out of using ref.as_non_null of a nullable ref. That
704691
// traps in normal code, which is bad enough, but it does not even
705692
// validate in a global. Switch to something safe instead.
693+
//
694+
// Likewise, if we see cont.new, we must switch as well. That can happen
695+
// if a nested struct we create has a continuation field, for example.
706696
type = getMVPType();
707697
init = makeConst(type);
708698
} else if (type.isTuple() && !init->is<TupleMake>()) {

0 commit comments

Comments
 (0)