diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-08-22 12:47:42 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-22 19:47:42 +0000 |
commit | b24df4d0c4705027fdc6e261aa3f8e4f61dc5c0a (patch) | |
tree | 67de9fd836576d6c0d2bcaba45135ba03eab83f3 /src/tools/fuzzing/fuzzing.cpp | |
parent | 97e07a60318bbc263752b3ed770c2e2bdc8c0872 (diff) | |
download | binaryen-b24df4d0c4705027fdc6e261aa3f8e4f61dc5c0a.tar.gz binaryen-b24df4d0c4705027fdc6e261aa3f8e4f61dc5c0a.tar.bz2 binaryen-b24df4d0c4705027fdc6e261aa3f8e4f61dc5c0a.zip |
Materialize non-null externrefs in the fuzzer (#4952)
Some fuzzer initial contents contain non-nullable externrefs that cause the
fuzzer to try to materialize non-nullable externref values. Perviously the
fuzzer did not support this and crashed with an assertion failure. Fix the
assertion failure by instead returning a null cast to non-null, which will trap
at runtime but at least produce a valid module.
Diffstat (limited to 'src/tools/fuzzing/fuzzing.cpp')
-rw-r--r-- | src/tools/fuzzing/fuzzing.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp index cc64b3b6a..831d80c04 100644 --- a/src/tools/fuzzing/fuzzing.cpp +++ b/src/tools/fuzzing/fuzzing.cpp @@ -1969,8 +1969,13 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) { assert(wasm.features.hasReferenceTypes()); switch (heapType.getBasic()) { case HeapType::ext: { - assert(type.isNullable() && "Cannot handle non-nullable externref"); - return builder.makeRefNull(type); + auto null = builder.makeRefNull(HeapType::ext); + // TODO: support actual non-nullable externrefs via imported globals or + // similar. + if (!type.isNullable()) { + return builder.makeRefAs(RefAsNonNull, null); + } + return null; } case HeapType::func: { return makeRefFuncConst(type); |