summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2022-01-24 18:03:57 -0800
committerGitHub <noreply@github.com>2022-01-25 02:03:57 +0000
commit64f5e52d9fbe1d3382587c39fde365f8f79358dc (patch)
treef848ec522a06a275cd591187d3945e73bae55a0d /src/wasm/wasm-binary.cpp
parent26d0df73150e0207e6ce6262214bba1453a740d7 (diff)
downloadbinaryen-64f5e52d9fbe1d3382587c39fde365f8f79358dc.tar.gz
binaryen-64f5e52d9fbe1d3382587c39fde365f8f79358dc.tar.bz2
binaryen-64f5e52d9fbe1d3382587c39fde365f8f79358dc.zip
Make `TypeBuilder::build()` fallible (#4474)
It is possible for type building to fail, for example if the declared nominal supertypes form a cycle or are structurally invalid. Previously we would report a fatal error and kill the program from inside `TypeBuilder::build()` in these situations, but this handles errors at the wrong layer of the code base and is inconvenient for testing the error cases. In preparation for testing the new error cases introduced by isorecursive typing, make type building fallible and add new tests for existing error cases. Also fix supertype cycle detection, which it turns out did not work correctly.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index b20269f9b..13bcc5110 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1989,7 +1989,11 @@ void WasmBinaryBuilder::readTypes() {
}
}
- types = builder.build();
+ auto result = builder.build();
+ if (auto* err = result.getError()) {
+ Fatal() << "Invalid type: " << err->reason << " at index " << err->index;
+ }
+ types = *result;
}
Name WasmBinaryBuilder::getFunctionName(Index index) {