Skip to content

Commit a288a73

Browse files
authored
Fuzzer: Stop emitting nullable stringviews (#6574)
As of https://chromium-review.googlesource.com/c/v8/v8/+/5471674 V8 requires stringviews to be non-nullable. It might be possible to make that change in our IR, or to remove views entirely, but for now this PR makes the fuzzer stop emitting nullable stringviews as a workaround to allow us to fuzz current V8. There are still rare corner cases where this pattern is emitted, that we have not tracked down, and so this also makes the fuzzer ignore the error for now.
1 parent ed2cec4 commit a288a73

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

scripts/fuzz_opt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ def filter_known_issues(output):
668668
HOST_LIMIT_PREFIX,
669669
# see comment above on this constant
670670
V8_UNINITIALIZED_NONDEF_LOCAL,
671+
# V8 does not accept nullable stringviews
672+
# (https://github.com/WebAssembly/binaryen/pull/6574)
673+
'expected (ref stringview_wtf16), got nullref',
671674
]
672675
for issue in known_issues:
673676
if issue in output:

src/ir/type-updating.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ namespace TypeUpdating {
304304

305305
bool canHandleAsLocal(Type type) {
306306
// TODO: Inline this into its callers.
307+
if (type.isRef()) {
308+
// V8 does not accept nullable string views, and so we must avoid putting
309+
// them in locals (as even a non-nullable one may end up nullable if we see
310+
// situations that require fixing in handleNonDefaultableLocals).
311+
auto heapType = type.getHeapType();
312+
return heapType != HeapType::stringview_wtf8 &&
313+
heapType != HeapType::stringview_wtf16 &&
314+
heapType != HeapType::stringview_iter;
315+
}
307316
return type.isConcrete();
308317
}
309318

src/tools/fuzzing/fuzzing.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ namespace wasm {
2929

3030
namespace {
3131

32-
// Weighting for the core make* methods. Some nodes are important enough that
33-
// we should do them quite often.
32+
bool canBeNullable(HeapType type) {
33+
// V8 does not accept nullable string views.
34+
return type != HeapType::stringview_wtf8 &&
35+
type != HeapType::stringview_wtf16 &&
36+
type != HeapType::stringview_iter;
37+
}
3438

3539
} // anonymous namespace
3640

@@ -703,6 +707,9 @@ Function* TranslateToFuzzReader::addFunction() {
703707
Index numVars = upToSquared(MAX_VARS);
704708
for (Index i = 0; i < numVars; i++) {
705709
auto type = getConcreteType();
710+
if (!TypeUpdating::canHandleAsLocal(type)) {
711+
type = Type::i32;
712+
}
706713
func->vars.push_back(type);
707714
}
708715
context.computeTypeLocals();
@@ -1858,7 +1865,7 @@ Expression* TranslateToFuzzReader::makeLocalGet(Type type) {
18581865
// the time), or emit a local.get of a new local, or emit a local.tee of a new
18591866
// local.
18601867
auto choice = upTo(3);
1861-
if (choice == 0) {
1868+
if (choice == 0 || !TypeUpdating::canHandleAsLocal(type)) {
18621869
return makeConst(type);
18631870
}
18641871
// Otherwise, add a new local. If the type is not non-nullable then we may
@@ -2712,6 +2719,9 @@ Expression* TranslateToFuzzReader::makeCompoundRef(Type type) {
27122719
if (funcContext && !funcContext->typeLocals[type].empty()) {
27132720
return makeLocalGet(type);
27142721
}
2722+
if (!canBeNullable(heapType)) {
2723+
return makeConst(type);
2724+
}
27152725
return builder.makeRefAs(RefAsNonNull, builder.makeRefNull(heapType));
27162726
}
27172727

@@ -2824,7 +2834,8 @@ Expression* TranslateToFuzzReader::makeStringConcat() {
28242834
}
28252835

28262836
Expression* TranslateToFuzzReader::makeStringSlice() {
2827-
auto* ref = makeTrappingRefUse(HeapType::stringview_wtf16);
2837+
// StringViews cannot be non-nullable.
2838+
auto* ref = make(Type(HeapType::stringview_wtf16, NonNullable));
28282839
auto* start = make(Type::i32);
28292840
auto* end = make(Type::i32);
28302841
return builder.makeStringSliceWTF(StringSliceWTF16, ref, start, end);
@@ -2855,7 +2866,8 @@ Expression* TranslateToFuzzReader::makeStringMeasure(Type type) {
28552866
Expression* TranslateToFuzzReader::makeStringGet(Type type) {
28562867
assert(type == Type::i32);
28572868

2858-
auto* ref = makeTrappingRefUse(HeapType::stringview_wtf16);
2869+
// StringViews cannot be non-nullable.
2870+
auto* ref = make(Type(HeapType::stringview_wtf16, NonNullable));
28592871
auto* pos = make(Type::i32);
28602872
return builder.makeStringWTF16Get(ref, pos);
28612873
}

0 commit comments

Comments
 (0)