diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2018-11-27 15:12:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-27 15:12:21 -0800 |
commit | 5d92d866d8326b1908328485cccd2f8ebe57ac75 (patch) | |
tree | 6f34e8815437b66c0ee083a61c1147a4257b68c6 /src/tools/wasm-reduce.cpp | |
parent | 70b949ffdc3e5f3fa83dd4044f632c95159674cf (diff) | |
download | binaryen-5d92d866d8326b1908328485cccd2f8ebe57ac75.tar.gz binaryen-5d92d866d8326b1908328485cccd2f8ebe57ac75.tar.bz2 binaryen-5d92d866d8326b1908328485cccd2f8ebe57ac75.zip |
Remove default cases (#1757)
Where reasonable from a readability perspective, remove default cases
in switches over types and instructions. This makes future feature
additions easier by making the compiler complain about each location
where new types and instructions are not yet handled.
Diffstat (limited to 'src/tools/wasm-reduce.cpp')
-rw-r--r-- | src/tools/wasm-reduce.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 4de8263e3..76a3034cf 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -51,7 +51,7 @@ std::string GetLastErrorStdStr() { if (error) { LPVOID lpMsgBuf; DWORD bufLen = FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, @@ -497,23 +497,27 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor< for (auto* child : ChildIterator(curr)) { if (child->type == curr->type) continue; // already tried if (!isConcreteType(child->type)) continue; // no conversion - Expression* fixed; + Expression* fixed = nullptr; switch (curr->type) { case i32: { switch (child->type) { + case i32: WASM_UNREACHABLE(); case i64: fixed = builder->makeUnary(WrapInt64, child); break; case f32: fixed = builder->makeUnary(TruncSFloat32ToInt32, child); break; case f64: fixed = builder->makeUnary(TruncSFloat64ToInt32, child); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } case i64: { switch (child->type) { case i32: fixed = builder->makeUnary(ExtendSInt32, child); break; + case i64: WASM_UNREACHABLE(); case f32: fixed = builder->makeUnary(TruncSFloat32ToInt64, child); break; case f64: fixed = builder->makeUnary(TruncSFloat64ToInt64, child); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } @@ -521,8 +525,10 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor< switch (child->type) { case i32: fixed = builder->makeUnary(ConvertSInt32ToFloat32, child); break; case i64: fixed = builder->makeUnary(ConvertSInt64ToFloat32, child); break; + case f32: WASM_UNREACHABLE(); case f64: fixed = builder->makeUnary(DemoteFloat64, child); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } @@ -531,11 +537,14 @@ struct Reducer : public WalkerPass<PostWalker<Reducer, UnifiedExpressionVisitor< case i32: fixed = builder->makeUnary(ConvertSInt32ToFloat64, child); break; case i64: fixed = builder->makeUnary(ConvertSInt64ToFloat64, child); break; case f32: fixed = builder->makeUnary(PromoteFloat32, child); break; - default: WASM_UNREACHABLE(); + case f64: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } assert(fixed->type == curr->type); if (tryToReplaceCurrent(fixed)) return; @@ -1049,4 +1058,3 @@ int main(int argc, const char* argv[]) { std::cerr << "|finished, final size: " << file_size(working) << "\n"; copy_file(working, test); // just to avoid confusion } - |