Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1485,16 +1485,32 @@ Function* TranslateToFuzzReader::addFunction() {
auto allocation = std::make_unique<Function>();
auto* func = allocation.get();
func->name = Names::getValidFunctionName(wasm, "func");
Index numParams = upToSquared(fuzzParams->MAX_PARAMS);
std::vector<Type> params;
params.reserve(numParams);
for (Index i = 0; i < numParams; i++) {
auto type = getSingleConcreteType();
params.push_back(type);

// Pick params and results. There may be an interesting heap type we can use.
std::optional<HeapType> funcType;
auto& funcTypes = interestingHeapSubTypes[HeapTypes::func];
if (!funcTypes.empty() && oneIn(2)) {
auto type = pick(funcTypes);
if (type.getSignature().params.size() < (size_t)fuzzParams->MAX_PARAMS) {
// This is suitable for us.
funcType = type;
}
}
auto paramType = Type(params);
auto resultType = getControlFlowType();
func->type = Signature(paramType, resultType);
if (!funcType) {
// Generate a new type on the fly.
Index numParams = upToSquared(fuzzParams->MAX_PARAMS);
std::vector<Type> params;
params.reserve(numParams);
for (Index i = 0; i < numParams; i++) {
auto type = getSingleConcreteType();
params.push_back(type);
}
auto paramType = Type(params);
auto resultType = getControlFlowType();
funcType = Signature(paramType, resultType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also choose whether to make the new type open or not independently, but maybe it's not worth the effort.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it's ok to leave that part to the interesting heap types. Here we just create the simplest MVP-style type.

}
func->type = *funcType;

Index numVars = upToSquared(fuzzParams->MAX_VARS);
for (Index i = 0; i < numVars; i++) {
auto type = getConcreteType();
Expand Down Expand Up @@ -1524,6 +1540,8 @@ Function* TranslateToFuzzReader::addFunction() {
// at least one, though, to keep each testcase interesting. Avoid non-
// nullable params, as those cannot be constructed by the fuzzer on the
// outside.
auto paramType = func->getParams();
auto resultType = func->getResults();
bool validExportParams =
std::all_of(paramType.begin(), paramType.end(), [&](Type t) {
return t.isDefaultable() && isValidPublicType(t);
Expand Down
Loading