diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/asmjs/asm_v_wasm.cpp | 25 | ||||
-rw-r--r-- | src/binaryen-c.cpp | 10 | ||||
-rw-r--r-- | src/ir/ExpressionAnalyzer.cpp | 10 | ||||
-rw-r--r-- | src/ir/abstract.h | 11 | ||||
-rw-r--r-- | src/ir/cost.h | 12 | ||||
-rw-r--r-- | src/ir/literal-utils.h | 5 | ||||
-rw-r--r-- | src/parsing.h | 5 | ||||
-rw-r--r-- | src/passes/ConstHoisting.cpp | 7 | ||||
-rw-r--r-- | src/passes/DeadCodeElimination.cpp | 4 | ||||
-rw-r--r-- | src/passes/FuncCastEmulation.cpp | 8 | ||||
-rw-r--r-- | src/passes/InstrumentLocals.cpp | 5 | ||||
-rw-r--r-- | src/passes/Print.cpp | 9 | ||||
-rw-r--r-- | src/passes/Souperify.cpp | 1 | ||||
-rw-r--r-- | src/shell-interface.h | 3 | ||||
-rw-r--r-- | src/tools/fuzzing.h | 34 | ||||
-rw-r--r-- | src/tools/spec-wrapper.h | 4 | ||||
-rw-r--r-- | src/tools/wasm-reduce.cpp | 24 | ||||
-rw-r--r-- | src/wasm-binary.h | 4 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 17 | ||||
-rw-r--r-- | src/wasm-js.cpp | 4 | ||||
-rw-r--r-- | src/wasm-stack.h | 15 | ||||
-rw-r--r-- | src/wasm-traversal.h | 2 | ||||
-rw-r--r-- | src/wasm/literal.cpp | 39 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 4 | ||||
-rw-r--r-- | src/wasm/wasm-type.cpp | 7 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 8 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 6 |
27 files changed, 176 insertions, 107 deletions
diff --git a/src/asmjs/asm_v_wasm.cpp b/src/asmjs/asm_v_wasm.cpp index bda1c3080..7102c588c 100644 --- a/src/asmjs/asm_v_wasm.cpp +++ b/src/asmjs/asm_v_wasm.cpp @@ -27,21 +27,25 @@ Type asmToWasmType(AsmType asmType) { case ASM_FLOAT: return Type::f32; case ASM_INT64: return Type::i64; case ASM_NONE: return Type::none; - default: {} + case ASM_FLOAT32X4: + case ASM_FLOAT64X2: + case ASM_INT8X16: + case ASM_INT16X8: + case ASM_INT32X4: WASM_UNREACHABLE(); } - abort(); + WASM_UNREACHABLE(); } AsmType wasmToAsmType(Type type) { switch (type) { - case Type::i32: return ASM_INT; - case Type::f32: return ASM_FLOAT; - case Type::f64: return ASM_DOUBLE; - case Type::i64: return ASM_INT64; - case Type::none: return ASM_NONE; - default: {} + case i32: return ASM_INT; + case f32: return ASM_FLOAT; + case f64: return ASM_DOUBLE; + case i64: return ASM_INT64; + case none: return ASM_NONE; + case unreachable: WASM_UNREACHABLE(); } - abort(); + WASM_UNREACHABLE(); } char getSig(Type type) { @@ -51,8 +55,9 @@ char getSig(Type type) { case f32: return 'f'; case f64: return 'd'; case none: return 'v'; - default: abort(); + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } std::string getSig(const FunctionType *type) { diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index e2ad349a0..aeef53343 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -49,7 +49,8 @@ BinaryenLiteral toBinaryenLiteral(Literal x) { case Type::i64: ret.i64 = x.geti64(); break; case Type::f32: ret.i32 = x.reinterpreti32(); break; case Type::f64: ret.i64 = x.reinterpreti64(); break; - default: abort(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } return ret; } @@ -60,8 +61,10 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) { case Type::i64: return Literal(x.i64); case Type::f32: return Literal(x.i32).castToF32(); case Type::f64: return Literal(x.i64).castToF64(); - default: abort(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } // Mutexes (global for now; in theory if multiple modules @@ -657,7 +660,8 @@ BinaryenExpressionRef BinaryenConst(BinaryenModuleRef module, BinaryenLiteral va std::cout << "));\n"; break; } - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } } return static_cast<Expression*>(ret); diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp index f9b981129..7788f7cde 100644 --- a/src/ir/ExpressionAnalyzer.cpp +++ b/src/ir/ExpressionAnalyzer.cpp @@ -294,7 +294,10 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left, Expression* right, Expr case Expression::Id::UnreachableId: { break; } - default: WASM_UNREACHABLE(); + case Expression::Id::InvalidId: + case Expression::Id::NumExpressionIds: { + WASM_UNREACHABLE(); + } } #undef CHECK #undef PUSH @@ -544,7 +547,10 @@ HashType ExpressionAnalyzer::hash(Expression* curr) { case Expression::Id::UnreachableId: { break; } - default: WASM_UNREACHABLE(); + case Expression::Id::InvalidId: + case Expression::Id::NumExpressionIds: { + WASM_UNREACHABLE(); + } } #undef HASH #undef PUSH diff --git a/src/ir/abstract.h b/src/ir/abstract.h index 7066d2633..2fe464c1d 100644 --- a/src/ir/abstract.h +++ b/src/ir/abstract.h @@ -62,7 +62,10 @@ inline UnaryOp getUnary(Type type, Op op) { } break; } - default: return InvalidUnary; + case none: + case unreachable: { + return InvalidUnary; + } } WASM_UNREACHABLE(); } @@ -137,7 +140,10 @@ inline BinaryOp getBinary(Type type, Op op) { } break; } - default: return InvalidBinary; + case none: + case unreachable: { + return InvalidBinary; + } } WASM_UNREACHABLE(); } @@ -147,4 +153,3 @@ inline BinaryOp getBinary(Type type, Op op) { } // namespace wasm #endif // wasm_ir_abstract_h - diff --git a/src/ir/cost.h b/src/ir/cost.h index 6d1078094..6dabf2fcb 100644 --- a/src/ir/cost.h +++ b/src/ir/cost.h @@ -136,10 +136,15 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> { case ConvertSInt32ToFloat64: case ConvertUInt32ToFloat64: case ConvertSInt64ToFloat64: - case ConvertUInt64ToFloat64: ret = 1; break; + case ConvertUInt64ToFloat64: + case ExtendS8Int32: + case ExtendS16Int32: + case ExtendS8Int64: + case ExtendS16Int64: + case ExtendS32Int64: ret = 1; break; case SqrtFloat32: case SqrtFloat64: ret = 2; break; - default: WASM_UNREACHABLE(); + case InvalidUnary: WASM_UNREACHABLE(); } return ret + visit(curr->value); } @@ -222,7 +227,7 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> { case NeFloat32: ret = 1; break; case EqFloat64: ret = 1; break; case NeFloat64: ret = 1; break; - default: WASM_UNREACHABLE(); + case InvalidBinary: WASM_UNREACHABLE(); } return ret + visit(curr->left) + visit(curr->right); } @@ -249,4 +254,3 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> { } // namespace wasm #endif // wasm_ir_cost_h - diff --git a/src/ir/literal-utils.h b/src/ir/literal-utils.h index 166897739..c78fdc663 100644 --- a/src/ir/literal-utils.h +++ b/src/ir/literal-utils.h @@ -29,8 +29,10 @@ inline Literal makeLiteralFromInt32(int32_t x, Type type) { case i64: return Literal(int64_t(x)); break; case f32: return Literal(float(x)); break; case f64: return Literal(double(x)); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } inline Literal makeLiteralZero(Type type) { @@ -53,4 +55,3 @@ inline Expression* makeZero(Type type, Module& wasm) { } // namespace wasm #endif // wasm_ir_literal_utils_h - diff --git a/src/parsing.h b/src/parsing.h index c6a3b8a83..3304122f2 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -213,7 +213,10 @@ inline Expression* parseConst(cashew::IString s, Type type, MixedArena& allocato ret->value = Literal(strtod(str, &end)); break; } - default: return nullptr; + case none: + case unreachable: { + return nullptr; + } } if (ret->value.type != type) { throw ParseException("parsed type does not match expected type"); diff --git a/src/passes/ConstHoisting.cpp b/src/passes/ConstHoisting.cpp index e598a2995..c0798fe78 100644 --- a/src/passes/ConstHoisting.cpp +++ b/src/passes/ConstHoisting.cpp @@ -77,7 +77,7 @@ private: bool worthHoisting(Literal value, Index num) { if (num < MIN_USES) return false; // measure the size of the constant - Index size; + Index size = 0; switch (value.type) { case i32: { size = getWrittenSize(S32LEB(value.geti32())); @@ -92,7 +92,10 @@ private: size = getTypeSize(value.type); break; } - default: WASM_UNREACHABLE(); + case none: + case unreachable: { + WASM_UNREACHABLE(); + } } // compute the benefit, of replacing the uses with // one use + a set and then a get for each use diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp index 87dbacf64..2e62197b5 100644 --- a/src/passes/DeadCodeElimination.cpp +++ b/src/passes/DeadCodeElimination.cpp @@ -257,8 +257,8 @@ struct DeadCodeElimination : public WalkerPass<PostWalker<DeadCodeElimination>> case Expression::Id::AtomicRMWId: DELEGATE(AtomicRMW); case Expression::Id::AtomicWaitId: DELEGATE(AtomicWait); case Expression::Id::AtomicWakeId: DELEGATE(AtomicWake); - case Expression::Id::InvalidId: - default: WASM_UNREACHABLE(); + case Expression::Id::InvalidId: WASM_UNREACHABLE(); + case Expression::Id::NumExpressionIds: WASM_UNREACHABLE(); } #undef DELEGATE return; diff --git a/src/passes/FuncCastEmulation.cpp b/src/passes/FuncCastEmulation.cpp index 30ae3e5e8..301a4b9fd 100644 --- a/src/passes/FuncCastEmulation.cpp +++ b/src/passes/FuncCastEmulation.cpp @@ -76,10 +76,6 @@ static Expression* toABI(Expression* value, Module* module) { // can leave it, the call isn't taken anyhow break; } - default: { - // SIMD may be interesting some day - WASM_UNREACHABLE(); - } } return value; } @@ -114,10 +110,6 @@ static Expression* fromABI(Expression* value, Type type, Module* module) { // can leave it, the call isn't taken anyhow break; } - default: { - // SIMD may be interesting some day - WASM_UNREACHABLE(); - } } return value; } diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index 4da41da17..9a8c34024 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -72,7 +72,8 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case i64: return; // TODO case f32: import = get_f32; break; case f64: import = get_f64; break; - default: WASM_UNREACHABLE(); + case none: WASM_UNREACHABLE(); + case unreachable: WASM_UNREACHABLE(); } replaceCurrent( builder.makeCall( @@ -96,7 +97,7 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case f32: import = set_f32; break; case f64: import = set_f64; break; case unreachable: return; // nothing to do here - default: WASM_UNREACHABLE(); + case none: WASM_UNREACHABLE(); } curr->value = builder.makeCall( import, diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 14ef584be..a70a96f17 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -292,7 +292,7 @@ struct PrintExpressionContents : public Visitor<PrintExpressionContents> { case ExtendS8Int64: o << "i64.extend8_s"; break; case ExtendS16Int64: o << "i64.extend16_s"; break; case ExtendS32Int64: o << "i64.extend32_s"; break; - default: abort(); + case InvalidUnary: WASM_UNREACHABLE(); } } void visitBinary(Binary* curr) { @@ -378,7 +378,7 @@ struct PrintExpressionContents : public Visitor<PrintExpressionContents> { case GtFloat64: o << "f64.gt"; break; case GeFloat64: o << "f64.ge"; break; - default: abort(); + case InvalidBinary: WASM_UNREACHABLE(); } restoreNormalColor(o); } @@ -395,7 +395,6 @@ struct PrintExpressionContents : public Visitor<PrintExpressionContents> { switch (curr->op) { case CurrentMemory: printMedium(o, "current_memory"); break; case GrowMemory: printMedium(o, "grow_memory"); break; - default: WASM_UNREACHABLE(); } } void visitNop(Nop* curr) { @@ -775,7 +774,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { decIndent(); break; } - default: { + case CurrentMemory: { o << ')'; } } @@ -819,7 +818,7 @@ struct PrintSExpression : public Visitor<PrintSExpression> { case ExternalKind::Table: o << "table"; break; case ExternalKind::Memory: o << "memory"; break; case ExternalKind::Global: o << "global"; break; - default: WASM_UNREACHABLE(); + case ExternalKind::Invalid: WASM_UNREACHABLE(); } o << ' '; printName(curr->value, o) << "))"; diff --git a/src/passes/Souperify.cpp b/src/passes/Souperify.cpp index a54146d38..5875c8f42 100644 --- a/src/passes/Souperify.cpp +++ b/src/passes/Souperify.cpp @@ -688,4 +688,3 @@ Pass *createSouperifySingleUsePass() { } } // namespace wasm - diff --git a/src/shell-interface.h b/src/shell-interface.h index abfd4ac18..54c2e580e 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -126,7 +126,8 @@ struct ShellExternalInterface final : ModuleInstance::ExternalInterface { case i64: globals[import->name] = Literal(int64_t(666)); break; case f32: globals[import->name] = Literal(float(666.6)); break; case f64: globals[import->name] = Literal(double(666.6)); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } } }); diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 8fa2e08fa..9a33524ec 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -665,7 +665,7 @@ private: return makeTrivial(type); } nesting++; - Expression* ret; + Expression* ret = nullptr; switch (type) { case i32: case i64: @@ -673,7 +673,6 @@ private: case f64: ret = _makeConcrete(type); break; case none: ret = _makenone(); break; case unreachable: ret = _makeunreachable(); break; - default: WASM_UNREACHABLE(); } assert(ret->type == type); // we should create the right type of thing nesting--; @@ -1088,8 +1087,10 @@ private: case f64: { return builder.makeLoad(8, false, offset, pick(1, 2, 4, 8), ptr, type); } - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Expression* makeLoad(Type type) { @@ -1148,8 +1149,10 @@ private: case f64: { return builder.makeStore(8, offset, pick(1, 2, 4, 8), ptr, value, type); } - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Store* makeStore(Type type) { @@ -1173,7 +1176,8 @@ private: case i64: value = Literal(get64()); break; case f32: value = Literal(getFloat()); break; case f64: value = Literal(getDouble()); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } @@ -1194,7 +1198,8 @@ private: case i64: value = Literal(int64_t(small)); break; case f32: value = Literal(float(small)); break; case f64: value = Literal(double(small)); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } break; } @@ -1230,7 +1235,10 @@ private: std::numeric_limits<int64_t>::min(), std::numeric_limits<int64_t>::max(), std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint64_t>::max())); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: { + WASM_UNREACHABLE(); + } } // tweak around special values if (oneIn(3)) { // +- 1 @@ -1248,7 +1256,8 @@ private: case i64: value = Literal(int64_t(1) << upTo(64)); break; case f32: value = Literal(float(int64_t(1) << upTo(64))); break; case f64: value = Literal(double(int64_t(1) << upTo(64))); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } // maybe negative if (oneIn(2)) { @@ -1325,7 +1334,10 @@ private: } WASM_UNREACHABLE(); } - default: WASM_UNREACHABLE(); + case none: + case unreachable: { + WASM_UNREACHABLE(); + } } WASM_UNREACHABLE(); } @@ -1361,7 +1373,8 @@ private: case f64: { return makeDeNanOp(makeBinary({ pick(AddFloat64, SubFloat64, MulFloat64, DivFloat64, CopySignFloat64, MinFloat64, MaxFloat64), make(f64), make(f64) })); } - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } WASM_UNREACHABLE(); } @@ -1619,4 +1632,3 @@ private: // XXX Switch class has a condition?! is it real? should the node type be the value type if it exists?! // TODO copy an existing function and replace just one node in it - diff --git a/src/tools/spec-wrapper.h b/src/tools/spec-wrapper.h index 82c45ffb6..ed27b6f34 100644 --- a/src/tools/spec-wrapper.h +++ b/src/tools/spec-wrapper.h @@ -34,7 +34,8 @@ static std::string generateSpecWrapper(Module& wasm) { case i64: ret += "(i64.const 0)"; break; case f32: ret += "(f32.const 0)"; break; case f64: ret += "(f64.const 0)"; break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } ret += " "; } @@ -44,4 +45,3 @@ static std::string generateSpecWrapper(Module& wasm) { } } // namespace wasm - 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 } - diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 3dac4de06..f88bd2d64 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -643,7 +643,7 @@ enum MemoryFlags { inline S32LEB binaryType(Type type) { - int ret; + int ret = 0; switch (type) { // None only used for block signatures. TODO: Separate out? case none: ret = BinaryConsts::EncodedType::Empty; break; @@ -651,7 +651,7 @@ inline S32LEB binaryType(Type type) { case i64: ret = BinaryConsts::EncodedType::i64; break; case f32: ret = BinaryConsts::EncodedType::f32; break; case f64: ret = BinaryConsts::EncodedType::f64; break; - default: abort(); + case unreachable: WASM_UNREACHABLE(); } return S32LEB(ret); } diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 8bd951eef..aeacdfc20 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -296,8 +296,9 @@ public: case ReinterpretFloat64: return value.castToI64(); case DemoteFloat64: return value.demote(); - default: WASM_UNREACHABLE(); + case InvalidUnary: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Flow visitBinary(Binary *curr) { NOTE_ENTER("Binary"); @@ -417,8 +418,10 @@ public: case MinFloat64: return left.min(right); case MaxFloat32: case MaxFloat64: return left.max(right); - default: WASM_UNREACHABLE(); + + case InvalidBinary: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Flow visitSelect(Select *curr) { NOTE_ENTER("Select"); @@ -575,8 +578,10 @@ public: } case f32: return Literal(load32u(addr)).castToF32(); case f64: return Literal(load64u(addr)).castToF64(); - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } virtual void store(Store* store, Address addr, Literal value) { switch (store->valueType) { @@ -602,7 +607,8 @@ public: // write floats carefully, ensuring all bits reach memory case f32: store32(addr, value.reinterpreti32()); break; case f64: store64(addr, value.reinterpreti64()); break; - default: WASM_UNREACHABLE(); + case none: + case unreachable: WASM_UNREACHABLE(); } } @@ -862,7 +868,6 @@ public: case Or: computed = computed.or_(value.value); break; case Xor: computed = computed.xor_(value.value); break; case Xchg: computed = value.value; break; - default: WASM_UNREACHABLE(); } instance.doAtomicStore(addr, curr->bytes, computed); return loaded; @@ -939,8 +944,8 @@ public: instance.memorySize = newSize; return Literal(int32_t(ret)); } - default: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } void trap(const char* why) override { diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp index 381487cd0..6e4b03aca 100644 --- a/src/wasm-js.cpp +++ b/src/wasm-js.cpp @@ -250,10 +250,12 @@ extern "C" void EMSCRIPTEN_KEEPALIVE instantiate() { switch (type) { case none: return Literal(); case i32: return Literal((int32_t)ret); + case i64: WASM_UNREACHABLE(); case f32: return Literal((float)ret); case f64: return Literal((double)ret); - default: abort(); + case unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } void importGlobals(std::map<Name, Literal>& globals, Module& wasm) override { diff --git a/src/wasm-stack.h b/src/wasm-stack.h index dc3416789..c013a57f1 100644 --- a/src/wasm-stack.h +++ b/src/wasm-stack.h @@ -628,7 +628,7 @@ void StackWriter<Mode, Parent>::visitLoad(Load* curr) { case f32: o << int8_t(BinaryConsts::F32LoadMem); break; case f64: o << int8_t(BinaryConsts::F64LoadMem); break; case unreachable: return; // the pointer is unreachable, so we are never reached; just don't emit a load - default: WASM_UNREACHABLE(); + case none: WASM_UNREACHABLE(); } } else { o << int8_t(BinaryConsts::AtomicPrefix); @@ -693,7 +693,8 @@ void StackWriter<Mode, Parent>::visitStore(Store* curr) { } case f32: o << int8_t(BinaryConsts::F32StoreMem); break; case f64: o << int8_t(BinaryConsts::F64StoreMem); break; - default: abort(); + case none: + case unreachable: WASM_UNREACHABLE(); } } else { o << int8_t(BinaryConsts::AtomicPrefix); @@ -882,7 +883,8 @@ void StackWriter<Mode, Parent>::visitConst(Const* curr) { o << int8_t(BinaryConsts::F64Const) << curr->value.reinterpreti64(); break; } - default: abort(); + case none: + case unreachable: WASM_UNREACHABLE(); } if (debug) std::cerr << "zz const node done.\n"; } @@ -949,7 +951,7 @@ void StackWriter<Mode, Parent>::visitUnary(Unary* curr) { case ExtendS8Int64: o << int8_t(BinaryConsts::I64ExtendS8); break; case ExtendS16Int64: o << int8_t(BinaryConsts::I64ExtendS16); break; case ExtendS32Int64: o << int8_t(BinaryConsts::I64ExtendS32); break; - default: abort(); + case InvalidUnary: WASM_UNREACHABLE(); } } @@ -1043,7 +1045,7 @@ void StackWriter<Mode, Parent>::visitBinary(Binary* curr) { case LeFloat64: o << int8_t(BinaryConsts::F64Le); break; case GtFloat64: o << int8_t(BinaryConsts::F64Gt); break; case GeFloat64: o << int8_t(BinaryConsts::F64Ge); break; - default: abort(); + case InvalidBinary: WASM_UNREACHABLE(); } } @@ -1083,7 +1085,6 @@ void StackWriter<Mode, Parent>::visitHost(Host* curr) { visitChild(curr->operands[0]); break; } - default: WASM_UNREACHABLE(); } if (justAddToStack(curr)) return; switch (curr->op) { @@ -1095,7 +1096,6 @@ void StackWriter<Mode, Parent>::visitHost(Host* curr) { o << int8_t(BinaryConsts::GrowMemory); break; } - default: WASM_UNREACHABLE(); } o << U32LEB(0); // Reserved flags field } @@ -1191,4 +1191,3 @@ StackInst* StackWriter<Mode, Parent>::makeStackInst(StackInst::Op op, Expression } // namespace wasm #endif // wasm_stack_h - diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 5bb176756..9ea1124d0 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -602,7 +602,7 @@ struct PostWalker : public Walker<SubType, VisitorType> { self->pushTask(SubType::doVisitUnreachable, currp); break; } - default: WASM_UNREACHABLE(); + case Expression::Id::NumExpressionIds: WASM_UNREACHABLE(); } } }; diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index b5c575b1c..3eb508bde 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -75,8 +75,9 @@ int64_t Literal::getBits() const { switch (type) { case Type::i32: case Type::f32: return i32; case Type::i64: case Type::f64: return i64; - default: abort(); + case Type::none: case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } bool Literal::operator==(const Literal& other) const { @@ -158,12 +159,12 @@ void Literal::printDouble(std::ostream& o, double d) { std::ostream& operator<<(std::ostream& o, Literal literal) { prepareMinorColor(o) << printType(literal.type) << ".const "; switch (literal.type) { - case none: o << "?"; break; + case Type::none: o << "?"; break; case Type::i32: o << literal.i32; break; case Type::i64: o << literal.i64; break; case Type::f32: literal.printFloat(o, literal.getf32()); break; case Type::f64: literal.printDouble(o, literal.getf64()); break; - default: WASM_UNREACHABLE(); + case Type::unreachable: WASM_UNREACHABLE(); } restoreNormalColor(o); return o; @@ -259,8 +260,10 @@ Literal Literal::eqz() const { case Type::i64: return eq(Literal(int64_t(0))); case Type::f32: return eq(Literal(float(0))); case Type::f64: return eq(Literal(double(0))); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::neg() const { @@ -269,8 +272,10 @@ Literal Literal::neg() const { case Type::i64: return Literal(-uint64_t(i64)); case Type::f32: return Literal(i32 ^ 0x80000000).castToF32(); case Type::f64: return Literal(int64_t(i64 ^ 0x8000000000000000ULL)).castToF64(); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::abs() const { @@ -279,8 +284,10 @@ Literal Literal::abs() const { case Type::i64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL)); case Type::f32: return Literal(i32 & 0x7fffffff).castToF32(); case Type::f64: return Literal(int64_t(i64 & 0x7fffffffffffffffULL)).castToF64(); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::ceil() const { @@ -344,8 +351,10 @@ Literal Literal::add(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) + uint64_t(other.i64)); case Type::f32: return Literal(getf32() + other.getf32()); case Type::f64: return Literal(getf64() + other.getf64()); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::sub(const Literal& other) const { @@ -354,8 +363,10 @@ Literal Literal::sub(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) - uint64_t(other.i64)); case Type::f32: return Literal(getf32() - other.getf32()); case Type::f64: return Literal(getf64() - other.getf64()); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::mul(const Literal& other) const { @@ -364,8 +375,10 @@ Literal Literal::mul(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) * uint64_t(other.i64)); case Type::f32: return Literal(getf32() * other.getf32()); case Type::f64: return Literal(getf64() * other.getf64()); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::div(const Literal& other) const { @@ -516,8 +529,10 @@ Literal Literal::eq(const Literal& other) const { case Type::i64: return Literal(i64 == other.i64); case Type::f32: return Literal(getf32() == other.getf32()); case Type::f64: return Literal(getf64() == other.getf64()); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::ne(const Literal& other) const { @@ -526,8 +541,10 @@ Literal Literal::ne(const Literal& other) const { case Type::i64: return Literal(i64 != other.i64); case Type::f32: return Literal(getf32() != other.getf32()); case Type::f64: return Literal(getf64() != other.getf64()); - default: WASM_UNREACHABLE(); + case Type::none: + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Literal Literal::ltS(const Literal& other) const { diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 97e70aeab..2dc89ee90 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -819,7 +819,9 @@ Type WasmBinaryBuilder::getType() { case BinaryConsts::EncodedType::i64: return i64; case BinaryConsts::EncodedType::f32: return f32; case BinaryConsts::EncodedType::f64: return f64; - default: throwError("invalid wasm type: " + std::to_string(type)); + case BinaryConsts::EncodedType::AnyFunc: + case BinaryConsts::EncodedType::Func: + throwError("invalid wasm type: " + std::to_string(type)); } WASM_UNREACHABLE(); } diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index b030e87ae..89eadcd47 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -29,8 +29,8 @@ const char* printType(Type type) { case Type::f32: return "f32"; case Type::f64: return "f64"; case Type::unreachable: return "unreachable"; - default: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } unsigned getTypeSize(Type type) { @@ -40,15 +40,16 @@ unsigned getTypeSize(Type type) { case Type::i64: return 8; case Type::f32: return 4; case Type::f64: return 8; - default: WASM_UNREACHABLE(); + case Type::unreachable: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } Type getType(unsigned size, bool float_) { if (size < 4) return Type::i32; if (size == 4) return float_ ? Type::f32 : Type::i32; if (size == 8) return float_ ? Type::f64 : Type::i64; - abort(); + WASM_UNREACHABLE(); } Type getReachableType(Type a, Type b) { diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 769f17d59..0b0d165ed 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -671,7 +671,7 @@ void FunctionValidator::visitBinary(Binary* curr) { shouldBeEqualOrFirstIsUnreachable(curr->left->type, f64, curr, "f64 op"); break; } - default: WASM_UNREACHABLE(); + case InvalidBinary: WASM_UNREACHABLE(); } } @@ -753,7 +753,7 @@ void FunctionValidator::visitUnary(Unary* curr) { case DemoteFloat64: shouldBeEqual(curr->value->type, f64, curr, "demote type must be correct"); break; case ReinterpretInt32: shouldBeEqual(curr->value->type, i32, curr, "reinterpret/i32 type must be correct"); break; case ReinterpretInt64: shouldBeEqual(curr->value->type, i64, curr, "reinterpret/i64 type must be correct"); break; - default: abort(); + case InvalidUnary: WASM_UNREACHABLE(); } } @@ -790,7 +790,6 @@ void FunctionValidator::visitHost(Host* curr) { break; } case CurrentMemory: break; - default: WASM_UNREACHABLE(); } } @@ -863,7 +862,8 @@ void FunctionValidator::validateAlignment(size_t align, Type type, Index bytes, shouldBeTrue(align <= 8, curr, "alignment must not exceed natural"); break; } - default: {} + case none: + case unreachable: {} } } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index 72fc3b202..1554ded62 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -102,8 +102,9 @@ const char* getExpressionName(Expression* curr) { case Expression::Id::AtomicRMWId: return "atomic_rmw"; case Expression::Id::AtomicWaitId: return "atomic_wait"; case Expression::Id::AtomicWakeId: return "atomic_wake"; - default: WASM_UNREACHABLE(); + case Expression::Id::NumExpressionIds: WASM_UNREACHABLE(); } + WASM_UNREACHABLE(); } // core AST type checking @@ -480,7 +481,7 @@ void Unary::finalize() { case ConvertUInt32ToFloat64: case ConvertSInt64ToFloat64: case ConvertUInt64ToFloat64: type = f64; break; - default: std::cerr << "waka " << op << '\n'; WASM_UNREACHABLE(); + case InvalidUnary: WASM_UNREACHABLE(); } } @@ -565,7 +566,6 @@ void Host::finalize() { } break; } - default: WASM_UNREACHABLE(); } } |