Skip to content

Commit 13fe0e3

Browse files
authored
Fuzzer: Use existing mechanism to fix up non-nullable global exnrefs (#8021)
We can't easily make a non-nullable exnref, and use a throw in a block to manufacture one when necessary. That doesn't work in the global scope. When in that bad situation, emit a RefAsNonNull to "fix" it, which is not valid (like a throw+block are not valid), but existing code for global generation notes that and fixes it up.
1 parent f23ae35 commit 13fe0e3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/tools/fuzzing/fuzzing.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,13 +3795,21 @@ Expression* TranslateToFuzzReader::makeBasicRef(Type type) {
37953795
return builder.makeArrayNewFixed(ht, {});
37963796
}
37973797
case HeapType::exn: {
3798-
// If nullable, we can emit a null. If there is no function context, then
3799-
// we must do so, as the other option is a throw in a block, which are not
3800-
// possible outside of functions.
3798+
// If nullable, sometimes emit a null. If not in a function context, see
3799+
// below, we need a null as well regardless of the type.
38013800
if ((type.isNullable() && oneIn(2)) || !funcContext) {
3802-
return builder.makeRefNull(HeapTypes::exn.getBasic(share));
3801+
auto* null = builder.makeRefNull(HeapTypes::exn.getBasic(share));
3802+
if (type.isNullable()) {
3803+
return null;
3804+
}
3805+
// The type is non-nullable, so we are here because we are in a non-
3806+
// function context, with nothing valid to emit. "Fix" it with a cast,
3807+
// which is not valid IR, but which the calling code will handle.
3808+
assert(!funcContext);
3809+
return builder.makeRefAs(RefAsNonNull, null);
38033810
}
38043811

3812+
// Emit a throw in a block.
38053813
auto* throww = makeThrow(Type::unreachable);
38063814
auto label = makeLabel();
38073815
auto* tryy = builder.makeTryTable(throww, {Name()}, {label}, {true});

0 commit comments

Comments
 (0)