diff options
author | Sam Clegg <sbc@chromium.org> | 2019-12-05 13:09:21 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-05 13:09:21 -0600 |
commit | a28343a33ed28b4d5c83c37e350aceaf09b5246f (patch) | |
tree | 084a487cdf79e8025246d2a85d5578c113c9ad51 | |
parent | cbf121df96cfce5038f52ed04f9780e19ed3b762 (diff) | |
download | binaryen-a28343a33ed28b4d5c83c37e350aceaf09b5246f.tar.gz binaryen-a28343a33ed28b4d5c83c37e350aceaf09b5246f.tar.bz2 binaryen-a28343a33ed28b4d5c83c37e350aceaf09b5246f.zip |
Add string parameter to WASM_UNREACHABLE (#2499)
This works more like llvm's unreachable handler in that is preserves
information even in release builds.
56 files changed, 450 insertions, 420 deletions
diff --git a/src/abi/stack.h b/src/abi/stack.h index 22cd8ba3c..68ac7f08a 100644 --- a/src/abi/stack.h +++ b/src/abi/stack.h @@ -93,7 +93,7 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) { builder.makeLocalGet(local, PointerType), builder.makeConst(Literal(int32_t(size)))); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unhandled PointerType"); } block->list.push_back(builder.makeGlobalSet(stackPointer->name, added)); auto makeStackRestore = [&]() { diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 24e9ddc76..048d363ef 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1548,7 +1548,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } else { assert(old == none); @@ -2060,7 +2060,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { ret->op = NegFloat32; ret->type = Type::f32; } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected asm type"); } return ret; } else if (ast[1] == B_NOT) { @@ -2195,7 +2195,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { ret->type = value->type; return ret; } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } if (name == Math_floor || name == Math_sqrt || name == Math_ceil) { @@ -2328,7 +2328,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { process(ast[2][2]), asmToWasmType(view.type)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected atomic op"); } bool tableCall = false; if (wasmOnly) { diff --git a/src/asmjs/asm_v_wasm.cpp b/src/asmjs/asm_v_wasm.cpp index 143d6667e..2fba0520a 100644 --- a/src/asmjs/asm_v_wasm.cpp +++ b/src/asmjs/asm_v_wasm.cpp @@ -38,7 +38,7 @@ Type asmToWasmType(AsmType asmType) { case ASM_INT32X4: return Type::v128; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } AsmType wasmToAsmType(Type type) { @@ -60,9 +60,9 @@ AsmType wasmToAsmType(Type type) { case none: return ASM_NONE; case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } char getSig(Type type) { @@ -84,9 +84,9 @@ char getSig(Type type) { case none: return 'v'; case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } std::string getSig(const FunctionType* type) { diff --git a/src/binaryen-c.cpp b/src/binaryen-c.cpp index 697d9a1e3..87e1fdb0b 100644 --- a/src/binaryen-c.cpp +++ b/src/binaryen-c.cpp @@ -74,7 +74,7 @@ BinaryenLiteral toBinaryenLiteral(Literal x) { case Type::exnref: // there's no exnref literals case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } return ret; } @@ -95,9 +95,9 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) { case Type::exnref: // there's no exnref literals case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } // Mutexes (global for now; in theory if multiple modules @@ -216,7 +216,7 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) { case Type::exnref: // there's no exnref literals case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h index 2e4c45950..8693831ad 100644 --- a/src/cfg/cfg-traversal.h +++ b/src/cfg/cfg-traversal.h @@ -365,7 +365,7 @@ private: return; } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("not found"); } }; diff --git a/src/compiler-support.h b/src/compiler-support.h index c75676d54..5f3edacea 100644 --- a/src/compiler-support.h +++ b/src/compiler-support.h @@ -25,27 +25,10 @@ #define __has_builtin(x) 0 #endif -// If control flow reaches the point of the WASM_UNREACHABLE(), the program is -// undefined. -#if __has_builtin(__builtin_unreachable) && defined(NDEBUG) -#define WASM_UNREACHABLE() __builtin_unreachable() +#if __has_builtin(__builtin_unreachable) +#define WASM_BUILTIN_UNREACHABLE __builtin_unreachable() #elif defined(_MSC_VER) -#define WASM_UNREACHABLE() __assume(false) -#elif __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) -#include "sanitizer/common_interface_defs.h" -#define WASM_UNREACHABLE() \ - do { \ - __sanitizer_print_stack_trace(); \ - __builtin_trap(); \ - } while (0) -#else -#include <assert.h> -#include <stdlib.h> -#define WASM_UNREACHABLE() \ - do { \ - assert(false); \ - abort(); \ - } while (0) +#define WASM_BUILTIN_UNREACHABLE __assume(false) #endif #ifdef __GNUC__ diff --git a/src/dataflow/graph.h b/src/dataflow/graph.h index 2d9b87873..873c4f218 100644 --- a/src/dataflow/graph.h +++ b/src/dataflow/graph.h @@ -547,7 +547,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { opposite = LeUInt64; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } auto* ret = visitBinary(builder.makeBinary(opposite, curr->right, curr->left)); @@ -783,7 +783,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> { // variable value. return Builder(*module).makeCall(FAKE_CALL, {}, node->wasmType); } else { - WASM_UNREACHABLE(); // TODO + WASM_UNREACHABLE("unexpected node type"); // TODO } } diff --git a/src/dataflow/node.h b/src/dataflow/node.h index 2966034ac..612a2f613 100644 --- a/src/dataflow/node.h +++ b/src/dataflow/node.h @@ -165,7 +165,7 @@ struct Node { case Bad: return unreachable; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid node type"); } } diff --git a/src/dataflow/utils.h b/src/dataflow/utils.h index 2d32dbeac..436ccc4d8 100644 --- a/src/dataflow/utils.h +++ b/src/dataflow/utils.h @@ -67,8 +67,6 @@ inline std::ostream& dump(Node* node, std::ostream& o, size_t indent = 0) { case Node::Type::Bad: o << "bad"; break; - default: - WASM_UNREACHABLE(); } if (!node->values.empty()) { o << '\n'; diff --git a/src/ir/ReFinalize.cpp b/src/ir/ReFinalize.cpp index bc5522c10..a8054d261 100644 --- a/src/ir/ReFinalize.cpp +++ b/src/ir/ReFinalize.cpp @@ -151,13 +151,15 @@ void ReFinalize::visitFunction(Function* curr) { } } -void ReFinalize::visitFunctionType(FunctionType* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitTable(Table* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitMemory(Memory* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitEvent(Event* curr) { WASM_UNREACHABLE(); } -void ReFinalize::visitModule(Module* curr) { WASM_UNREACHABLE(); } +void ReFinalize::visitFunctionType(FunctionType* curr) { + WASM_UNREACHABLE("unimp"); +} +void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE("unimp"); } +void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE("unimp"); } +void ReFinalize::visitTable(Table* curr) { WASM_UNREACHABLE("unimp"); } +void ReFinalize::visitMemory(Memory* curr) { WASM_UNREACHABLE("unimp"); } +void ReFinalize::visitEvent(Event* curr) { WASM_UNREACHABLE("unimp"); } +void ReFinalize::visitModule(Module* curr) { WASM_UNREACHABLE("unimp"); } void ReFinalize::updateBreakValueType(Name name, Type type) { if (type != unreachable || breakValues.count(name) == 0) { diff --git a/src/ir/abstract.h b/src/ir/abstract.h index 2653218b0..384f8b555 100644 --- a/src/ir/abstract.h +++ b/src/ir/abstract.h @@ -78,8 +78,7 @@ inline UnaryOp getUnary(Type type, Op op) { break; } case v128: { - assert(false && "v128 not implemented yet"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("v128 not implemented yet"); } case anyref: // there's no unary instructions for anyref case exnref: // there's no unary instructions for exnref @@ -88,7 +87,7 @@ inline UnaryOp getUnary(Type type, Op op) { return InvalidUnary; } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } inline BinaryOp getBinary(Type type, Op op) { @@ -210,8 +209,7 @@ inline BinaryOp getBinary(Type type, Op op) { break; } case v128: { - assert(false && "v128 not implemented yet"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("v128 not implemented yet"); } case anyref: // there's no binary instructions for anyref case exnref: // there's no binary instructions for exnref @@ -220,7 +218,7 @@ inline BinaryOp getBinary(Type type, Op op) { return InvalidBinary; } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } // namespace Abstract diff --git a/src/ir/bits.h b/src/ir/bits.h index faae4c723..cbac70d77 100644 --- a/src/ir/bits.h +++ b/src/ir/bits.h @@ -60,7 +60,7 @@ struct Bits { } else if (type == i64) { return amount & 63; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } static Index getEffectiveShifts(Expression* expr) { @@ -70,7 +70,7 @@ struct Bits { } else if (amount->type == i64) { return getEffectiveShifts(amount->value.geti64(), i64); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } static Expression* makeSignExt(Expression* value, Index bytes, Module& wasm) { diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h index 53279eee6..a22301e54 100644 --- a/src/ir/branch-utils.h +++ b/src/ir/branch-utils.h @@ -49,7 +49,7 @@ inline bool isBranchReachable(Expression* expr) { } else if (auto* br = expr->dynCast<BrOnExn>()) { return isBranchReachable(br); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } inline std::set<Name> getUniqueTargets(Break* br) { return {br->name}; } @@ -90,7 +90,7 @@ inline bool replacePossibleTarget(Expression* branch, Name from, Name to) { worked = true; } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } return worked; } diff --git a/src/ir/cost.h b/src/ir/cost.h index 60eb84b08..79be195f7 100644 --- a/src/ir/cost.h +++ b/src/ir/cost.h @@ -188,7 +188,7 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> { case WidenHighUVecI16x8ToVecI32x4: return 1; case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid unary op"); } return ret + visit(curr->value); } @@ -709,7 +709,7 @@ struct CostAnalyzer : public Visitor<CostAnalyzer, Index> { ret = 1; break; case InvalidBinary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid binary op"); } return ret + visit(curr->left) + visit(curr->right); } diff --git a/src/ir/utils.h b/src/ir/utils.h index e8c5b78b3..722277bc3 100644 --- a/src/ir/utils.h +++ b/src/ir/utils.h @@ -220,13 +220,13 @@ struct ReFinalizeNode : public OverriddenVisitor<ReFinalizeNode> { void visitPush(Push* curr) { curr->finalize(); } void visitPop(Pop* curr) { curr->finalize(); } - void visitFunctionType(FunctionType* curr) { WASM_UNREACHABLE(); } - void visitExport(Export* curr) { WASM_UNREACHABLE(); } - void visitGlobal(Global* curr) { WASM_UNREACHABLE(); } - void visitTable(Table* curr) { WASM_UNREACHABLE(); } - void visitMemory(Memory* curr) { WASM_UNREACHABLE(); } - void visitEvent(Event* curr) { WASM_UNREACHABLE(); } - void visitModule(Module* curr) { WASM_UNREACHABLE(); } + void visitFunctionType(FunctionType* curr) { WASM_UNREACHABLE("unimp"); } + void visitExport(Export* curr) { WASM_UNREACHABLE("unimp"); } + void visitGlobal(Global* curr) { WASM_UNREACHABLE("unimp"); } + void visitTable(Table* curr) { WASM_UNREACHABLE("unimp"); } + void visitMemory(Memory* curr) { WASM_UNREACHABLE("unimp"); } + void visitEvent(Event* curr) { WASM_UNREACHABLE("unimp"); } + void visitModule(Module* curr) { WASM_UNREACHABLE("unimp"); } // given a stack of nested expressions, update them all from child to parent static void updateStack(ExpressionStack& expressionStack) { diff --git a/src/literal.h b/src/literal.h index 1106d1c27..c77c21947 100644 --- a/src/literal.h +++ b/src/literal.h @@ -84,9 +84,9 @@ public: case Type::exnref: // there's no exnref literals case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } inline static Literal makeZero(Type type) { return makeFromInt32(0, type); } @@ -467,7 +467,7 @@ template<> struct less<wasm::Literal> { case wasm::Type::unreachable: return false; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } }; } // namespace std diff --git a/src/parsing.h b/src/parsing.h index 2591c4357..7017fdb0f 100644 --- a/src/parsing.h +++ b/src/parsing.h @@ -265,7 +265,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) { case v128: case anyref: // there's no anyref.const case exnref: // there's no exnref.const - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected const type"); case none: case unreachable: { return nullptr; diff --git a/src/pass.h b/src/pass.h index 46b603f00..760feb7c0 100644 --- a/src/pass.h +++ b/src/pass.h @@ -254,13 +254,15 @@ public: virtual void prepareToRun(PassRunner* runner, Module* module) {} // Implement this with code to run the pass on the whole module - virtual void run(PassRunner* runner, Module* module) { WASM_UNREACHABLE(); } + virtual void run(PassRunner* runner, Module* module) { + WASM_UNREACHABLE("unimplemented"); + } // Implement this with code to run the pass on a single function, for // a function-parallel pass virtual void runOnFunction(PassRunner* runner, Module* module, Function* function) { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimplemented"); } // Function parallelism. By default, passes are not run in parallel, but you @@ -285,7 +287,7 @@ public: // This method is used to create instances per function for a // function-parallel pass. You may need to override this if you subclass a // Walker, as otherwise this will create the parent class. - virtual Pass* create() { WASM_UNREACHABLE(); } + virtual Pass* create() { WASM_UNREACHABLE("unimplenented"); } // Whether this pass modifies the Binaryen IR in the module. This is true for // most passes, except for passes that have no side effects, or passes that diff --git a/src/passes/AlignmentLowering.cpp b/src/passes/AlignmentLowering.cpp index 05ec2892f..d659fcb69 100644 --- a/src/passes/AlignmentLowering.cpp +++ b/src/passes/AlignmentLowering.cpp @@ -103,10 +103,10 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { i32), builder.makeConst(Literal(int32_t(16))))); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid alignment"); } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } replaceCurrent( builder.makeBlock({builder.makeLocalSet(temp, curr->ptr), ret})); @@ -199,10 +199,10 @@ struct AlignmentLowering : public WalkerPass<PostWalker<AlignmentLowering>> { builder.makeConst(Literal(int32_t(16)))), i32)); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid alignment"); } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } block->finalize(); replaceCurrent(block); diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index 818d61907..d92181639 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -841,7 +841,7 @@ private: // the state, so there should be nothing that can reach here - add it // earlier as necessary. // std::cout << *curr << '\n'; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } // Possibly skip some code, if rewinding. diff --git a/src/passes/ConstHoisting.cpp b/src/passes/ConstHoisting.cpp index 08fede1df..9eb853878 100644 --- a/src/passes/ConstHoisting.cpp +++ b/src/passes/ConstHoisting.cpp @@ -97,9 +97,8 @@ private: return false; } case none: - case unreachable: { - WASM_UNREACHABLE(); - } + case unreachable: + WASM_UNREACHABLE("unexpected type"); } // compute the benefit, of replacing the uses with // one use + a set and then a get for each use diff --git a/src/passes/DataFlowOpts.cpp b/src/passes/DataFlowOpts.cpp index dc8f6ca94..d4a3cc087 100644 --- a/src/passes/DataFlowOpts.cpp +++ b/src/passes/DataFlowOpts.cpp @@ -215,7 +215,7 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected dataflow node type"); } } // No one is a user of this node after we replaced all the uses. @@ -234,9 +234,8 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> { return &binary->left; } else if (index == 1) { return &binary->right; - } else { - WASM_UNREACHABLE(); } + WASM_UNREACHABLE("unexpected index"); } else if (auto* select = expr->dynCast<Select>()) { if (index == 0) { return &select->condition; @@ -244,12 +243,10 @@ struct DataFlowOpts : public WalkerPass<PostWalker<DataFlowOpts>> { return &select->ifTrue; } else if (index == 2) { return &select->ifFalse; - } else { - WASM_UNREACHABLE(); } - } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected index"); } + WASM_UNREACHABLE("unexpected expression type"); } }; diff --git a/src/passes/DeadCodeElimination.cpp b/src/passes/DeadCodeElimination.cpp index dcbac960e..be6f92ffa 100644 --- a/src/passes/DeadCodeElimination.cpp +++ b/src/passes/DeadCodeElimination.cpp @@ -356,9 +356,9 @@ struct DeadCodeElimination case Expression::Id::BrOnExnId: DELEGATE(BrOnExn); case Expression::Id::InvalidId: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); case Expression::Id::NumExpressionIds: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } #undef DELEGATE return; diff --git a/src/passes/Flatten.cpp b/src/passes/Flatten.cpp index ee7a93b72..6f698367f 100644 --- a/src/passes/Flatten.cpp +++ b/src/passes/Flatten.cpp @@ -156,7 +156,7 @@ struct Flatten loop->finalize(); replaceCurrent(rep); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } } else { // for anything else, there may be existing preludes diff --git a/src/passes/FuncCastEmulation.cpp b/src/passes/FuncCastEmulation.cpp index f938da3b7..f36e1e909 100644 --- a/src/passes/FuncCastEmulation.cpp +++ b/src/passes/FuncCastEmulation.cpp @@ -63,16 +63,13 @@ static Expression* toABI(Expression* value, Module* module) { break; } case v128: { - assert(false && "v128 not implemented yet"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("v128 not implemented yet"); } case anyref: { - assert(false && "anyref cannot be converted to i64"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("anyref cannot be converted to i64"); } case exnref: { - assert(false && "exnref cannot be converted to i64"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("exnref cannot be converted to i64"); } case none: { // the value is none, but we need a value here @@ -109,16 +106,13 @@ static Expression* fromABI(Expression* value, Type type, Module* module) { break; } case v128: { - assert(false && "v128 not implemented yet"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("v128 not implemented yet"); } case anyref: { - assert(false && "anyref cannot be converted from i64"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("anyref cannot be converted from i64"); } case exnref: { - assert(false && "exnref cannot be converted from i64"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("exnref cannot be converted from i64"); } case none: { value = builder.makeDrop(value); diff --git a/src/passes/I64ToI32Lowering.cpp b/src/passes/I64ToI32Lowering.cpp index b51858474..e2f744957 100644 --- a/src/passes/I64ToI32Lowering.cpp +++ b/src/passes/I64ToI32Lowering.cpp @@ -130,7 +130,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { } else if (auto* get = curr->init->dynCast<GlobalGet>()) { high->init = builder->makeGlobalGet(makeHighName(get->name), i32); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } curr->init->type = i32; } @@ -752,8 +752,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { lower(result, ClzInt32, std::move(highBits), std::move(lowBits)); break; case CtzInt64: - std::cerr << "i64.ctz should be removed already" << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("i64.ctz should be removed already"); break; default: abort(); @@ -829,8 +828,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { lowerConvertIntToFloat(curr); break; case PopcntInt64: - std::cerr << "i64.popcnt should already be removed" << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("i64.popcnt should already be removed"); default: std::cerr << "Unhandled unary operator: " << curr->op << std::endl; abort(); @@ -1328,9 +1326,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> { case RemUInt64: case RotLInt64: case RotRInt64: - std::cerr << "should have been removed by now " << curr->op - << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("should have been removed by now"); case AndInt64: case OrInt64: diff --git a/src/passes/InstrumentLocals.cpp b/src/passes/InstrumentLocals.cpp index 6e12b0f3a..0b21c5000 100644 --- a/src/passes/InstrumentLocals.cpp +++ b/src/passes/InstrumentLocals.cpp @@ -92,9 +92,8 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { import = get_exnref; break; case none: - WASM_UNREACHABLE(); case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } replaceCurrent( builder.makeCall(import, @@ -137,7 +136,7 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> { case unreachable: return; // nothing to do here case none: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } curr->value = builder.makeCall(import, diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 64c49fc96..6de1d3d00 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -59,7 +59,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) { case i64: return 64 - const_->value.countLeadingZeroes().geti64(); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } else if (auto* binary = curr->dynCast<Binary>()) { switch (binary->op) { @@ -186,7 +186,7 @@ Index getMaxBits(Expression* curr, LocalInfoProvider* localInfoProvider) { case unreachable: return 64; // not interesting, but don't crash default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index e35d9b57e..a8d9383bf 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -205,7 +205,7 @@ struct PrintExpressionContents } else if (bytes == 4) { o << "32"; } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid RMW byte length"); } } o << '.'; @@ -757,7 +757,7 @@ struct PrintExpressionContents o << "i32x4.widen_high_i16x8_u"; break; case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unvalid unary operator"); } } void visitBinary(Binary* curr) { @@ -1287,7 +1287,7 @@ struct PrintExpressionContents break; case InvalidBinary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unvalid binary operator"); } restoreNormalColor(o); } @@ -1901,7 +1901,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> { o << "event"; break; case ExternalKind::Invalid: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid ExternalKind"); } o << ' '; printName(curr->value, o) << "))"; @@ -2389,7 +2389,7 @@ WasmPrinter::printStackInst(StackInst* inst, std::ostream& o, Function* func) { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpeted op"); } return o; } @@ -2446,7 +2446,7 @@ WasmPrinter::printStackIR(StackIR* ir, std::ostream& o, Function* func) { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpeted op"); } std::cout << '\n'; } diff --git a/src/passes/ReReloop.cpp b/src/passes/ReReloop.cpp index 0fbe22c71..5d4190d18 100644 --- a/src/passes/ReReloop.cpp +++ b/src/passes/ReReloop.cpp @@ -102,7 +102,7 @@ struct ReReloop final : public Pass { struct Task { ReReloop& parent; Task(ReReloop& parent) : parent(parent) {} - virtual void run() { WASM_UNREACHABLE(); } + virtual void run() { WASM_UNREACHABLE("unimpl"); } }; typedef std::shared_ptr<Task> TaskPtr; @@ -200,7 +200,7 @@ struct ReReloop final : public Pass { parent.addBranch(ifTrueEnd, after); parent.addBranch(ifFalseEnd, after); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid phase"); } } }; diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp index 3b04522ad..1cd974704 100644 --- a/src/passes/RemoveUnusedNames.cpp +++ b/src/passes/RemoveUnusedNames.cpp @@ -80,7 +80,7 @@ struct RemoveUnusedNames : public WalkerPass<PostWalker<RemoveUnusedNames>> { br->name = child->name; } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } } child->finalize(child->type); diff --git a/src/passes/Souperify.cpp b/src/passes/Souperify.cpp index c5dca51fa..fb0a9d7b9 100644 --- a/src/passes/Souperify.cpp +++ b/src/passes/Souperify.cpp @@ -308,7 +308,7 @@ struct Trace { return nullptr; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected node type"); } // Assert on no cycles assert(addedNodes.find(node) == addedNodes.end()); @@ -344,7 +344,7 @@ struct Trace { } else if (curr == iff->ifFalse) { index = 1; } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid expr"); } auto* condition = conditions[index]; // Add the condition itself as an instruction in the trace - @@ -353,7 +353,7 @@ struct Trace { // Add it as a pc, which we will emit directly. pathConditions.push_back(condition); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid expr"); } } @@ -501,11 +501,10 @@ struct Printer { break; } case Node::Type::Bad: { - std::cout << "!!!BAD!!!"; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("!!!BAD!!!"); } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpted type"); } if (node->isExpr() || node->isPhi()) { if (node->origin != trace.toInfer->origin && @@ -557,7 +556,7 @@ struct Printer { std::cout << "ctpop"; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } std::cout << ' '; auto* value = node->getValue(0); @@ -649,7 +648,7 @@ struct Printer { std::cout << "ule"; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } std::cout << ' '; auto* left = node->getValue(0); @@ -665,7 +664,7 @@ struct Printer { std::cout << ", "; printInternal(node->getValue(2)); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexecpted node type"); } } diff --git a/src/passes/SpillPointers.cpp b/src/passes/SpillPointers.cpp index 5c3d546ad..10fa58845 100644 --- a/src/passes/SpillPointers.cpp +++ b/src/passes/SpillPointers.cpp @@ -132,7 +132,7 @@ struct SpillPointers pointer, toSpill, spillLocal, pointerMap, func, getModule()); } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected action"); } } } @@ -179,7 +179,7 @@ struct SpillPointers } handleOperand(call->cast<CallIndirect>()->target); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr"); } // add the spills for (auto index : toSpill) { diff --git a/src/passes/TrapMode.cpp b/src/passes/TrapMode.cpp index df900a125..c00c34eca 100644 --- a/src/passes/TrapMode.cpp +++ b/src/passes/TrapMode.cpp @@ -183,7 +183,7 @@ Function* generateUnaryFunc(Module& wasm, Unary* curr) { makeClampLimitLiterals<uint64_t, double>(iMin, fMin, fMax); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } auto func = new Function; diff --git a/src/shell-interface.h b/src/shell-interface.h index e73ce4c48..63cbd9807 100644 --- a/src/shell-interface.h +++ b/src/shell-interface.h @@ -120,7 +120,7 @@ struct ShellExternalInterface : ModuleInstance::ExternalInterface { assert(false && "exnref not implemented yet"); case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } }); diff --git a/src/support/CMakeLists.txt b/src/support/CMakeLists.txt index 54ab8b08f..a97863107 100644 --- a/src/support/CMakeLists.txt +++ b/src/support/CMakeLists.txt @@ -8,5 +8,6 @@ set(support_SOURCES path.cpp safe_integer.cpp threads.cpp + utilities.cpp ) add_library(support OBJECT ${support_SOURCES}) diff --git a/src/support/bits.cpp b/src/support/bits.cpp index c237807ee..2489a0249 100644 --- a/src/support/bits.cpp +++ b/src/support/bits.cpp @@ -17,6 +17,7 @@ #define wasm_support_bits_definitions #include "support/bits.h" #include "../compiler-support.h" +#include "support/utilities.h" namespace wasm { @@ -91,7 +92,7 @@ template<> int CountLeadingZeroes<uint64_t>(uint64_t v) { uint32_t Log2(uint32_t v) { switch (v) { default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); case 1: return 0; case 2: diff --git a/src/support/utilities.cpp b/src/support/utilities.cpp new file mode 100644 index 000000000..ea426df9c --- /dev/null +++ b/src/support/utilities.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2019 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "utilities.h" + +#include <cassert> +#include <cstdlib> +#include <iostream> + +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +#include "sanitizer/common_interface_defs.h" +#endif + +void wasm::handle_unreachable(const char* msg, + const char* file, + unsigned line) { +#ifndef NDEBUG + if (msg) { + std::cerr << msg << "\n"; + } + std::cerr << "UNREACHABLE executed"; + if (file) { + std::cerr << " at " << file << ":" << line; + } + std::cerr << "!\n"; +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) + __sanitizer_print_stack_trace(); + __builtin_trap(); +#endif +#endif + abort(); +} diff --git a/src/support/utilities.h b/src/support/utilities.h index 71d8ce2e0..5280fcb3b 100644 --- a/src/support/utilities.h +++ b/src/support/utilities.h @@ -74,6 +74,20 @@ public: } }; +WASM_NORETURN void handle_unreachable(const char* msg = nullptr, + const char* file = nullptr, + unsigned line = 0); + +// If control flow reaches the point of the WASM_UNREACHABLE(), the program is +// undefined. +#ifndef NDEBUG +#define WASM_UNREACHABLE(msg) wasm::handle_unreachable(msg, __FILE__, __LINE__) +#elif defined(WASM_BUILTIN_UNREACHABLE) +#define WASM_UNREACHABLE(msg) WASM_BUILTIN_UNREACHABLE +#else +#define WASM_UNREACHABLE(msg) wasm::handle_unreachable() +#endif + } // namespace wasm #endif // wasm_support_utilities_h diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 733029bd7..8de47900c 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -171,7 +171,7 @@ public: options.passes.push_back("vacuum"); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected value"); } } if (oneIn(2)) { @@ -984,7 +984,7 @@ private: case 14: return makeUnreachable(unreachable); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected value"); } // make something with no chance of infinite recursion @@ -1334,7 +1334,7 @@ private: return builder.makeLoad( 4, signed_, offset, pick(1, 2, 4), ptr, type); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected value"); } case i64: { bool signed_ = get() & 1; @@ -1350,7 +1350,7 @@ private: return builder.makeLoad( 8, signed_, offset, pick(1, 2, 4, 8), ptr, type); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected value"); } case f32: { return builder.makeLoad(4, false, offset, pick(1, 2, 4), ptr, type); @@ -1369,9 +1369,9 @@ private: case exnref: // exnref cannot be loaded from memory case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Expression* makeLoad(Type type) { @@ -1437,7 +1437,7 @@ private: return builder.makeStore( 4, offset, pick(1, 2, 4), ptr, value, type); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case i64: { switch (upTo(4)) { @@ -1452,7 +1452,7 @@ private: return builder.makeStore( 8, offset, pick(1, 2, 4, 8), ptr, value, type); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case f32: { return builder.makeStore(4, offset, pick(1, 2, 4), ptr, value, type); @@ -1471,9 +1471,9 @@ private: case exnref: // exnref cannot be stored in memory case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Expression* makeStore(Type type) { @@ -1546,7 +1546,7 @@ private: return Literal( std::array<Literal, 2>{{makeLiteral(f64), makeLiteral(f64)}}); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected value"); } } @@ -1567,7 +1567,7 @@ private: case exnref: // exnref cannot have literals case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } break; } @@ -1594,7 +1594,7 @@ private: small = uint32_t(get32()); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } switch (type) { case i32: @@ -1610,7 +1610,7 @@ private: case exnref: // exnref cannot have literals case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } break; } @@ -1676,7 +1676,7 @@ private: case exnref: // exnref cannot have literals case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } // tweak around special values if (oneIn(3)) { // +- 1 @@ -1708,7 +1708,7 @@ private: case exnref: // exnref cannot have literals case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } // maybe negative if (oneIn(2)) { @@ -1717,7 +1717,7 @@ private: return value; } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalide value"); } Literal makeLiteral(Type type) { @@ -1816,9 +1816,9 @@ private: case exnref: // there's no unary ops for exnref case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } case i64: { switch (upTo(4)) { @@ -1856,7 +1856,7 @@ private: return buildUnary({op, make(f64)}); } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case f32: { switch (upTo(4)) { @@ -1881,7 +1881,7 @@ private: case 3: return makeDeNanOp(buildUnary({DemoteFloat64, make(f64)})); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case f64: { switch (upTo(4)) { @@ -1906,7 +1906,7 @@ private: case 3: return makeDeNanOp(buildUnary({PromoteFloat32, make(f32)})); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case v128: { assert(wasm.features.hasSIMD()); @@ -1950,15 +1950,15 @@ private: WidenHighUVecI16x8ToVecI32x4), make(v128)}); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case anyref: // there's no unary ops for anyref case exnref: // there's no unary ops for exnref case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Expression* buildBinary(const BinaryArgs& args) { @@ -2042,7 +2042,7 @@ private: make(f64), make(f64)}); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } case i64: { return buildBinary({pick(AddInt64, @@ -2189,9 +2189,9 @@ private: case exnref: // there's no binary ops for exnref case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Expression* buildSelect(const ThreeArgs& args) { @@ -2292,7 +2292,7 @@ private: bytes = pick(1, 2, 4); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalide value"); } break; } @@ -2311,12 +2311,12 @@ private: bytes = pick(1, 2, 4, 8); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalide value"); } break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } auto offset = logify(get()); auto* ptr = makePointer(); @@ -2362,7 +2362,7 @@ private: case 6: return makeSIMDLoad(); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } Expression* makeSIMDExtract(Type type) { @@ -2389,7 +2389,7 @@ private: case exnref: case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Expression* vec = make(v128); uint8_t index = 0; @@ -2450,7 +2450,7 @@ private: lane_t = f64; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } Expression* value = make(lane_t); return builder.makeSIMDReplace(op, vec, index, value); @@ -2551,7 +2551,7 @@ private: case 3: return makeMemoryFill(); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid value"); } Expression* makeMemoryInit() { @@ -2739,7 +2739,7 @@ private: } else if (auto* loop = target->dynCast<Loop>()) { return loop->name; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } Type getTargetType(Expression* target) { @@ -2748,7 +2748,7 @@ private: } else if (target->is<Loop>()) { return none; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } }; diff --git a/src/tools/spec-wrapper.h b/src/tools/spec-wrapper.h index 8dcb5fde4..bcdf2e113 100644 --- a/src/tools/spec-wrapper.h +++ b/src/tools/spec-wrapper.h @@ -52,7 +52,7 @@ static std::string generateSpecWrapper(Module& wasm) { case exnref: // there's no exnref.const case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } ret += " "; } diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 34451b871..b45c624a4 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -231,7 +231,8 @@ struct CtorEvalExternalInterface : EvallingModuleInstance::ExternalInterface { } else if (segment.offset->is<GlobalGet>()) { start = 0; } else { - WASM_UNREACHABLE(); // wasm spec only allows const and global.get there + // wasm spec only allows const and global.get there + WASM_UNREACHABLE("invalid expr type"); } auto end = start + segment.data.size(); if (start <= index && index < end) { diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp index 0fe15b444..3e1e464f8 100644 --- a/src/tools/wasm-reduce.cpp +++ b/src/tools/wasm-reduce.cpp @@ -581,7 +581,7 @@ struct Reducer case i32: { switch (child->type) { case i32: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); case i64: fixed = builder->makeUnary(WrapInt64, child); break; @@ -597,7 +597,7 @@ struct Reducer continue; // not implemented yet case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } break; } @@ -607,7 +607,7 @@ struct Reducer fixed = builder->makeUnary(ExtendSInt32, child); break; case i64: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); case f32: fixed = builder->makeUnary(TruncSFloat32ToInt64, child); break; @@ -620,7 +620,7 @@ struct Reducer continue; // not implemented yet case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } break; } @@ -633,7 +633,7 @@ struct Reducer fixed = builder->makeUnary(ConvertSInt64ToFloat32, child); break; case f32: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); case f64: fixed = builder->makeUnary(DemoteFloat64, child); break; @@ -643,7 +643,7 @@ struct Reducer continue; // not implemented yet case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } break; } @@ -659,14 +659,14 @@ struct Reducer fixed = builder->makeUnary(PromoteFloat32, child); break; case f64: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); case v128: case anyref: case exnref: continue; // not implemented yet case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } break; } @@ -676,7 +676,7 @@ struct Reducer continue; // not implemented yet case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } assert(fixed->type == curr->type); if (tryToReplaceCurrent(fixed)) { diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp index f9efcd245..53436c9d3 100644 --- a/src/tools/wasm-shell.cpp +++ b/src/tools/wasm-shell.cpp @@ -84,8 +84,7 @@ struct Operation { } else if (operation == GET) { return instance->getExport(name); } else { - Fatal() << "unknown operation: " << operation << '\n'; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unknown operation"); } } }; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index ec95470ad..34919cc79 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -919,7 +919,7 @@ inline S32LEB binaryType(Type type) { ret = BinaryConsts::EncodedType::exnref; break; case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } return S32LEB(ret); } diff --git a/src/wasm-features.h b/src/wasm-features.h index c9496bb42..ba3cb7856 100644 --- a/src/wasm-features.h +++ b/src/wasm-features.h @@ -21,6 +21,7 @@ #include <string> #include "compiler-support.h" +#include "support/utilities.h" struct FeatureSet { enum Feature : uint32_t { @@ -58,7 +59,7 @@ struct FeatureSet { case ReferenceTypes: return "reference-types"; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected feature"); } } diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index e17b4e939..1a90fdf71 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -465,9 +465,9 @@ public: case WidenHighUVecI16x8ToVecI32x4: return value.widenHighUToVecI32x4(); case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid unary op"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitBinary(Binary* curr) { NOTE_ENTER("Binary"); @@ -846,9 +846,9 @@ public: return left.swizzleVec8x16(right); case InvalidBinary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid binary op"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitSIMDExtract(SIMDExtract* curr) { NOTE_ENTER("SIMDExtract"); @@ -875,7 +875,7 @@ public: case ExtractLaneVecF64x2: return vec.extractLaneF64x2(curr->index); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitSIMDReplace(SIMDReplace* curr) { NOTE_ENTER("SIMDReplace"); @@ -903,7 +903,7 @@ public: case ReplaceLaneVecF64x2: return vec.replaceLaneF64x2(value, curr->index); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitSIMDShuffle(SIMDShuffle* curr) { NOTE_ENTER("SIMDShuffle"); @@ -941,7 +941,7 @@ public: return c.bitselectV128(a, b); default: // TODO: implement qfma/qfms - WASM_UNREACHABLE(); + WASM_UNREACHABLE("not implemented"); } } Flow visitSIMDShift(SIMDShift* curr) { @@ -982,7 +982,7 @@ public: case ShrUVecI64x2: return vec.shrUI64x2(shift); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitSelect(Select* curr) { NOTE_ENTER("Select"); @@ -1029,7 +1029,7 @@ public: Flow visitUnreachable(Unreachable* curr) { NOTE_ENTER("Unreachable"); trap("unreachable"); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unreachable"); } Literal truncSFloat(Unary* curr, Literal value) { @@ -1098,33 +1098,33 @@ public: return Flow(); } - Flow visitCall(Call*) { WASM_UNREACHABLE(); } - Flow visitCallIndirect(CallIndirect*) { WASM_UNREACHABLE(); } - Flow visitLocalGet(LocalGet*) { WASM_UNREACHABLE(); } - Flow visitLocalSet(LocalSet*) { WASM_UNREACHABLE(); } - Flow visitGlobalSet(GlobalSet*) { WASM_UNREACHABLE(); } - Flow visitLoad(Load* curr) { WASM_UNREACHABLE(); } - Flow visitStore(Store* curr) { WASM_UNREACHABLE(); } - Flow visitHost(Host* curr) { WASM_UNREACHABLE(); } - Flow visitMemoryInit(MemoryInit* curr) { WASM_UNREACHABLE(); } - Flow visitDataDrop(DataDrop* curr) { WASM_UNREACHABLE(); } - Flow visitMemoryCopy(MemoryCopy* curr) { WASM_UNREACHABLE(); } - Flow visitMemoryFill(MemoryFill* curr) { WASM_UNREACHABLE(); } - Flow visitAtomicRMW(AtomicRMW*) { WASM_UNREACHABLE(); } - Flow visitAtomicCmpxchg(AtomicCmpxchg*) { WASM_UNREACHABLE(); } - Flow visitAtomicWait(AtomicWait*) { WASM_UNREACHABLE(); } - Flow visitAtomicNotify(AtomicNotify*) { WASM_UNREACHABLE(); } - Flow visitSIMDLoad(SIMDLoad*) { WASM_UNREACHABLE(); } - Flow visitSIMDLoadSplat(SIMDLoad*) { WASM_UNREACHABLE(); } - Flow visitSIMDLoadExtend(SIMDLoad*) { WASM_UNREACHABLE(); } - Flow visitPush(Push*) { WASM_UNREACHABLE(); } - Flow visitPop(Pop*) { WASM_UNREACHABLE(); } - Flow visitTry(Try*) { WASM_UNREACHABLE(); } - Flow visitThrow(Throw*) { WASM_UNREACHABLE(); } - Flow visitRethrow(Rethrow*) { WASM_UNREACHABLE(); } - Flow visitBrOnExn(BrOnExn*) { WASM_UNREACHABLE(); } - - virtual void trap(const char* why) { WASM_UNREACHABLE(); } + Flow visitCall(Call*) { WASM_UNREACHABLE("unimp"); } + Flow visitCallIndirect(CallIndirect*) { WASM_UNREACHABLE("unimp"); } + Flow visitLocalGet(LocalGet*) { WASM_UNREACHABLE("unimp"); } + Flow visitLocalSet(LocalSet*) { WASM_UNREACHABLE("unimp"); } + Flow visitGlobalSet(GlobalSet*) { WASM_UNREACHABLE("unimp"); } + Flow visitLoad(Load* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitStore(Store* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitHost(Host* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitMemoryInit(MemoryInit* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitDataDrop(DataDrop* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitMemoryCopy(MemoryCopy* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitMemoryFill(MemoryFill* curr) { WASM_UNREACHABLE("unimp"); } + Flow visitAtomicRMW(AtomicRMW*) { WASM_UNREACHABLE("unimp"); } + Flow visitAtomicCmpxchg(AtomicCmpxchg*) { WASM_UNREACHABLE("unimp"); } + Flow visitAtomicWait(AtomicWait*) { WASM_UNREACHABLE("unimp"); } + Flow visitAtomicNotify(AtomicNotify*) { WASM_UNREACHABLE("unimp"); } + Flow visitSIMDLoad(SIMDLoad*) { WASM_UNREACHABLE("unimp"); } + Flow visitSIMDLoadSplat(SIMDLoad*) { WASM_UNREACHABLE("unimp"); } + Flow visitSIMDLoadExtend(SIMDLoad*) { WASM_UNREACHABLE("unimp"); } + Flow visitPush(Push*) { WASM_UNREACHABLE("unimp"); } + Flow visitPop(Pop*) { WASM_UNREACHABLE("unimp"); } + Flow visitTry(Try*) { WASM_UNREACHABLE("unimp"); } + Flow visitThrow(Throw*) { WASM_UNREACHABLE("unimp"); } + Flow visitRethrow(Rethrow*) { WASM_UNREACHABLE("unimp"); } + Flow visitBrOnExn(BrOnExn*) { WASM_UNREACHABLE("unimp"); } + + virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); } }; // Execute an constant expression in a global init or memory offset. @@ -1185,7 +1185,7 @@ public: case 4: return Literal((int32_t)load32s(addr)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } break; } @@ -1203,7 +1203,7 @@ public: case 8: return Literal((int64_t)load64s(addr)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } break; } @@ -1217,9 +1217,9 @@ public: case exnref: // exnref cannot be loaded from memory case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } virtual void store(Store* store, Address addr, Literal value) { switch (store->valueType) { @@ -1235,7 +1235,7 @@ public: store32(addr, value.geti32()); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid store size"); } break; } @@ -1254,7 +1254,7 @@ public: store64(addr, value.geti64()); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid store size"); } break; } @@ -1272,31 +1272,41 @@ public: case exnref: // exnref cannot be stored in memory case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } - virtual int8_t load8s(Address addr) { WASM_UNREACHABLE(); } - virtual uint8_t load8u(Address addr) { WASM_UNREACHABLE(); } - virtual int16_t load16s(Address addr) { WASM_UNREACHABLE(); } - virtual uint16_t load16u(Address addr) { WASM_UNREACHABLE(); } - virtual int32_t load32s(Address addr) { WASM_UNREACHABLE(); } - virtual uint32_t load32u(Address addr) { WASM_UNREACHABLE(); } - virtual int64_t load64s(Address addr) { WASM_UNREACHABLE(); } - virtual uint64_t load64u(Address addr) { WASM_UNREACHABLE(); } + virtual int8_t load8s(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual uint8_t load8u(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual int16_t load16s(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual uint16_t load16u(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual int32_t load32s(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual uint32_t load32u(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual int64_t load64s(Address addr) { WASM_UNREACHABLE("unimp"); } + virtual uint64_t load64u(Address addr) { WASM_UNREACHABLE("unimp"); } virtual std::array<uint8_t, 16> load128(Address addr) { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } - virtual void store8(Address addr, int8_t value) { WASM_UNREACHABLE(); } - virtual void store16(Address addr, int16_t value) { WASM_UNREACHABLE(); } - virtual void store32(Address addr, int32_t value) { WASM_UNREACHABLE(); } - virtual void store64(Address addr, int64_t value) { WASM_UNREACHABLE(); } + virtual void store8(Address addr, int8_t value) { + WASM_UNREACHABLE("unimp"); + } + virtual void store16(Address addr, int16_t value) { + WASM_UNREACHABLE("unimp"); + } + virtual void store32(Address addr, int32_t value) { + WASM_UNREACHABLE("unimp"); + } + virtual void store64(Address addr, int64_t value) { + WASM_UNREACHABLE("unimp"); + } virtual void store128(Address addr, const std::array<uint8_t, 16>&) { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } - virtual void tableStore(Address addr, Name entry) { WASM_UNREACHABLE(); } + virtual void tableStore(Address addr, Name entry) { + WASM_UNREACHABLE("unimp"); + } }; SubType* self() { return static_cast<SubType*>(this); } @@ -1443,7 +1453,7 @@ private: std::cerr << "Function `" << function->name << "` expects " << function->params.size() << " parameters, got " << arguments.size() << " arguments." << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid param count"); } locals.resize(function->getNumLocals()); for (size_t i = 0; i < function->getNumLocals(); i++) { @@ -1453,7 +1463,7 @@ private: std::cerr << "Function `" << function->name << "` expects type " << function->params[i] << " for parameter " << i << ", got " << arguments[i].type << "." << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid param count"); } locals[i] = arguments[i]; } else { @@ -1746,7 +1756,7 @@ private: case LoadExtUVec32x2ToVecI64x2: return visitSIMDLoadExtend(curr); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitSIMDLoadSplat(SIMDLoad* curr) { Load load; @@ -1773,7 +1783,7 @@ private: splat = &Literal::splatI64x2; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } load.finalize(); Flow flow = this->visit(&load); @@ -1804,9 +1814,9 @@ private: case LoadExtUVec32x2ToVecI64x2: return Literal(int64_t(instance.externalInterface->load32u(addr))); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); }; auto fillLanes = [&](auto lanes, size_t laneBytes) { for (auto& lane : lanes) { @@ -1833,9 +1843,9 @@ private: return fillLanes(lanes, 4); } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitHost(Host* curr) { NOTE_ENTER("Host"); @@ -1867,7 +1877,7 @@ private: return Literal(int32_t(ret)); } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid op"); } Flow visitMemoryInit(MemoryInit* curr) { NOTE_ENTER("MemoryInit"); @@ -2046,7 +2056,7 @@ public: if (function->result != ret.type) { std::cerr << "calling " << function->name << " resulted in " << ret << " but the function type is " << function->result << '\n'; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpect result type"); } // may decrease more than one, if we jumped up the stack callDepth = previousCallDepth; diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 16fe87af1..85b7ca415 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -186,7 +186,7 @@ template<typename SubType, typename ReturnType = void> struct Visitor { DELEGATE(Pop); case Expression::Id::InvalidId: default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } #undef DELEGATE @@ -204,7 +204,7 @@ struct OverriddenVisitor { &SubType::visit##CLASS_TO_VISIT != \ &OverriddenVisitor<SubType, ReturnType>::visit##CLASS_TO_VISIT, \ "Derived class must implement visit" #CLASS_TO_VISIT); \ - WASM_UNREACHABLE(); \ + WASM_UNREACHABLE("Derived class must implement visit" #CLASS_TO_VISIT); \ } UNIMPLEMENTED(Block); @@ -357,7 +357,7 @@ struct OverriddenVisitor { DELEGATE(Pop); case Expression::Id::InvalidId: default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } #undef DELEGATE @@ -1083,7 +1083,7 @@ struct PostWalker : public Walker<SubType, VisitorType> { break; } case Expression::Id::NumExpressionIds: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } } }; @@ -1185,7 +1185,7 @@ struct ExpressionStackWalker : public PostWalker<SubType, VisitorType> { return curr; } } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expression type"); } if (i == 0) { return nullptr; diff --git a/src/wasm/literal.cpp b/src/wasm/literal.cpp index 3b2930c67..4183d8a23 100644 --- a/src/wasm/literal.cpp +++ b/src/wasm/literal.cpp @@ -141,7 +141,7 @@ void Literal::getBits(uint8_t (&buf)[16]) const { case Type::exnref: // exnref type is opaque case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } @@ -276,7 +276,7 @@ std::ostream& operator<<(std::ostream& o, Literal literal) { case Type::anyref: // anyref type is opaque case Type::exnref: // exnref type is opaque case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } restoreNormalColor(o); return o; @@ -289,7 +289,7 @@ Literal Literal::countLeadingZeroes() const { if (type == Type::i64) { return Literal((int64_t)CountLeadingZeroes(i64)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::countTrailingZeroes() const { @@ -299,7 +299,7 @@ Literal Literal::countTrailingZeroes() const { if (type == Type::i64) { return Literal((int64_t)CountTrailingZeroes(i64)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::popCount() const { @@ -309,7 +309,7 @@ Literal Literal::popCount() const { if (type == Type::i64) { return Literal((int64_t)PopCount(i64)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::extendToSI64() const { @@ -334,7 +334,7 @@ Literal Literal::extendS8() const { if (type == Type::i64) { return Literal(int64_t(int8_t(geti64() & 0xFF))); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::extendS16() const { @@ -344,14 +344,14 @@ Literal Literal::extendS16() const { if (type == Type::i64) { return Literal(int64_t(int16_t(geti64() & 0xFFFF))); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::extendS32() const { if (type == Type::i64) { return Literal(int64_t(int32_t(geti64() & 0xFFFFFFFF))); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::wrapToI32() const { @@ -366,7 +366,7 @@ Literal Literal::convertSIToF32() const { if (type == Type::i64) { return Literal(float(i64)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::convertUIToF32() const { @@ -376,7 +376,7 @@ Literal Literal::convertUIToF32() const { if (type == Type::i64) { return Literal(float(uint64_t(i64))); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::convertSIToF64() const { @@ -386,7 +386,7 @@ Literal Literal::convertSIToF64() const { if (type == Type::i64) { return Literal(double(i64)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::convertUIToF64() const { @@ -396,7 +396,7 @@ Literal Literal::convertUIToF64() const { if (type == Type::i64) { return Literal(double(uint64_t(i64))); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } template<typename F> struct AsInt { using type = void; }; @@ -427,7 +427,7 @@ Literal Literal::truncSatToSI32() const { return saturating_trunc<double, int32_t, isInRangeI32TruncS>( Literal(*this).castToI64().geti64()); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::truncSatToSI64() const { @@ -439,7 +439,7 @@ Literal Literal::truncSatToSI64() const { return saturating_trunc<double, int64_t, isInRangeI64TruncS>( Literal(*this).castToI64().geti64()); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::truncSatToUI32() const { @@ -451,7 +451,7 @@ Literal Literal::truncSatToUI32() const { return saturating_trunc<double, uint32_t, isInRangeI32TruncU>( Literal(*this).castToI64().geti64()); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::truncSatToUI64() const { @@ -463,7 +463,7 @@ Literal Literal::truncSatToUI64() const { return saturating_trunc<double, uint64_t, isInRangeI64TruncU>( Literal(*this).castToI64().geti64()); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::eqz() const { @@ -481,9 +481,9 @@ Literal Literal::eqz() const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::neg() const { @@ -501,9 +501,9 @@ Literal Literal::neg() const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } Literal Literal::abs() const { @@ -521,9 +521,9 @@ Literal Literal::abs() const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Literal Literal::ceil() const { @@ -533,7 +533,7 @@ Literal Literal::ceil() const { case Type::f64: return Literal(std::ceil(getf64())); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -544,7 +544,7 @@ Literal Literal::floor() const { case Type::f64: return Literal(std::floor(getf64())); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -555,7 +555,7 @@ Literal Literal::trunc() const { case Type::f64: return Literal(std::trunc(getf64())); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -566,7 +566,7 @@ Literal Literal::nearbyint() const { case Type::f64: return Literal(std::nearbyint(getf64())); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -577,7 +577,7 @@ Literal Literal::sqrt() const { case Type::f64: return Literal(std::sqrt(getf64())); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -624,9 +624,9 @@ Literal Literal::add(const Literal& other) const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Literal Literal::sub(const Literal& other) const { @@ -644,9 +644,9 @@ Literal Literal::sub(const Literal& other) const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } template<typename T> static T add_sat_s(T a, T b) { @@ -735,9 +735,9 @@ Literal Literal::mul(const Literal& other) const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Literal Literal::div(const Literal& other) const { @@ -759,7 +759,7 @@ Literal Literal::div(const Literal& other) const { return Literal( std::copysign(std::numeric_limits<float>::infinity(), sign)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid fp classification"); } case FP_NAN: // fallthrough case FP_INFINITE: // fallthrough @@ -767,7 +767,7 @@ Literal Literal::div(const Literal& other) const { case FP_SUBNORMAL: return Literal(lhs / rhs); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid fp classification"); } } case Type::f64: { @@ -787,7 +787,7 @@ Literal Literal::div(const Literal& other) const { return Literal( std::copysign(std::numeric_limits<double>::infinity(), sign)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid fp classification"); } case FP_NAN: // fallthrough case FP_INFINITE: // fallthrough @@ -795,11 +795,11 @@ Literal Literal::div(const Literal& other) const { case FP_SUBNORMAL: return Literal(lhs / rhs); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid fp classification"); } } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -810,7 +810,7 @@ Literal Literal::divS(const Literal& other) const { case Type::i64: return Literal(i64 / other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -821,7 +821,7 @@ Literal Literal::divU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) / uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -832,7 +832,7 @@ Literal Literal::remS(const Literal& other) const { case Type::i64: return Literal(i64 % other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -843,7 +843,7 @@ Literal Literal::remU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) % uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -867,7 +867,7 @@ Literal Literal::and_(const Literal& other) const { case Type::i64: return Literal(i64 & other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -878,7 +878,7 @@ Literal Literal::or_(const Literal& other) const { case Type::i64: return Literal(i64 | other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -889,7 +889,7 @@ Literal Literal::xor_(const Literal& other) const { case Type::i64: return Literal(i64 ^ other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -902,7 +902,7 @@ Literal Literal::shl(const Literal& other) const { return Literal(uint64_t(i64) << Bits::getEffectiveShifts(other.i64, Type::i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -913,7 +913,7 @@ Literal Literal::shrS(const Literal& other) const { case Type::i64: return Literal(i64 >> Bits::getEffectiveShifts(other.i64, Type::i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -926,7 +926,7 @@ Literal Literal::shrU(const Literal& other) const { return Literal(uint64_t(i64) >> Bits::getEffectiveShifts(other.i64, Type::i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -937,7 +937,7 @@ Literal Literal::rotL(const Literal& other) const { case Type::i64: return Literal(RotateLeft(uint64_t(i64), uint64_t(other.i64))); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -948,7 +948,7 @@ Literal Literal::rotR(const Literal& other) const { case Type::i64: return Literal(RotateRight(uint64_t(i64), uint64_t(other.i64))); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -967,9 +967,9 @@ Literal Literal::eq(const Literal& other) const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Literal Literal::ne(const Literal& other) const { @@ -987,9 +987,9 @@ Literal Literal::ne(const Literal& other) const { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } Literal Literal::ltS(const Literal& other) const { @@ -999,7 +999,7 @@ Literal Literal::ltS(const Literal& other) const { case Type::i64: return Literal(i64 < other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1010,7 +1010,7 @@ Literal Literal::ltU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) < uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1021,7 +1021,7 @@ Literal Literal::lt(const Literal& other) const { case Type::f64: return Literal(getf64() < other.getf64()); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1032,7 +1032,7 @@ Literal Literal::leS(const Literal& other) const { case Type::i64: return Literal(i64 <= other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1043,7 +1043,7 @@ Literal Literal::leU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) <= uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1054,7 +1054,7 @@ Literal Literal::le(const Literal& other) const { case Type::f64: return Literal(getf64() <= other.getf64()); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1065,7 +1065,7 @@ Literal Literal::gtS(const Literal& other) const { case Type::i64: return Literal(i64 > other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1076,7 +1076,7 @@ Literal Literal::gtU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) > uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1087,7 +1087,7 @@ Literal Literal::gt(const Literal& other) const { case Type::f64: return Literal(getf64() > other.getf64()); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1098,7 +1098,7 @@ Literal Literal::geS(const Literal& other) const { case Type::i64: return Literal(i64 >= other.i64); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1109,7 +1109,7 @@ Literal Literal::geU(const Literal& other) const { case Type::i64: return Literal(uint64_t(i64) >= uint64_t(other.i64)); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1120,7 +1120,7 @@ Literal Literal::ge(const Literal& other) const { case Type::f64: return Literal(getf64() >= other.getf64()); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1163,7 +1163,7 @@ Literal Literal::min(const Literal& other) const { .castToF64(); } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1206,7 +1206,7 @@ Literal Literal::max(const Literal& other) const { .castToF64(); } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -1222,7 +1222,7 @@ Literal Literal::copysign(const Literal& other) const { .castToF64(); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index bb8b96aa4..b8b001927 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -398,7 +398,7 @@ void WasmBinaryWriter::writeExports() { o << U32LEB(getEventIndex(curr->value)); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected extern kind"); } } finishSection(start); @@ -669,7 +669,7 @@ void WasmBinaryWriter::writeFeaturesSection() { case FeatureSet::ReferenceTypes: return BinaryConsts::UserSections::ReferenceTypesFeature; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected feature flag"); } }; @@ -1023,9 +1023,10 @@ Type WasmBinaryBuilder::getType() { return anyref; case BinaryConsts::EncodedType::exnref: return exnref; - default: { throwError("invalid wasm type: " + std::to_string(type)); } + default: + throwError("invalid wasm type: " + std::to_string(type)); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpeced type"); } Type WasmBinaryBuilder::getConcreteType() { @@ -2848,7 +2849,7 @@ bool WasmBinaryBuilder::maybeVisitAtomicRMW(Expression*& out, uint8_t code) { SET_FOR_OP(Xor); SET_FOR_OP(Xchg); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected opcode"); } #undef SET_FOR_OP #undef SET @@ -2902,7 +2903,7 @@ bool WasmBinaryBuilder::maybeVisitAtomicCmpxchg(Expression*& out, SET(i64, 4); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected opcode"); } BYN_TRACE("zz node: AtomicCmpxchg\n"); @@ -2934,7 +2935,7 @@ bool WasmBinaryBuilder::maybeVisitAtomicWait(Expression*& out, uint8_t code) { curr->expectedType = i64; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected opcode"); } curr->type = i32; BYN_TRACE("zz node: AtomicWait\n"); diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 3f64bafe8..dae125096 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -678,7 +678,7 @@ std::string proxyingSuffix(Proxying proxy) { case Proxying::Async: return "async_on_main_thread_"; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid prozy type"); } struct AsmConstWalker : public LinearExecutionWalker<AsmConstWalker> { diff --git a/src/wasm/wasm-stack.cpp b/src/wasm/wasm-stack.cpp index f1aaff93e..0f12a2f2b 100644 --- a/src/wasm/wasm-stack.cpp +++ b/src/wasm/wasm-stack.cpp @@ -152,7 +152,7 @@ void BinaryInstWriter::visitLoad(Load* curr) { case anyref: // anyref cannot be loaded from memory case exnref: // exnref cannot be loaded from memory case none: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } else { o << int8_t(BinaryConsts::AtomicPrefix); @@ -169,7 +169,7 @@ void BinaryInstWriter::visitLoad(Load* curr) { o << int8_t(BinaryConsts::I32AtomicLoad); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid load size"); } break; } @@ -188,14 +188,14 @@ void BinaryInstWriter::visitLoad(Load* curr) { o << int8_t(BinaryConsts::I64AtomicLoad); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid load size"); } break; } case unreachable: return; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } emitMemoryAccess(curr->align, curr->bytes, curr->offset); @@ -253,7 +253,7 @@ void BinaryInstWriter::visitStore(Store* curr) { case exnref: // exnref cannot be stored in memory case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } else { o << int8_t(BinaryConsts::AtomicPrefix); @@ -270,7 +270,7 @@ void BinaryInstWriter::visitStore(Store* curr) { o << int8_t(BinaryConsts::I32AtomicStore); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid store size"); } break; } @@ -289,12 +289,12 @@ void BinaryInstWriter::visitStore(Store* curr) { o << int8_t(BinaryConsts::I64AtomicStore); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid store size"); } break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } emitMemoryAccess(curr->align, curr->bytes, curr->offset); @@ -318,7 +318,7 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) { o << int8_t(BinaryConsts::I32AtomicRMW##Op); \ break; \ default: \ - WASM_UNREACHABLE(); \ + WASM_UNREACHABLE("invalid rmw size"); \ } \ break; \ case i64: \ @@ -336,11 +336,11 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) { o << int8_t(BinaryConsts::I64AtomicRMW##Op); \ break; \ default: \ - WASM_UNREACHABLE(); \ + WASM_UNREACHABLE("invalid rmw size"); \ } \ break; \ default: \ - WASM_UNREACHABLE(); \ + WASM_UNREACHABLE("unexpected type"); \ } \ break @@ -352,7 +352,7 @@ void BinaryInstWriter::visitAtomicRMW(AtomicRMW* curr) { CASE_FOR_OP(Xor); CASE_FOR_OP(Xchg); default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } #undef CASE_FOR_OP @@ -374,7 +374,7 @@ void BinaryInstWriter::visitAtomicCmpxchg(AtomicCmpxchg* curr) { o << int8_t(BinaryConsts::I32AtomicCmpxchg); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } break; case i64: @@ -392,11 +392,11 @@ void BinaryInstWriter::visitAtomicCmpxchg(AtomicCmpxchg* curr) { o << int8_t(BinaryConsts::I64AtomicCmpxchg); break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } emitMemoryAccess(curr->bytes, curr->bytes, curr->offset); } @@ -415,7 +415,7 @@ void BinaryInstWriter::visitAtomicWait(AtomicWait* curr) { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -648,7 +648,7 @@ void BinaryInstWriter::visitConst(Const* curr) { case exnref: // there's no exnref.const case none: case unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } } @@ -990,7 +990,7 @@ void BinaryInstWriter::visitUnary(Unary* curr) { << U32LEB(BinaryConsts::I32x4WidenHighUI16x8); break; case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid unary op"); } } @@ -1532,7 +1532,7 @@ void BinaryInstWriter::visitBinary(Binary* curr) { break; case InvalidBinary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid binary op"); } } @@ -1664,7 +1664,7 @@ void BinaryInstWriter::mapLocalsAndEmitHeader() { mappedLocals[i] = index + currLocalsByType[exnref] - 1; continue; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); } // Emit them. o << U32LEB((numLocalsByType[i32] ? 1 : 0) + (numLocalsByType[i64] ? 1 : 0) + @@ -1708,7 +1708,7 @@ int32_t BinaryInstWriter::getBreakIndex(Name name) { // -1 if not found return breakStack.size() - 1 - i; } } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("break index not found"); } void StackIRGenerator::emit(Expression* curr) { @@ -1738,7 +1738,7 @@ void StackIRGenerator::emitScopeEnd(Expression* curr) { } else if (curr->is<Try>()) { stackInst = makeStackInst(StackInst::TryEnd, curr); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } stackIR.push_back(stackInst); } @@ -1796,7 +1796,7 @@ void StackIRToBinaryWriter::write() { break; } default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } } writer.emitFunctionEnd(); diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index 50ddc82f8..d5a3668fb 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -248,9 +248,9 @@ unsigned getTypeSize(Type type) { case Type::exnref: // exnref type is opaque case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } FeatureSet getFeatures(Type type) { @@ -279,7 +279,7 @@ Type getType(unsigned size, bool float_) { if (size == 16) { return Type::v128; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid size"); } Type reinterpretType(Type type) { @@ -297,9 +297,9 @@ Type reinterpretType(Type type) { case Type::exnref: case Type::none: case Type::unreachable: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } // namespace wasm diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index d3f03b76c..75121d4f4 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -1183,7 +1183,7 @@ void FunctionValidator::validateMemBytes(uint8_t bytes, case anyref: // anyref cannot be stored in memory case exnref: // exnref cannot be stored in memory case none: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected type"); case unreachable: break; } @@ -1387,7 +1387,7 @@ void FunctionValidator::visitBinary(Binary* curr) { break; } case InvalidBinary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invliad binary op"); } shouldBeTrue(Features::get(curr->op) <= getModule()->features, curr, @@ -1601,7 +1601,7 @@ void FunctionValidator::visitUnary(Unary* curr) { shouldBeEqual(curr->value->type, v128, curr, "expected v128 operand"); break; case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid unary op"); } shouldBeTrue(Features::get(curr->op) <= getModule()->features, curr, @@ -1866,7 +1866,7 @@ void FunctionValidator::validateAlignment( case anyref: // anyref cannot be stored in memory case exnref: // exnref cannot be stored in memory case none: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid type"); } } @@ -1995,7 +1995,7 @@ static void validateExports(Module& module, ValidationInfo& info) { name, "module event exports must be found"); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid ExternalKind"); } Name exportName = exp->name; info.shouldBeFalse(exportNames.count(exportName) > 0, diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index f0c853172..5a722e600 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -94,7 +94,7 @@ Name ATTR("attr"); const char* getExpressionName(Expression* curr) { switch (curr->_id) { case Expression::Id::InvalidId: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid expr id"); case Expression::Id::BlockId: return "block"; case Expression::Id::IfId: @@ -182,9 +182,9 @@ const char* getExpressionName(Expression* curr) { case Expression::BrOnExnId: return "br_on_exn"; case Expression::Id::NumExpressionIds: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid expr id"); } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid expr id"); } // core AST type checking @@ -559,7 +559,7 @@ void SIMDExtract::finalize() { type = f64; break; default: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } if (vec->type == unreachable) { type = unreachable; @@ -653,7 +653,7 @@ Index SIMDLoad::getMemBytes() { case LoadExtUVec32x2ToVecI64x2: return 8; } - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected op"); } Const* Const::set(Literal value_) { @@ -801,7 +801,7 @@ void Unary::finalize() { break; case InvalidUnary: - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid unary op"); } } @@ -981,7 +981,7 @@ Type Function::getLocalType(Index index) { } else if (isVar(index)) { return vars[index - getVarIndexBase()]; } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("invalid local index"); } } diff --git a/src/wasm2js.h b/src/wasm2js.h index 5e6e1d8ea..906a4b9dc 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -563,7 +563,7 @@ void Wasm2JSBuilder::addTable(Ref ast, Module* wasm) { PLUS, ValueBuilder::makeNum(i)); } else { - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unexpected expr type"); } ast->push_back(ValueBuilder::makeStatement(ValueBuilder::makeBinary( ValueBuilder::makeSub(ValueBuilder::makeName(FUNCTION_TABLE), index), @@ -1395,9 +1395,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, } case CtzInt32: case PopcntInt32: { - std::cerr << "i32 unary should have been removed: " << curr - << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE("i32 unary should have been removed"); } case EqZInt32: { // XXX !x does change the type to bool, which is correct, but may @@ -1524,15 +1522,11 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, case NearestFloat64: case TruncFloat32: case TruncFloat64: - std::cerr - << "operation should have been removed in previous passes" - << std::endl; - WASM_UNREACHABLE(); + WASM_UNREACHABLE( + "operation should have been removed in previous passes"); default: - std::cerr << "Unhandled unary float operator: " << curr - << std::endl; - abort(); + WASM_UNREACHABLE("unhandled unary float operator"); } if (curr->type == f32) { // doubles need much less coercing return makeAsmCoercion(ret, ASM_FLOAT); @@ -1668,13 +1662,9 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, return ValueBuilder::makeBinary(left, LT, right); case RotLInt32: case RotRInt32: - std::cerr << "should be removed already" << std::endl; - WASM_UNREACHABLE(); - default: { - std::cerr << "Unhandled i32 binary operator: " << curr - << std::endl; - abort(); - } + WASM_UNREACHABLE("should be removed already"); + default: + WASM_UNREACHABLE("unhandled i32 binary operator"); } break; } @@ -1790,7 +1780,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, } else if (curr->op == HostOp::MemorySize) { return ValueBuilder::makeCall(WASM_MEMORY_SIZE); } - WASM_UNREACHABLE(); // TODO + WASM_UNREACHABLE("unexpected expr type"); // TODO } Ref visitNop(Nop* curr) { return ValueBuilder::makeToplevel(); } @@ -1803,19 +1793,19 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Ref visitAtomicRMW(AtomicRMW* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitAtomicCmpxchg(AtomicCmpxchg* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitAtomicWait(AtomicWait* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitAtomicNotify(AtomicNotify* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitAtomicFence(AtomicFence* curr) { // Sequentially consistent fences can be lowered to no operation @@ -1823,67 +1813,67 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, } Ref visitSIMDExtract(SIMDExtract* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitSIMDReplace(SIMDReplace* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitSIMDShuffle(SIMDShuffle* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitSIMDTernary(SIMDTernary* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitSIMDShift(SIMDShift* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitSIMDLoad(SIMDLoad* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitMemoryInit(MemoryInit* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitDataDrop(DataDrop* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitMemoryCopy(MemoryCopy* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitMemoryFill(MemoryFill* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitTry(Try* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitThrow(Throw* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitRethrow(Rethrow* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitBrOnExn(BrOnExn* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitPush(Push* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } Ref visitPop(Pop* curr) { unimplemented(curr); - WASM_UNREACHABLE(); + WASM_UNREACHABLE("unimp"); } private: |