summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-02-03 12:20:59 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-02-03 12:20:59 -0800
commit0c4e4521b5ede340a7060bf052ccdf84269c3f0a (patch)
tree3698cca698bbb8dfb044a4c8625a7b5c06f68e48 /src
parent83b368381eb1e9e499f213129627d0c188d0008f (diff)
downloadbinaryen-0c4e4521b5ede340a7060bf052ccdf84269c3f0a.tar.gz
binaryen-0c4e4521b5ede340a7060bf052ccdf84269c3f0a.tar.bz2
binaryen-0c4e4521b5ede340a7060bf052ccdf84269c3f0a.zip
Break and Return have unreachable type
Diffstat (limited to 'src')
-rw-r--r--src/passes/RemoveUnusedBrs.cpp2
-rw-r--r--src/wasm-binary.h6
-rw-r--r--src/wasm.h12
3 files changed, 14 insertions, 6 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp
index c7fa43df9..5302c368a 100644
--- a/src/passes/RemoveUnusedBrs.cpp
+++ b/src/passes/RemoveUnusedBrs.cpp
@@ -37,7 +37,7 @@ struct RemoveUnusedBrs : public WalkerPass<WasmWalker<RemoveUnusedBrs>> {
}
return;
}
- if (curr->type != none) return; // already has a returned value
+ if (isConcreteWasmType(curr->type)) return; // already has a returned value
// an if_else that indirectly returns a value by breaking to the same target can potentially remove both breaks, and break outside once
auto getLast = [](Expression *side) -> Expression* {
Block* b = side->dyn_cast<Block>();
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index de4747d84..440689ea0 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -851,7 +851,7 @@ assert(0);
void visitBinary(Binary *curr) {
if (debug) std::cerr << "zz node: Binary" << std::endl;
#define TYPED_CODE(code) { \
- switch (curr->left->type) { \
+ switch (getReachableWasmType(curr->left->type, curr->right->type)) { \
case i32: o << int8_t(BinaryConsts::I32##code); break; \
case i64: o << int8_t(BinaryConsts::I64##code); break; \
case f32: o << int8_t(BinaryConsts::F32##code); break; \
@@ -861,7 +861,7 @@ assert(0);
break; \
}
#define INT_TYPED_CODE(code) { \
- switch (curr->left->type) { \
+ switch (getReachableWasmType(curr->left->type, curr->right->type)) { \
case i32: o << int8_t(BinaryConsts::I32##code); break; \
case i64: o << int8_t(BinaryConsts::I64##code); break; \
default: abort(); \
@@ -869,7 +869,7 @@ assert(0);
break; \
}
#define FLOAT_TYPED_CODE(code) { \
- switch (curr->left->type) { \
+ switch (getReachableWasmType(curr->left->type, curr->right->type)) { \
case f32: o << int8_t(BinaryConsts::F32##code); break; \
case f64: o << int8_t(BinaryConsts::F64##code); break; \
default: abort(); \
diff --git a/src/wasm.h b/src/wasm.h
index 7a792fda4..c030d9d60 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -138,6 +138,10 @@ inline WasmType getReachableWasmType(WasmType a, WasmType b) {
return a != unreachable ? a : b;
}
+inline bool isConcreteWasmType(WasmType type) {
+ return type != none && type != unreachable;
+}
+
// Literals
class Literal {
@@ -497,7 +501,9 @@ public:
class Break : public Expression {
public:
- Break() : Expression(BreakId), condition(nullptr), value(nullptr) {}
+ Break() : Expression(BreakId), condition(nullptr), value(nullptr) {
+ type = unreachable;
+ }
Expression *condition;
Name name;
@@ -926,7 +932,9 @@ class Return : public Expression {
public:
Expression *value;
- Return() : Expression(ReturnId), value(nullptr) {}
+ Return() : Expression(ReturnId), value(nullptr) {
+ type = unreachable;
+ }
std::ostream& doPrint(std::ostream &o, unsigned indent) {
printOpening(o, "return");