Skip to content

Commit

Permalink
Directize: if we change a type to unreachable, we need to propagate t…
Browse files Browse the repository at this point in the history
…hat out (#1989)
  • Loading branch information
kripken authored Apr 9, 2019
1 parent b56c691 commit d318b18
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/passes/Directize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "wasm-builder.h"
#include "wasm-traversal.h"
#include "asm_v_wasm.h"
#include <ir/utils.h>

namespace wasm {

Expand Down Expand Up @@ -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());
Expand All @@ -109,6 +118,7 @@ struct FunctionDirectizer : public WalkerPass<PostWalker<FunctionDirectizer>> {
builder.makeUnreachable()
)
);
changedTypes = true;
}
};

Expand Down
14 changes: 14 additions & 0 deletions test/passes/directize.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
)
)
13 changes: 12 additions & 1 deletion test/passes/directize.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
)
)

0 comments on commit d318b18

Please sign in to comment.