From 5d92d866d8326b1908328485cccd2f8ebe57ac75 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 27 Nov 2018 15:12:21 -0800 Subject: 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. --- src/tools/wasm-reduce.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/tools/wasm-reduce.cpp') 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 WalkerPasstype == 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 WalkerPasstype) { 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 WalkerPassmakeUnary(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 } - -- cgit v1.2.3