Skip to content

Commit 60cd24d

Browse files
authored
Fuzzer: Avoid generating ref.as_non_null in more places (#7870)
1. Rather than assert against this, allow it. We cannot prevent a situation where some nested struct.new in a global init ends up with a tricky field. Instead, we note the issue later, and recreate the global init. 2. That recreation logic had an ordering bug: First handle tuples, and then also handle ref.as_non_null, as we may end up creating one right there.
1 parent d06f09b commit 60cd24d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/tools/fuzzing/fuzzing.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,13 @@ void TranslateToFuzzReader::setupGlobals() {
683683
// initializer.
684684
auto* init = makeTrivial(type);
685685

686+
if (type.isTuple() && !init->is<TupleMake>()) {
687+
// For now we disallow anything but tuple.make at the top level of tuple
688+
// globals (see details in wasm-binary.cpp). In the future we may allow
689+
// global.get or other things here.
690+
init = makeConst(type);
691+
assert(init->is<TupleMake>());
692+
}
686693
if (!FindAll<RefAs>(init).list.empty() ||
687694
!FindAll<ContNew>(init).list.empty()) {
688695
// When creating this initial value we ended up emitting a RefAs, which
@@ -695,12 +702,6 @@ void TranslateToFuzzReader::setupGlobals() {
695702
// if a nested struct we create has a continuation field, for example.
696703
type = getMVPType();
697704
init = makeConst(type);
698-
} else if (type.isTuple() && !init->is<TupleMake>()) {
699-
// For now we disallow anything but tuple.make at the top level of tuple
700-
// globals (see details in wasm-binary.cpp). In the future we may allow
701-
// global.get or other things here.
702-
init = makeConst(type);
703-
assert(init->is<TupleMake>());
704705
}
705706
auto global = builder.makeGlobal(
706707
Names::getValidGlobalName(wasm, "global$"), type, init, mutability);
@@ -3445,7 +3446,6 @@ Expression* TranslateToFuzzReader::makeBasicRef(Type type) {
34453446
// TODO: support actual non-nullable externrefs via imported globals or
34463447
// similar.
34473448
if (!type.isNullable()) {
3448-
assert(funcContext);
34493449
return builder.makeRefAs(RefAsNonNull, null);
34503450
}
34513451
return null;

0 commit comments

Comments
 (0)