Skip to content

Commit a28343a

Browse files
authored
Add string parameter to WASM_UNREACHABLE (#2499)
This works more like llvm's unreachable handler in that is preserves information even in release builds.
1 parent cbf121d commit a28343a

56 files changed

Lines changed: 450 additions & 420 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/abi/stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) {
9393
builder.makeLocalGet(local, PointerType),
9494
builder.makeConst(Literal(int32_t(size))));
9595
} else {
96-
WASM_UNREACHABLE();
96+
WASM_UNREACHABLE("unhandled PointerType");
9797
}
9898
block->list.push_back(builder.makeGlobalSet(stackPointer->name, added));
9999
auto makeStackRestore = [&]() {

src/asm2wasm.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
15481548
break;
15491549
}
15501550
default:
1551-
WASM_UNREACHABLE();
1551+
WASM_UNREACHABLE("unexpected type");
15521552
}
15531553
} else {
15541554
assert(old == none);
@@ -2060,7 +2060,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
20602060
ret->op = NegFloat32;
20612061
ret->type = Type::f32;
20622062
} else {
2063-
WASM_UNREACHABLE();
2063+
WASM_UNREACHABLE("unexpected asm type");
20642064
}
20652065
return ret;
20662066
} else if (ast[1] == B_NOT) {
@@ -2195,7 +2195,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
21952195
ret->type = value->type;
21962196
return ret;
21972197
} else {
2198-
WASM_UNREACHABLE();
2198+
WASM_UNREACHABLE("unexpected type");
21992199
}
22002200
}
22012201
if (name == Math_floor || name == Math_sqrt || name == Math_ceil) {
@@ -2328,7 +2328,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
23282328
process(ast[2][2]),
23292329
asmToWasmType(view.type));
23302330
}
2331-
WASM_UNREACHABLE();
2331+
WASM_UNREACHABLE("unexpected atomic op");
23322332
}
23332333
bool tableCall = false;
23342334
if (wasmOnly) {

src/asmjs/asm_v_wasm.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Type asmToWasmType(AsmType asmType) {
3838
case ASM_INT32X4:
3939
return Type::v128;
4040
}
41-
WASM_UNREACHABLE();
41+
WASM_UNREACHABLE("invalid type");
4242
}
4343

4444
AsmType wasmToAsmType(Type type) {
@@ -60,9 +60,9 @@ AsmType wasmToAsmType(Type type) {
6060
case none:
6161
return ASM_NONE;
6262
case unreachable:
63-
WASM_UNREACHABLE();
63+
WASM_UNREACHABLE("invalid type");
6464
}
65-
WASM_UNREACHABLE();
65+
WASM_UNREACHABLE("invalid type");
6666
}
6767

6868
char getSig(Type type) {
@@ -84,9 +84,9 @@ char getSig(Type type) {
8484
case none:
8585
return 'v';
8686
case unreachable:
87-
WASM_UNREACHABLE();
87+
WASM_UNREACHABLE("invalid type");
8888
}
89-
WASM_UNREACHABLE();
89+
WASM_UNREACHABLE("invalid type");
9090
}
9191

9292
std::string getSig(const FunctionType* type) {

src/binaryen-c.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ BinaryenLiteral toBinaryenLiteral(Literal x) {
7474
case Type::exnref: // there's no exnref literals
7575
case Type::none:
7676
case Type::unreachable:
77-
WASM_UNREACHABLE();
77+
WASM_UNREACHABLE("unexpected type");
7878
}
7979
return ret;
8080
}
@@ -95,9 +95,9 @@ Literal fromBinaryenLiteral(BinaryenLiteral x) {
9595
case Type::exnref: // there's no exnref literals
9696
case Type::none:
9797
case Type::unreachable:
98-
WASM_UNREACHABLE();
98+
WASM_UNREACHABLE("unexpected type");
9999
}
100-
WASM_UNREACHABLE();
100+
WASM_UNREACHABLE("invalid type");
101101
}
102102

103103
// Mutexes (global for now; in theory if multiple modules
@@ -216,7 +216,7 @@ void printArg(std::ostream& setup, std::ostream& out, BinaryenLiteral arg) {
216216
case Type::exnref: // there's no exnref literals
217217
case Type::none:
218218
case Type::unreachable:
219-
WASM_UNREACHABLE();
219+
WASM_UNREACHABLE("unexpected type");
220220
}
221221
}
222222

src/cfg/cfg-traversal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
365365
return;
366366
}
367367
}
368-
WASM_UNREACHABLE();
368+
WASM_UNREACHABLE("not found");
369369
}
370370
};
371371

src/compiler-support.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,10 @@
2525
#define __has_builtin(x) 0
2626
#endif
2727

28-
// If control flow reaches the point of the WASM_UNREACHABLE(), the program is
29-
// undefined.
30-
#if __has_builtin(__builtin_unreachable) && defined(NDEBUG)
31-
#define WASM_UNREACHABLE() __builtin_unreachable()
28+
#if __has_builtin(__builtin_unreachable)
29+
#define WASM_BUILTIN_UNREACHABLE __builtin_unreachable()
3230
#elif defined(_MSC_VER)
33-
#define WASM_UNREACHABLE() __assume(false)
34-
#elif __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
35-
#include "sanitizer/common_interface_defs.h"
36-
#define WASM_UNREACHABLE() \
37-
do { \
38-
__sanitizer_print_stack_trace(); \
39-
__builtin_trap(); \
40-
} while (0)
41-
#else
42-
#include <assert.h>
43-
#include <stdlib.h>
44-
#define WASM_UNREACHABLE() \
45-
do { \
46-
assert(false); \
47-
abort(); \
48-
} while (0)
31+
#define WASM_BUILTIN_UNREACHABLE __assume(false)
4932
#endif
5033

5134
#ifdef __GNUC__

src/dataflow/graph.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> {
547547
opposite = LeUInt64;
548548
break;
549549
default:
550-
WASM_UNREACHABLE();
550+
WASM_UNREACHABLE("unexpected op");
551551
}
552552
auto* ret =
553553
visitBinary(builder.makeBinary(opposite, curr->right, curr->left));
@@ -783,7 +783,7 @@ struct Graph : public UnifiedExpressionVisitor<Graph, Node*> {
783783
// variable value.
784784
return Builder(*module).makeCall(FAKE_CALL, {}, node->wasmType);
785785
} else {
786-
WASM_UNREACHABLE(); // TODO
786+
WASM_UNREACHABLE("unexpected node type"); // TODO
787787
}
788788
}
789789

src/dataflow/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct Node {
165165
case Bad:
166166
return unreachable;
167167
default:
168-
WASM_UNREACHABLE();
168+
WASM_UNREACHABLE("invalid node type");
169169
}
170170
}
171171

src/dataflow/utils.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ inline std::ostream& dump(Node* node, std::ostream& o, size_t indent = 0) {
6767
case Node::Type::Bad:
6868
o << "bad";
6969
break;
70-
default:
71-
WASM_UNREACHABLE();
7270
}
7371
if (!node->values.empty()) {
7472
o << '\n';

src/ir/ReFinalize.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ void ReFinalize::visitFunction(Function* curr) {
151151
}
152152
}
153153

154-
void ReFinalize::visitFunctionType(FunctionType* curr) { WASM_UNREACHABLE(); }
155-
void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE(); }
156-
void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE(); }
157-
void ReFinalize::visitTable(Table* curr) { WASM_UNREACHABLE(); }
158-
void ReFinalize::visitMemory(Memory* curr) { WASM_UNREACHABLE(); }
159-
void ReFinalize::visitEvent(Event* curr) { WASM_UNREACHABLE(); }
160-
void ReFinalize::visitModule(Module* curr) { WASM_UNREACHABLE(); }
154+
void ReFinalize::visitFunctionType(FunctionType* curr) {
155+
WASM_UNREACHABLE("unimp");
156+
}
157+
void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE("unimp"); }
158+
void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE("unimp"); }
159+
void ReFinalize::visitTable(Table* curr) { WASM_UNREACHABLE("unimp"); }
160+
void ReFinalize::visitMemory(Memory* curr) { WASM_UNREACHABLE("unimp"); }
161+
void ReFinalize::visitEvent(Event* curr) { WASM_UNREACHABLE("unimp"); }
162+
void ReFinalize::visitModule(Module* curr) { WASM_UNREACHABLE("unimp"); }
161163

162164
void ReFinalize::updateBreakValueType(Name name, Type type) {
163165
if (type != unreachable || breakValues.count(name) == 0) {

0 commit comments

Comments
 (0)