From e3c38c14e7dd9c115da960daafd109d2687f1a08 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Sun, 10 Jan 2016 10:49:59 -0800 Subject: Add Travis builds with sanitizers This triggers 5 independent build / test runs: - clang, no sanitizer; - clang, UB sanitizer; - clang, address sanitizer (disabled for now); - clang, thread sanitizer (disabled for now); - GCC. Enabling UBSan led to these changes: - Fix a bunch of undefined behavior throughout the code base. - Fix some tests that relied on that undefined behavior. - Make some of the tests easier to debug by printing their command line. - Add ubsan blacklist to work around libstdc++ bug. - Example testcase also needs sanitizer because libsupport.a uses it. --- src/emscripten-optimizer/optimizer-shared.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/emscripten-optimizer/optimizer-shared.cpp') diff --git a/src/emscripten-optimizer/optimizer-shared.cpp b/src/emscripten-optimizer/optimizer-shared.cpp index 4466fb0e9..6831d81b0 100644 --- a/src/emscripten-optimizer/optimizer-shared.cpp +++ b/src/emscripten-optimizer/optimizer-shared.cpp @@ -14,7 +14,10 @@ * limitations under the License. */ +#include + #include "optimizer.h" +#include "support/safe_integer.h" using namespace cashew; @@ -26,20 +29,6 @@ IString SIMD_INT8X16_CHECK("SIMD_Int8x16_check"), SIMD_FLOAT32X4_CHECK("SIMD_Float32x4_check"), SIMD_FLOAT64X2_CHECK("SIMD_Float64x2_check"); -bool isInteger(double x) { - return fmod(x, 1) == 0; -} - -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)) { @@ -67,7 +56,7 @@ AsmType detectType(Ref node, AsmData *asmData, bool inVarDef, IString minifiedFr switch (node[0]->getCString()[0]) { case 'n': { if (node[0] == NUM) { - if (!isInteger(node[1]->getNumber())) return ASM_DOUBLE; + if (!wasm::isInteger(node[1]->getNumber())) return ASM_DOUBLE; return ASM_INT; } else if (node[0] == NAME) { if (asmData) { @@ -176,7 +165,7 @@ AsmSign detectSign(Ref node, IString minifiedFround) { double value = node[1]->getNumber(); if (value < 0) return ASM_SIGNED; if (value > uint32_t(-1) || fmod(value, 1) != 0) return ASM_NONSIGNED; - if (value == int32_t(value)) return ASM_FLEXIBLE; + if (wasm::isSInteger32(value)) return ASM_FLEXIBLE; return ASM_UNSIGNED; } else if (type == NAME) { return ASM_FLEXIBLE; -- cgit v1.2.3