@@ -507,7 +507,8 @@ Function* TranslateToFuzzReader::addFunction() {
507507 params.push_back (type);
508508 }
509509 auto paramType = Type (params);
510- func->type = Signature (paramType, getControlFlowType ());
510+ auto resultType = getControlFlowType ();
511+ func->type = Signature (paramType, resultType);
511512 Index numVars = upToSquared (MAX_VARS);
512513 for (Index i = 0 ; i < numVars; i++) {
513514 auto type = getConcreteType ();
@@ -549,13 +550,29 @@ Function* TranslateToFuzzReader::addFunction() {
549550 wasm.addFunction (func);
550551 // Export some functions, but not all (to allow inlining etc.). Try to export
551552 // at least one, though, to keep each testcase interesting. Only functions
552- // with defaultable params can be exported because the trap fuzzer depends on
553- // that (TODO: fix this).
554- bool defaultableParams =
555- std::all_of (paramType.begin (), paramType.end (), [](Type t) {
556- return t.isDefaultable ();
553+ // with valid params and returns can be exported because the trap fuzzer
554+ // depends on that (TODO: fix this).
555+ auto validExportType = [](Type t) {
556+ if (!t.isRef ()) {
557+ return true ;
558+ }
559+ auto heapType = t.getHeapType ();
560+ return heapType == HeapType::ext || heapType == HeapType::func ||
561+ heapType == HeapType::string;
562+ };
563+ bool validExportParams =
564+ std::all_of (paramType.begin (), paramType.end (), [&](Type t) {
565+ return validExportType (t) && t.isDefaultable ();
557566 });
558- if (defaultableParams && (numAddedFunctions == 0 || oneIn (2 )) &&
567+ // Note: spec discussions around JS API integration are still ongoing, and it
568+ // is not clear if we should allow nondefaultable types in exports or not
569+ // (in imports, we cannot allow them in the fuzzer anyhow, since it can't
570+ // construct such values in JS to send over to the wasm from the fuzzer
571+ // harness).
572+ bool validExportResults =
573+ std::all_of (resultType.begin (), resultType.end (), validExportType);
574+ if (validExportParams && validExportResults &&
575+ (numAddedFunctions == 0 || oneIn (2 )) &&
559576 !wasm.getExportOrNull (func->name )) {
560577 auto * export_ = new Export;
561578 export_->name = func->name ;
0 commit comments