summaryrefslogtreecommitdiff
path: root/src/tools/fuzzing/fuzzing.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-08-22 16:21:19 -0700
committerGitHub <noreply@github.com>2022-08-22 16:21:19 -0700
commit92cdc7245b715d88cf986a7eaf78c49ea64ba825 (patch)
tree7e20e91c0a60a5b08f8bb01d64ea7ebc3a6b6885 /src/tools/fuzzing/fuzzing.cpp
parent195c4e1804d5a4530c8216d4c9a138b56f676d10 (diff)
downloadbinaryen-92cdc7245b715d88cf986a7eaf78c49ea64ba825.tar.gz
binaryen-92cdc7245b715d88cf986a7eaf78c49ea64ba825.tar.bz2
binaryen-92cdc7245b715d88cf986a7eaf78c49ea64ba825.zip
Separate `func` into a separate type hierarchy (#4955)
Just like `extern` is no longer a subtype of `any` in the new GC type system, `func` is no longer a subtype of `any`, either. Make that change in our type system implementation and update tests and fuzzers accordingly.
Diffstat (limited to 'src/tools/fuzzing/fuzzing.cpp')
-rw-r--r--src/tools/fuzzing/fuzzing.cpp37
1 files changed, 10 insertions, 27 deletions
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 831d80c04..828f80693 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -1984,17 +1984,7 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) {
// Choose a subtype we can materialize a constant for. We cannot
// materialize non-nullable refs to func or i31 in global contexts.
Nullability nullability = getSubType(type.getNullability());
- HeapType subtype;
- if (funcContext || nullability == Nullable) {
- subtype = pick(FeatureOptions<HeapType>()
- .add(FeatureSet::ReferenceTypes, HeapType::func)
- .add(FeatureSet::ReferenceTypes | FeatureSet::GC,
- HeapType::func,
- HeapType::i31,
- HeapType::data));
- } else {
- subtype = HeapType::func;
- }
+ HeapType subtype = oneIn(2) ? HeapType::i31 : HeapType::data;
return makeConst(Type(subtype, nullability));
}
case HeapType::eq: {
@@ -2017,13 +2007,10 @@ Expression* TranslateToFuzzReader::makeConstBasicRef(Type type) {
}
case HeapType::i31: {
assert(wasm.features.hasGC());
- // i31.new is not allowed in initializer expressions.
- if (funcContext) {
- return builder.makeI31New(makeConst(Type::i32));
- } else {
- assert(type.isNullable());
+ if (type.isNullable() && oneIn(4)) {
return builder.makeRefNull(type);
}
+ return builder.makeI31New(makeConst(Type::i32));
}
case HeapType::data: {
assert(wasm.features.hasGC());
@@ -2986,9 +2973,11 @@ Type TranslateToFuzzReader::getSingleConcreteType() {
.add(FeatureSet::SIMD, WeightedOption{Type::v128, Important})
.add(FeatureSet::ReferenceTypes,
Type(HeapType::func, Nullable),
- Type(HeapType::any, Nullable))
+ Type(HeapType::ext, Nullable))
.add(FeatureSet::ReferenceTypes | FeatureSet::GC,
// Type(HeapType::func, NonNullable),
+ // Type(HeapType::ext, NonNullable),
+ Type(HeapType::any, Nullable),
// Type(HeapType::any, NonNullable),
Type(HeapType::eq, Nullable),
Type(HeapType::eq, NonNullable),
@@ -3000,8 +2989,7 @@ Type TranslateToFuzzReader::getSingleConcreteType() {
Type TranslateToFuzzReader::getReferenceType() {
return pick(FeatureOptions<Type>()
- // Avoid Type::anyref without GC enabled, see
- // TranslateToFuzzReader::getSingleConcreteType.
+ // TODO: Add externref here.
.add(FeatureSet::ReferenceTypes, Type(HeapType::func, Nullable))
.add(FeatureSet::ReferenceTypes | FeatureSet::GC,
Type(HeapType::func, NonNullable),
@@ -3102,14 +3090,9 @@ HeapType TranslateToFuzzReader::getSubType(HeapType type) {
return HeapType::ext;
case HeapType::any:
// TODO: nontrivial types as well.
- return pick(
- FeatureOptions<HeapType>()
- .add(FeatureSet::ReferenceTypes, HeapType::func /*, HeapType::ext*/)
- .add(FeatureSet::ReferenceTypes | FeatureSet::GC,
- HeapType::any,
- HeapType::eq,
- HeapType::i31,
- HeapType::data));
+ assert(wasm.features.hasReferenceTypes());
+ assert(wasm.features.hasGC());
+ return pick(HeapType::any, HeapType::eq, HeapType::i31, HeapType::data);
case HeapType::eq:
// TODO: nontrivial types as well.
assert(wasm.features.hasReferenceTypes());