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...@@ -14209,8 +14209,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
14209 if (inst_data.size != .One) {14209 if (inst_data.size != .One) {
14210 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});14210 return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{});
14211 }14211 }
14212 const fn_align = elem_ty.abiAlignment(target);14212 const fn_align = elem_ty.fnInfo().alignment;
14213 if (inst_data.flags.has_align and abi_align != 0 and abi_align != fn_align) {14213 if (inst_data.flags.has_align and abi_align != 0 and fn_align != 0 and
14214 abi_align != fn_align)
14215 {
14214 return sema.fail(block, align_src, "function pointer alignment disagrees with function alignment", .{});14216 return sema.fail(block, align_src, "function pointer alignment disagrees with function alignment", .{});
14215 }14217 }
14216 } else if (inst_data.size == .Many and elem_ty.zigTypeTag() == .Opaque) {14218 } 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 {...@@ -16,10 +16,13 @@ comptime {
16 var a: *align(2) fn () void = undefined;16 var a: *align(2) fn () void = undefined;
17 _ = a;17 _ = a;
18}18}
19comptime {
20 var a: *align(1) fn () align(2) void = undefined;
21 _ = a;
22}
1923
20// error24// error
21// backend=stage225// backend=stage2
22// target=x86_64-linux26// target=native
23//27//
24// :2:19: error: function pointer alignment disagrees with function alignment28// :20:19: error: function pointer alignment disagrees with function alignment
25// :16:19: error: function pointer alignment disagrees with function alignment