diff options
author | Alon Zakai <azakai@google.com> | 2021-04-08 18:06:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-08 18:06:15 -0700 |
commit | 8498027da4e078e6babe72f66829b479dd163510 (patch) | |
tree | 882048ce758b06d32c3875eb4d72d6574dfe1071 /src/tools/fuzzing.h | |
parent | 8e20e49a858f207e689589dfe9c056098c58eca2 (diff) | |
download | binaryen-8498027da4e078e6babe72f66829b479dd163510.tar.gz binaryen-8498027da4e078e6babe72f66829b479dd163510.tar.bz2 binaryen-8498027da4e078e6babe72f66829b479dd163510.zip |
RefFunc: Validate that the type is non-nullable, and avoid possible bugs in the builder (#3790)
The builder can receive a HeapType so that callers don't need to set non-nullability
themselves.
Not NFC as some of the callers were in fact still making it nullable.
Diffstat (limited to 'src/tools/fuzzing.h')
-rw-r--r-- | src/tools/fuzzing.h | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 37c027088..b3b21f8ca 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -738,7 +738,7 @@ private: } // add some to an elem segment while (oneIn(3) && !finishedInput) { - auto type = Type(HeapType(func->sig), Nullable); + auto type = Type(HeapType(func->sig), NonNullable); std::vector<ElementSegment*> compatibleSegments; ModuleUtils::iterActiveElementSegments( wasm, [&](ElementSegment* segment) { @@ -747,8 +747,7 @@ private: } }); auto& randomElem = compatibleSegments[upTo(compatibleSegments.size())]; - // FIXME: make the type NonNullable when we support it! - randomElem->data.push_back(builder.makeRefFunc(func->name, type)); + randomElem->data.push_back(builder.makeRefFunc(func->name, func->sig)); } numAddedFunctions++; return func; @@ -1523,10 +1522,9 @@ private: for (const auto& type : target->sig.params) { args.push_back(make(type)); } - auto targetType = Type(HeapType(target->sig), NonNullable); // TODO: half the time make a completely random item with that type. return builder.makeCallRef( - builder.makeRefFunc(target->name, targetType), args, type, isReturn); + builder.makeRefFunc(target->name, target->sig), args, type, isReturn); } Expression* makeLocalGet(Type type) { @@ -2115,8 +2113,7 @@ private: if (!wasm.functions.empty() && !oneIn(wasm.functions.size())) { target = pick(wasm.functions).get(); } - auto type = Type(HeapType(target->sig), Nullable); - return builder.makeRefFunc(target->name, type); + return builder.makeRefFunc(target->name, target->sig); } if (type == Type::i31ref) { return builder.makeI31New(makeConst(Type::i32)); @@ -2138,7 +2135,7 @@ private: // TODO: randomize the order for (auto& func : wasm.functions) { if (type == Type(HeapType(func->sig), NonNullable)) { - return builder.makeRefFunc(func->name, type); + return builder.makeRefFunc(func->name, func->sig); } } // We failed to find a function, so create a null reference if we can. @@ -2160,7 +2157,7 @@ private: sig, {}, builder.makeUnreachable())); - return builder.makeRefFunc(func->name, type); + return builder.makeRefFunc(func->name, heapType); } if (type.isRtt()) { return builder.makeRtt(type); |