summaryrefslogtreecommitdiff
path: root/src/wasm-emscripten.cpp
diff options
context:
space:
mode:
authorjgravelle-google <jgravelle@google.com>2016-09-14 15:32:57 -0700
committerGitHub <noreply@github.com>2016-09-14 15:32:57 -0700
commit63b499e3ec9bbdf4e79ab6d9dc198299516e8aec (patch)
tree4da883c2fc51d75dcfc3ffee7e766cb5d8b68b94 /src/wasm-emscripten.cpp
parentac078dcb1c677f83527693536cb1c06157095447 (diff)
downloadbinaryen-63b499e3ec9bbdf4e79ab6d9dc198299516e8aec.tar.gz
binaryen-63b499e3ec9bbdf4e79ab6d9dc198299516e8aec.tar.bz2
binaryen-63b499e3ec9bbdf4e79ab6d9dc198299516e8aec.zip
In AsmConstWalker, don't assume a segment exists (#697)
It's possible to generate an EM_ASM call with empty contents (due to ifdefs, for example), and this gets converted to an empty string. AsmConstWalker assumes that by this point any addresses it is pointing to have a corresponding data section, which is reasonable. However in the case of an empty string, we don't create a data section, but just leave that address uninitialized, i.e. set to 0. In the case of AsmConstWalker, a correct thing to do is to emit the empty string as metadata, which becomes an empty emscripten_asm_v call.
Diffstat (limited to 'src/wasm-emscripten.cpp')
-rw-r--r--src/wasm-emscripten.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wasm-emscripten.cpp b/src/wasm-emscripten.cpp
index 912ca6d61..f1e544a39 100644
--- a/src/wasm-emscripten.cpp
+++ b/src/wasm-emscripten.cpp
@@ -105,8 +105,16 @@ struct AsmConstWalker : public PostWalker<AsmConstWalker, Visitor<AsmConstWalker
void AsmConstWalker::visitCallImport(CallImport* curr) {
if (curr->target == EMSCRIPTEN_ASM_CONST) {
auto arg = curr->operands[0]->cast<Const>();
- Address segmentIndex = segmentsByAddress[arg->value.geti32()];
- std::string code = escape(&wasm.memory.segments[segmentIndex].data[0]);
+ auto address = arg->value.geti32();
+ auto segmentIterator = segmentsByAddress.find(address);
+ std::string code;
+ if (segmentIterator != segmentsByAddress.end()) {
+ Address segmentIndex = segmentsByAddress[address];
+ code = escape(&wasm.memory.segments[segmentIndex].data[0]);
+ } else {
+ // If we can't find the segment corresponding with the address, then we omitted the segment and the address points to an empty string.
+ code = escape("");
+ }
int32_t id;
if (ids.count(code) == 0) {
id = ids.size();