summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-11-28 20:07:28 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-11-28 20:16:52 -0800
commitd8f258e8e74b17d06ee7d94fc7c4dd3165819f0d (patch)
tree16c6706992f27a2e86fc9c112838aa168d2b637f /src
parent37b7e93a71e1a51fcb826cb2bce88f47bd396674 (diff)
downloadbinaryen-d8f258e8e74b17d06ee7d94fc7c4dd3165819f0d.tar.gz
binaryen-d8f258e8e74b17d06ee7d94fc7c4dd3165819f0d.tar.bz2
binaryen-d8f258e8e74b17d06ee7d94fc7c4dd3165819f0d.zip
be very careful when converting doubles to ints in asm2wasm
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h2
-rw-r--r--src/emscripten-optimizer/optimizer-shared.cpp6
-rw-r--r--src/emscripten-optimizer/optimizer.h2
3 files changed, 8 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 8dcefec0e..51536663d 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -935,7 +935,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
double num = ast[1]->getNumber();
if (isInteger32(num)) {
ret->value.type = WasmType::i32;
- ret->value.i32 = num;
+ ret->value.i32 = toInteger32(num);
} else {
ret->value.type = WasmType::f64;
ret->value.f64 = num;
diff --git a/src/emscripten-optimizer/optimizer-shared.cpp b/src/emscripten-optimizer/optimizer-shared.cpp
index 24c19cd79..6a8bbf9b5 100644
--- a/src/emscripten-optimizer/optimizer-shared.cpp
+++ b/src/emscripten-optimizer/optimizer-shared.cpp
@@ -19,6 +19,12 @@ bool isInteger32(double x) {
return isInteger(x) && (x == (int32_t)x || x == (uint32_t)x);
}
+int32_t toInteger32(double x) {
+ if (x == (int32_t)x) return (int32_t)x;
+ assert(x == (uint32_t)x);
+ return (uint32_t)x;
+}
+
int parseInt(const char *str) {
int ret = *str - '0';
while (*(++str)) {
diff --git a/src/emscripten-optimizer/optimizer.h b/src/emscripten-optimizer/optimizer.h
index faef2cccb..12d0671eb 100644
--- a/src/emscripten-optimizer/optimizer.h
+++ b/src/emscripten-optimizer/optimizer.h
@@ -102,8 +102,8 @@ struct AsmData {
};
bool isInteger(double x);
-
bool isInteger32(double x);
+int32_t toInteger32(double x);
extern cashew::IString ASM_FLOAT_ZERO;