summaryrefslogtreecommitdiff
path: root/src/passes/Flatten.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-31 07:58:07 -0700
committerGitHub <noreply@github.com>2021-03-31 07:58:07 -0700
commitfdd6926c83a5901ba7d7ae12d02f1bd033c92657 (patch)
treee1547ee64cddc0d681950a8a7ca09daf112f91f5 /src/passes/Flatten.cpp
parentf034dc656b058b69bff3246a27790ab8079f2e6a (diff)
downloadbinaryen-fdd6926c83a5901ba7d7ae12d02f1bd033c92657.tar.gz
binaryen-fdd6926c83a5901ba7d7ae12d02f1bd033c92657.tar.bz2
binaryen-fdd6926c83a5901ba7d7ae12d02f1bd033c92657.zip
Avoid flatten + multivalue + reference types in the fuzzer (#3760)
The problem is that a tuple with a non-nullable element cannot be stored to a local. We'd need to split up the tuple, but that raises questions about what should be allowed in flat IR (we'd need to allow nested tuple ops in more places). That combination doesn't seem urgent, so add a clear error for now, and avoid it in the fuzzer. Avoids #3759 in the fuzzer
Diffstat (limited to 'src/passes/Flatten.cpp')
-rw-r--r--src/passes/Flatten.cpp30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp
index 39c97b133..c8f731d64 100644
--- a/src/passes/Flatten.cpp
+++ b/src/passes/Flatten.cpp
@@ -17,8 +17,27 @@
//
// Flattens code into "Flat IR" form. See ir/flat.h.
//
-// TODO: handle non-nullability
+// TODO: handle non-nullability. for example:
//
+// (module
+// (type $none (func))
+// (func $foo
+// (drop
+// (block (result funcref (ref $none))
+// (tuple.make
+// (ref.null func)
+// (ref.func $foo)
+// )
+// )
+// )
+// )
+// )
+//
+// The tuple has a non-nullable type, and so it cannot be set to a local. We
+// would need to split up the tuple and reconstruct it later, but that would
+// require allowing tuple operations in more nested places than Flat IR allows
+// today. For now, error on this; eventually changes in the spec regarding
+// null-nullability may make this easier.
#include <ir/branch-utils.h>
#include <ir/effects.h>
@@ -319,6 +338,15 @@ struct Flatten
curr->body = getPreludesWithExpression(originalBody, curr->body);
// New locals we added may be non-nullable.
TypeUpdating::handleNonNullableLocals(curr, *getModule());
+ // We cannot handle non-nullable tuples currently, see the comment at the
+ // top of the file.
+ for (auto type : curr->vars) {
+ if (!type.isDefaultable()) {
+ Fatal() << "Flatten was forced to add a local of a type it cannot "
+ "handle yet: "
+ << type;
+ }
+ }
}
private: