diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2020-05-26 17:16:25 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2020-05-26 17:17:32 +0200 |
| commit | 015c899297c9fdc8ef9d0d22af29a7a0d0bdbc5c (patch) | |
| tree | dc7f91bfdd2d218628a99b9c4484533b4b890246 /src/analyze.cpp | |
| parent | 4b8077ea8e888382fc73dd8a19c6e9160f2cef46 (diff) | |
| download | zig-015c899297c9fdc8ef9d0d22af29a7a0d0bdbc5c.tar.gz zig-015c899297c9fdc8ef9d0d22af29a7a0d0bdbc5c.zip | |
Make align expr on fns a compile error in Wasm
In Wasm, specifying alignment of function pointers makes little sense
since function pointers are in fact indices to a Wasm table, therefore
any alignment check on those is invalid. This can cause unexpected
behaviour when checking expected alignment with `@ptrToInt(fn_ptr)`
or similar. This commit proposes to make `align` expressions a
compile error when compiled to Wasm architecture.
Some references:
[1] [Mozilla: WebAssembly Tables](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables)
[2] [Sunfishcode's Wasm Ref Manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#indirect-call)
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 88f967240a..ff1946c70e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1921,6 +1921,21 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc } if (fn_proto->align_expr != nullptr) { + if (target_is_wasm(g->zig_target)) { + // In Wasm, specifying alignment of function pointers makes little sense + // since function pointers are in fact indices to a Wasm table, therefore + // any alignment check on those is invalid. This can cause unexpected + // behaviour when checking expected alignment with `@ptrToInt(fn_ptr)` + // or similar. This commit proposes to make `align` expressions a + // compile error when compiled to Wasm architecture. + // + // Some references: + // [1] [Mozilla: WebAssembly Tables](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables) + // [2] [Sunfishcode's Wasm Ref Manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#indirect-call) + add_node_error(g, fn_proto->align_expr, + buf_sprintf("align(N) expr is not allowed on function prototypes in wasm32/wasm64")); + return g->builtin_types.entry_invalid; + } if (!analyze_const_align(g, child_scope, fn_proto->align_expr, &fn_type_id.alignment)) { return g->builtin_types.entry_invalid; } |
