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.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index c4c47ee23..03ee7d376 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -2146,12 +2146,26 @@ Expression* TranslateToFuzzReader::makeConstCompoundRef(Type type) {
// 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*>{});
+ auto& fields = heapType.getStruct().fields;
+ std::vector<Expression*> values;
+ // TODO: use non-default values randomly even when not necessary, sometimes
+ if (std::any_of(fields.begin(), fields.end(), [&](const Field& field) {
+ return !field.type.isDefaultable();
+ })) {
+ // There is a nondefaultable field, which we must create.
+ for (auto& field : fields) {
+ values.push_back(makeTrivial(field.type));
+ }
+ }
+ return builder.makeStructNew(heapType, values);
} else if (type.isArray()) {
- return builder.makeArrayNew(type.getHeapType(), makeConst(Type::i32));
+ auto element = heapType.getArray().element;
+ Expression* init = nullptr;
+ if (!element.type.isDefaultable()) {
+ init = makeTrivial(element.type);
+ }
+ return builder.makeArrayNew(type.getHeapType(), makeConst(Type::i32), init);
} else {
WASM_UNREACHABLE("bad user-defined ref type");
}