summaryrefslogtreecommitdiff
path: root/src/tools/fuzzing/fuzzing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/fuzzing/fuzzing.cpp')
-rw-r--r--src/tools/fuzzing/fuzzing.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index fe091c91f..e5afbf559 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -2017,23 +2017,35 @@ Expression* TranslateToFuzzReader::makeConstCompoundRef(Type type) {
assert(wasm.features.hasReferenceTypes());
if (heapType.isSignature()) {
return makeRefFuncConst(type);
- } else {
- // TODO: Handle nontrivial array and struct types.
}
+
// We weren't able to directly materialize a non-null constant. Try again to
// create a null.
if (type.isNullable()) {
return builder.makeRefNull(type);
}
+
// We have to produce a non-null value. Possibly create a null and cast it
// to non-null even though that will trap at runtime. We must have a
- // function context because the cast is not allowed in globals.
- if (!funcContext) {
- std::cerr << type << "\n";
+ // function context for this because the cast is not allowed in globals.
+ if (funcContext) {
+ return builder.makeRefAs(RefAsNonNull,
+ builder.makeRefNull(Type(heapType, Nullable)));
+ }
+
+ // Otherwise, we are not in a function context. This can happen if we need
+ // to make a constant for the initializer of a global, for example. We've
+ // already handled simple cases of this above, for basic heap types, so what
+ // we have left here are user-defined heap types like structs.
+ // TODO: support non-defaultable fields. for now, just use default values.
+ if (type.isStruct()) {
+ return builder.makeStructNew(type.getHeapType(),
+ std::vector<Expression*>{});
+ } else if (type.isArray()) {
+ return builder.makeArrayNew(type.getHeapType(), makeConst(Type::i32));
+ } else {
+ WASM_UNREACHABLE("bad user-defined ref type");
}
- assert(funcContext);
- return builder.makeRefAs(RefAsNonNull,
- builder.makeRefNull(Type(heapType, Nullable)));
}
Expression* TranslateToFuzzReader::buildUnary(const UnaryArgs& args) {