summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-10-17 10:12:02 -0700
committerGitHub <noreply@github.com>2023-10-17 17:12:02 +0000
commit2bf3caae764689c606ae38353b1bad5fe28bf5bb (patch)
tree7112801575e46132fdccad7bf120f5cafb9471da /src
parentb816ac563de6b1c53087796335fce593a96f569a (diff)
downloadbinaryen-2bf3caae764689c606ae38353b1bad5fe28bf5bb.tar.gz
binaryen-2bf3caae764689c606ae38353b1bad5fe28bf5bb.tar.bz2
binaryen-2bf3caae764689c606ae38353b1bad5fe28bf5bb.zip
Add getGeneralSuperType() that includes basic supers, and use in fuzzer (#6005)
With this, the fuzzer can replace e.g. an eq expression with a specific struct type, because now it is away that struct types have eq as their ancestor.
Diffstat (limited to 'src')
-rw-r--r--src/ir/subtypes.h1
-rw-r--r--src/tools/fuzzing.h7
-rw-r--r--src/tools/fuzzing/fuzzing.cpp3
-rw-r--r--src/wasm-type.h5
-rw-r--r--src/wasm/wasm-type.cpp41
5 files changed, 47 insertions, 10 deletions
diff --git a/src/ir/subtypes.h b/src/ir/subtypes.h
index 7cc633a75..488bb8310 100644
--- a/src/ir/subtypes.h
+++ b/src/ir/subtypes.h
@@ -122,7 +122,6 @@ struct SubTypes {
}
// Add the max depths of basic types.
- // TODO: update when we get structtype
for (auto type : types) {
HeapType basic;
if (type.isStruct()) {
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index e29a6ddaf..a40a76106 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -25,8 +25,6 @@ high chance for set at start of loop
high chance of a tee in that case => loop var
*/
-// TODO Generate exception handling instructions
-
#include "ir/branch-utils.h"
#include "ir/memory-utils.h"
#include "ir/struct-utils.h"
@@ -399,8 +397,3 @@ private:
};
} // namespace wasm
-
-// XXX Switch class has a condition?! is it real? should the node type be the
-// value type if it exists?!
-
-// TODO copy an existing function and replace just one node in it
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 2e4d460f7..bdaf71e83 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -765,8 +765,7 @@ void TranslateToFuzzReader::recombine(Function* func) {
while (1) {
ret.push_back(Type(heapType, nullability));
- // TODO: handle basic supertypes too
- auto super = heapType.getDeclaredSuperType();
+ auto super = heapType.getSuperType();
if (!super) {
break;
}
diff --git a/src/wasm-type.h b/src/wasm-type.h
index bc6b25b34..23ceb9143 100644
--- a/src/wasm-type.h
+++ b/src/wasm-type.h
@@ -372,6 +372,11 @@ public:
// module) nominal supertype, return it, else an empty optional.
std::optional<HeapType> getDeclaredSuperType() const;
+ // As |getDeclaredSuperType|, but also handles basic types, that is, if the
+ // super is a basic type, then we return it here. Declared types are returned
+ // as well, just like |getDeclaredSuperType|.
+ std::optional<HeapType> getSuperType() const;
+
// Return the depth of this heap type in the nominal type hierarchy, i.e. the
// number of supertypes in its supertype chain.
size_t getDepth() const;
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 1b8d7d0f1..68d7f732b 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -1219,6 +1219,47 @@ std::optional<HeapType> HeapType::getDeclaredSuperType() const {
return {};
}
+std::optional<HeapType> HeapType::getSuperType() const {
+ auto ret = getDeclaredSuperType();
+ if (ret) {
+ return ret;
+ }
+
+ // There may be a basic supertype.
+ if (isBasic()) {
+ switch (getBasic()) {
+ case ext:
+ case noext:
+ case func:
+ case nofunc:
+ case any:
+ case none:
+ case string:
+ case stringview_wtf8:
+ case stringview_wtf16:
+ case stringview_iter:
+ return {};
+ case eq:
+ return any;
+ case i31:
+ case struct_:
+ case array:
+ return eq;
+ }
+ }
+
+ auto* info = getHeapTypeInfo(*this);
+ switch (info->kind) {
+ case HeapTypeInfo::SignatureKind:
+ return func;
+ case HeapTypeInfo::StructKind:
+ return struct_;
+ case HeapTypeInfo::ArrayKind:
+ return array;
+ }
+ WASM_UNREACHABLE("unexpected kind");
+}
+
size_t HeapType::getDepth() const {
size_t depth = 0;
std::optional<HeapType> super;