diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-28 18:26:24 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-28 18:26:24 -0700 |
commit | fb0d9509f23472df14d03d93d333d242d23bd2bd (patch) | |
tree | 40afeae744cd0355e27f18e45f2911c1d01c31f3 | |
parent | 97972db66d30c1acb716e4f7a421f1fbe7410927 (diff) | |
parent | 5cc2c2182332cd17bf12e3cdb58e61d0582eafc1 (diff) | |
download | binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.tar.gz binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.tar.bz2 binaryen-fb0d9509f23472df14d03d93d333d242d23bd2bd.zip |
Merge pull request #287 from WebAssembly/vs2015_fixes
VS2015 fixes
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/binaryen-shell.cpp | 14 | ||||
-rw-r--r-- | src/s2wasm-main.cpp | 8 | ||||
-rw-r--r-- | src/s2wasm.h | 6 | ||||
-rw-r--r-- | src/support/file.cpp | 10 | ||||
-rw-r--r-- | src/wasm-binary.h | 2 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 10 | ||||
-rw-r--r-- | src/wasm-s-parser.h | 6 |
8 files changed, 36 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e2eed16b3..89f7ce54c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,8 +29,10 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") IF(MSVC) - ADD_COMPILE_FLAG("/arch:sse2") - ADD_COMPILE_FLAG("/Wall") + IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "19.0") # VS2013 and older explicitly need /arch:sse2 set, VS2015 no longer has that option, but always enabled. + ADD_COMPILE_FLAG("/arch:sse2") + ENDIF() + ADD_COMPILE_FLAG("/wd4146") # Ignore warning "warning C4146: unary minus operator applied to unsigned type, result still unsigned", this pattern is used somewhat commonly in the code. ADD_COMPILE_FLAG("/WX-") IF(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") ADD_COMPILE_FLAG("/O0") diff --git a/src/binaryen-shell.cpp b/src/binaryen-shell.cpp index bfed8277e..78ff91150 100644 --- a/src/binaryen-shell.cpp +++ b/src/binaryen-shell.cpp @@ -178,9 +178,9 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { } case i64: { switch (store->bytes) { - case 1: memory.set<int8_t>(addr, value.geti64()); break; - case 2: memory.set<int16_t>(addr, value.geti64()); break; - case 4: memory.set<int32_t>(addr, value.geti64()); break; + case 1: memory.set<int8_t>(addr, (int8_t)value.geti64()); break; + case 2: memory.set<int16_t>(addr, (int16_t)value.geti64()); break; + case 4: memory.set<int32_t>(addr, (int32_t)value.geti64()); break; case 8: memory.set<int64_t>(addr, value.geti64()); break; default: abort(); } @@ -248,7 +248,7 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm, if (wasm) { interface = new ShellExternalInterface(); instance = new ModuleInstance(*wasm, interface); - if (entry.is() > 0) { + if (entry.is()) { Function* function = wasm->functionsMap[entry]; if (!function) { std::cerr << "Unknown entry " << entry << std::endl; @@ -259,7 +259,7 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm, } try { instance->callExport(entry, arguments); - } catch (ExitException& x) { + } catch (ExitException&) { } } } @@ -287,7 +287,7 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm, throw ParseException(); }) ); - } catch (const ParseException& e) { + } catch (const ParseException&) { invalid = true; } if (!invalid) { @@ -307,7 +307,7 @@ static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm, try { Invocation invocation(*curr[1], instance, *builder->get()); result = invocation.invoke(); - } catch (const TrapException& e) { + } catch (const TrapException&) { trapped = true; } if (id == ASSERT_RETURN) { diff --git a/src/s2wasm-main.cpp b/src/s2wasm-main.cpp index 752494aac..40009cbc9 100644 --- a/src/s2wasm-main.cpp +++ b/src/s2wasm-main.cpp @@ -78,18 +78,18 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "Parsing and wasming..." << std::endl; AllocatingModule wasm; - size_t globalBase = options.extra.find("global-base") != options.extra.end() + uint64_t globalBase = options.extra.find("global-base") != options.extra.end() ? std::stoull(options.extra["global-base"]) : 1; - size_t stackAllocation = + uint64_t stackAllocation = options.extra.find("stack-allocation") != options.extra.end() ? std::stoull(options.extra["stack-allocation"]) : 0; - size_t initialMem = + uint64_t initialMem = options.extra.find("initial-memory") != options.extra.end() ? std::stoull(options.extra["initial-memory"]) : 0; - size_t maxMem = + uint64_t maxMem = options.extra.find("max-memory") != options.extra.end() ? std::stoull(options.extra["max-memory"]) : 0; diff --git a/src/s2wasm.h b/src/s2wasm.h index e10d365a0..f4c83fe65 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -703,7 +703,7 @@ class S2WasmBuilder { curr->align = curr->bytes; if (attributes[0]) { assert(strncmp(attributes[0], "p2align=", 8) == 0); - curr->align = pow(2, getInt(attributes[0] + 8)); + curr->align = 1U << getInt(attributes[0] + 8); } setOutput(curr, assign); }; @@ -722,7 +722,7 @@ class S2WasmBuilder { curr->align = curr->bytes; if (attributes[0]) { assert(strncmp(attributes[0], "p2align=", 8) == 0); - curr->align = pow(2, getInt(attributes[0] + 8)); + curr->align = 1U << getInt(attributes[0] + 8); } curr->value = inputs[1]; setOutput(curr, assign); @@ -1101,7 +1101,7 @@ class S2WasmBuilder { align = getInt(); skipWhitespace(); } - align = pow(2, align); // convert from power to actual bytes + align = (size_t)1 << align; // convert from power to actual bytes if (match(".lcomm")) { parseLcomm(name, align); return; diff --git a/src/support/file.cpp b/src/support/file.cpp index 8813750d4..c93086990 100644 --- a/src/support/file.cpp +++ b/src/support/file.cpp @@ -17,6 +17,7 @@ #include "support/file.h" #include <cstdlib> +#include <limits> template <typename T> T wasm::read_file(const std::string &filename, bool debug) { @@ -27,8 +28,13 @@ T wasm::read_file(const std::string &filename, bool debug) { exit(EXIT_FAILURE); } infile.seekg(0, std::ios::end); - size_t insize = infile.tellg(); - T input(insize + 1, '\0'); + std::streampos insize = infile.tellg(); + if (size_t(insize) >= std::numeric_limits<size_t>::max()) { + // Building a 32-bit executable where size_t == 32 bits, we are not able to create strings larger than 2^32 bytes in length, so must abort here. + std::cerr << "Failed opening '" << filename << "': Input file too large: " << insize << " bytes. Try rebuilding in 64-bit mode." << std::endl; + exit(EXIT_FAILURE); + } + T input(size_t(insize) + 1, '\0'); infile.seekg(0); infile.read(&input[0], insize); return input; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 6782eec21..edc904787 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -43,7 +43,7 @@ struct LEB { bool hasMore(T temp, MiniT byte) { // for signed, we must ensure the last bit has the right sign, as it will zero extend - return isSigned() ? (temp != 0 && int32_t(temp) != -1) || (value >= 0 && (byte & 64)) || (value < 0 && !(byte & 64)): temp; + return isSigned() ? (temp != 0 && int32_t(temp) != -1) || (value >= 0 && (byte & 64)) || (value < 0 && !(byte & 64)): (temp != 0); } void write(std::vector<uint8_t>* out) { diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 9aadccb59..e7a5d6d14 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -283,7 +283,7 @@ private: if (curr->condition) { Flow conditionFlow = visit(curr->condition); if (conditionFlow.breaking()) return conditionFlow; - condition = conditionFlow.value.getInteger(); + condition = conditionFlow.value.getInteger() != 0; } return condition ? flow : Flow(); } @@ -304,7 +304,7 @@ private: Name target = curr->default_; if (index >= 0 && (size_t)index < curr->targets.size()) { - target = curr->targets[index]; + target = curr->targets[(size_t)index]; } flow.breakTo = target; return flow; @@ -641,7 +641,7 @@ private: if (val > (double)std::numeric_limits<int32_t>::max() || val < (double)std::numeric_limits<int32_t>::min()) trap("i32.truncSFloat overflow"); return Literal(int32_t(val)); } else { - int64_t converted = val; + int64_t converted = (int64_t)val; if ((val >= 1 && converted <= 0) || val < (double)LLONG_MIN) trap("i64.truncSFloat overflow"); return Literal(converted); } @@ -654,7 +654,7 @@ private: if (val > (double)std::numeric_limits<uint32_t>::max() || val <= (double)-1) trap("i32.truncUFloat overflow"); return Literal(uint32_t(val)); } else { - uint64_t converted = val; + uint64_t converted = (uint64_t)val; if (converted < val - 1 || val <= (double)-1) trap("i64.truncUFloat overflow"); return Literal(converted); } @@ -695,7 +695,7 @@ private: template <class LS> size_t getFinalAddress(LS* curr, Literal ptr) { - auto trapIfGt = [this](size_t lhs, size_t rhs, const char* msg) { + auto trapIfGt = [this](uint64_t lhs, uint64_t rhs, const char* msg) { if (lhs > rhs) { std::stringstream ss; ss << msg << ": " << lhs << " > " << rhs; diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index 965336857..575ceff97 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -23,6 +23,8 @@ #define wasm_wasm_s_parser_h #include <cmath> +#include <cctype> +#include <limits> #include "wasm.h" #include "mixed_arena.h" @@ -825,8 +827,8 @@ private: ret->align = atoi(eq); } else if (str[0] == 'o') { uint64_t offset = atoll(eq); - if (offset > 0xffffffff) onError(); - ret->offset = offset; + if (offset > std::numeric_limits<uint32_t>::max()) onError(); + ret->offset = (uint32_t)offset; } else onError(); i++; } |