authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-21 15:16:59-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-21 15:19:56-07:00
log25f3be32db148c2816547c75462285ae8f5e99eb
treefa8d29a65b4c85737161180394a1357acb32ead1
parentfc6e111b76764ae00e2c868ad46f39235837e239

Sema: fix fn pointer align disagrees with fn align error

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

2 files changed, 10 insertions(+), 5 deletions(-)

src/Sema.zig+4-2
......@@ -14209,8 +14209,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1420914209 if (inst_data.size != .One) {
1421014210 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
1421114211 }
14212 const fn_align = elem_ty.abiAlignment(target);
14213 if (inst_data.flags.has_align and abi_align != 0 and abi_align != fn_align) {
14212 const fn_align = elem_ty.fnInfo().alignment;
14213 if (inst_data.flags.has_align and abi_align != 0 and fn_align != 0 and
14214 abi_align != fn_align)
14215 {
1421414216 return sema.fail(block, align_src, "function pointer alignment disagrees with function alignment", .{});
1421514217 }
1421614218 } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) {
test/cases/compile_errors/function_ptr_alignment.zig+6-3
......@@ -16,10 +16,13 @@ comptime {
1616 var a: *align(2) fn () void = undefined;
1717 _ = a;
1818}
19comptime {
20 var a: *align(1) fn () align(2) void = undefined;
21 _ = a;
22}
1923
2024// error
2125// backend=stage2
22// target=x86_64-linux
26// target=native
2327//
24// :2:19: error: function pointer alignment disagrees with function alignment
25// :16:19: error: function pointer alignment disagrees with function alignment
28// :20:19: error: function pointer alignment disagrees with function alignment