summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-04-09 09:31:26 -0700
committerGitHub <noreply@github.com>2019-04-09 09:31:26 -0700
commitd318b18d8c415357e8ee65dd4ae34ec28dc8f9d0 (patch)
tree5979332c0bdd7d09da3620913f09586641767ef7
parentb56c691ab87c2cd09255b2617213ec5d8e92a748 (diff)
downloadbinaryen-d318b18d8c415357e8ee65dd4ae34ec28dc8f9d0.tar.gz
binaryen-d318b18d8c415357e8ee65dd4ae34ec28dc8f9d0.tar.bz2
binaryen-d318b18d8c415357e8ee65dd4ae34ec28dc8f9d0.zip
Directize: if we change a type to unreachable, we need to propagate that out (#1989)
-rw-r--r--src/passes/Directize.cpp10
-rw-r--r--test/passes/directize.txt14
-rw-r--r--test/passes/directize.wast13
3 files changed, 36 insertions, 1 deletions
diff --git a/src/passes/Directize.cpp b/src/passes/Directize.cpp
index b2d132c5e..8d5cacdaf 100644
--- a/src/passes/Directize.cpp
+++ b/src/passes/Directize.cpp
@@ -27,6 +27,7 @@
#include "wasm-builder.h"
#include "wasm-traversal.h"
#include "asm_v_wasm.h"
+#include <ir/utils.h>
namespace wasm {
@@ -95,8 +96,16 @@ struct FunctionDirectizer : public WalkerPass<PostWalker<FunctionDirectizer>> {
}
}
+ void doWalkFunction(Function* func) {
+ WalkerPass<PostWalker<FunctionDirectizer>>::doWalkFunction(func);
+ if (changedTypes) {
+ ReFinalize().walkFunctionInModule(func, getModule());
+ }
+ }
+
private:
FlatTable* flatTable;
+ bool changedTypes = false;
void replaceWithUnreachable(CallIndirect* call) {
Builder builder(*getModule());
@@ -109,6 +118,7 @@ private:
builder.makeUnreachable()
)
);
+ changedTypes = true;
}
};
diff --git a/test/passes/directize.txt b/test/passes/directize.txt
index 7f4b1a57c..fb6d94e4c 100644
--- a/test/passes/directize.txt
+++ b/test/passes/directize.txt
@@ -181,3 +181,17 @@
(unreachable)
)
)
+(module
+ (type $0 (func))
+ (table $0 8 8 funcref)
+ (func $0 (; 0 ;) (type $0)
+ (block $block
+ (nop)
+ (block
+ (block
+ )
+ (unreachable)
+ )
+ )
+ )
+)
diff --git a/test/passes/directize.wast b/test/passes/directize.wast
index 8e6839457..7deb2572c 100644
--- a/test/passes/directize.wast
+++ b/test/passes/directize.wast
@@ -179,4 +179,15 @@
(unreachable)
)
)
-
+;; change types
+(module
+ (table $0 8 8 funcref)
+ (func $0
+ (block ;; the type of this block will change
+ (nop)
+ (call_indirect (type $0)
+ (i32.const 15)
+ )
+ )
+ )
+)