diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-22 16:01:10 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:05 -0700 |
commit | f3bb9debe6af0576d76bda1580df2570e749bd36 (patch) | |
tree | ac4bc7b6e7dfe89cb5c1df7ecb44833e83d313bc | |
parent | 83e0dde16f381b28c1ee0d099de25444b0f34e58 (diff) | |
download | binaryen-f3bb9debe6af0576d76bda1580df2570e749bd36.tar.gz binaryen-f3bb9debe6af0576d76bda1580df2570e749bd36.tar.bz2 binaryen-f3bb9debe6af0576d76bda1580df2570e749bd36.zip |
handle asm.js globals that are set and the return value used
-rw-r--r-- | src/asm2wasm.h | 5 | ||||
-rw-r--r-- | test/unit.asm.js | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 52598ad0b..321d5275e 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1014,7 +1014,10 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { } // global var assert(mappedGlobals.find(name) != mappedGlobals.end()); - return builder.makeSetGlobal(name, process(ast[3])); + auto* ret = builder.makeSetGlobal(name, process(ast[3])); + // set_global does not return; if our value is trivially not used, don't emit a load (if nontrivially not used, opts get it later) + if (astStackHelper.getParent()[0] == STAT) return ret; + return builder.makeSequence(ret, builder.makeGetGlobal(name, ret->value->type)); } else if (ast[2][0] == SUB) { Ref target = ast[2]; assert(target[1][0] == NAME); diff --git a/test/unit.asm.js b/test/unit.asm.js index d6d0a27e8..cf2060030 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -281,6 +281,17 @@ function asm(global, env, buffer) { return phi() | 0; } + function useSetGlobal() { + var x = 0; + x = (Int = 10); + Int = 20; + return (Int = 30) | 0; + } + + function usesSetGlobal2() { + return (Int = 40, 50) | 0; + } + function z() { } function w() { |