diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-26 15:49:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-26 15:49:19 -0400 |
| commit | ef42ef9ce8d36d26f91669a61f4c57fd3e4d58d7 (patch) | |
| tree | 2f0d5c4175cf0f01f7e3ebf75cfcec4be31ccc2a /src/analyze.cpp | |
| parent | dd62f63c04fa21427869abea86bbc5fc090b6562 (diff) | |
| parent | 08b0cae7778ea0946d595df451b9b4a65ff09abd (diff) | |
| download | zig-ef42ef9ce8d36d26f91669a61f4c57fd3e4d58d7.tar.gz zig-ef42ef9ce8d36d26f91669a61f4c57fd3e4d58d7.zip | |
Merge pull request #5440 from kubkon/align-fn-error-wasm
Make align expr on fns a compile error in Wasm
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 4aa4d129c2..9062c1fb13 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; } |
