Commit Graph

4 Commits

Author SHA1 Message Date
Jonathan Marler
1165e13c25 wasm2c: avoid indexing null pointer triggering undefined behavior
Using zig cc to compile and run wasm2c on zig.wasm on Windows triggers
what appears to be a sanitizer crash.  The FuncGen reuse array pointer is
initialized to null and at some point it's resized to a length of zero,
which triggers this code to execute:

    memcpy(&self->reuse[self->reuse_i], &self->reuse[reuse_top], sizeof(uint32_t) * reuse_n);

Given the current values, this equates to:

    memcpy(&(NULL)[0], &(NULL)[0], 0);

Taking the address of the first element of a null pointer doesn't trigger
any actual runtime problem, since the pointer won't be dereferenced because
were passing 0 as the length to memcpy, however, it seems that the C spec
considers indexing a null pointer to be undefined behavior even if you
don't use the resulting value (or are just taking the address of an
indexed pointer).
2024-06-17 14:34:52 -04:00
Jacob Young
6966fb8ca5 wasm2c: reuse locals
* Reduce stack usage of a -O0 build of zig1 by 33%.
 * Avoid compiler builtin calls.
2022-12-09 03:45:29 -05:00
Jacob Young
9f4ef4de23 wasm2c: remove unnecessary brackets to reduce max bracket depth
This avoids the need to pass `-fbracket-depth=512` to clang.
2022-12-06 12:15:04 -07:00
Jacob Young
1263346774 use zig-wasm2c for bootstrapping 2022-12-06 12:15:04 -07:00