summaryrefslogtreecommitdiff
path: root/src/wasm/wasm.cpp
diff options
context:
space:
mode:
authorAlon Zakai (kripken) <alonzakai@gmail.com>2017-05-02 14:36:56 -0700
committerAlon Zakai (kripken) <alonzakai@gmail.com>2017-05-02 14:36:56 -0700
commita8f493f24d41295b63c6834fe8efb4996370fee5 (patch)
treeeacd81525ba79dcce02fadf9d336f0aea23e9bb6 /src/wasm/wasm.cpp
parentd0df9588b9adb5c9000d008c8cb739dd3289e68d (diff)
downloadbinaryen-a8f493f24d41295b63c6834fe8efb4996370fee5.tar.gz
binaryen-a8f493f24d41295b63c6834fe8efb4996370fee5.tar.bz2
binaryen-a8f493f24d41295b63c6834fe8efb4996370fee5.zip
fix unreachable typing: for all nodes, if they are not reached - e.g., a binary with either side unreachable - then they are unreachable. this makes our usage of the unreachable type consistent
Diffstat (limited to 'src/wasm/wasm.cpp')
-rw-r--r--src/wasm/wasm.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index 36eff681f..96ca8fbc8 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -248,7 +248,9 @@ void Loop::finalize() {
void Break::finalize() {
if (condition) {
- if (value) {
+ if (condition->type == unreachable) {
+ type = unreachable;
+ } else if (value) {
type = value->type;
} else {
type = none;
@@ -258,6 +260,10 @@ void Break::finalize() {
}
}
+void Switch::finalize() {
+ type = unreachable;
+}
+
bool FunctionType::structuralComparison(FunctionType& b) {
if (result != b.result) return false;
if (params.size() != b.params.size()) return false;
@@ -286,6 +292,11 @@ void SetLocal::setTee(bool is) {
void Store::finalize() {
assert(valueType != none); // must be set
+ if (ptr->type == unreachable || value->type == unreachable) {
+ type = unreachable;
+ } else {
+ type = none;
+ }
}
Const* Const::set(Literal value_) {
@@ -299,6 +310,10 @@ bool Unary::isRelational() {
}
void Unary::finalize() {
+ if (value->type == unreachable) {
+ type = unreachable;
+ return;
+ }
switch (op) {
case ClzInt32:
case CtzInt32:
@@ -390,16 +405,22 @@ bool Binary::isRelational() {
void Binary::finalize() {
assert(left && right);
- if (isRelational()) {
+ if (left->type == unreachable || right->type == unreachable) {
+ type = unreachable;
+ } else if (isRelational()) {
type = i32;
} else {
- type = getReachableWasmType(left->type, right->type);
+ type = left->type;
}
}
void Select::finalize() {
assert(ifTrue && ifFalse);
- type = getReachableWasmType(ifTrue->type, ifFalse->type);
+ if (ifTrue->type == unreachable || ifFalse->type == unreachable || condition->type == unreachable) {
+ type = unreachable;
+ } else {
+ type = ifTrue->type;
+ }
}
void Host::finalize() {