zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 25f3be32db148c2816547c75462285ae8f5e99eb (tree)
parent fc6e111b76764ae00e2c868ad46f39235837e239
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 21 Jul 2022 15:16:59 -0700

Sema: fix fn pointer align disagrees with fn align error

Check the specified function alignment rather than the effective
function alignment.

Diffstat:
Msrc/Sema.zig | 6++++--
Mtest/cases/compile_errors/function_ptr_alignment.zig | 9++++++---
2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -14209,8 +14209,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air if (inst_data.size != .One) { return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{}); } - const fn_align = elem_ty.abiAlignment(target); - if (inst_data.flags.has_align and abi_align != 0 and abi_align != fn_align) { + const fn_align = elem_ty.fnInfo().alignment; + if (inst_data.flags.has_align and abi_align != 0 and fn_align != 0 and + abi_align != fn_align) + { return sema.fail(block, align_src, "function pointer alignment disagrees with function alignment", .{}); } } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) { diff --git a/test/cases/compile_errors/function_ptr_alignment.zig b/test/cases/compile_errors/function_ptr_alignment.zig @@ -16,10 +16,13 @@ comptime { var a: *align(2) fn () void = undefined; _ = a; } +comptime { + var a: *align(1) fn () align(2) void = undefined; + _ = a; +} // error // backend=stage2 -// target=x86_64-linux +// target=native // -// :2:19: error: function pointer alignment disagrees with function alignment -// :16:19: error: function pointer alignment disagrees with function alignment +// :20:19: error: function pointer alignment disagrees with function alignment