Skip to content

Commit 52d0bed

Browse files
committed
wasm2c warm.h: make panic a macro to propagate noreturn
I got the following warning when compiling zig-wasm2c: C:\git\zig\stage1\wasm.h(55) : warning C4715: 'WasmMut_toC': not all control paths return a value This is because the C compiler doesn't understand that the panic function from `panic.h` is noreturn. I addressed this making panic a macro so the caller sees that abort is called and is able to see that it's a "noreturn codepath".
1 parent 8aab222 commit 52d0bed

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

stage1/panic.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <stdio.h>
55
#include <stdlib.h>
66

7-
static void panic(const char *reason) {
8-
fprintf(stderr, "%s\n", reason);
9-
abort();
10-
}
7+
// panic is a macro rather than a function so the caller can derive
8+
// that this is noreturn from the call to abort()
9+
#define panic(reason) do { fprintf(stderr, "%s\n", reason); abort(); } while (0)
1110

1211
#endif /* PANIC_H */

0 commit comments

Comments
 (0)