| author | |
| committer | |
| log | 25f3be32db148c2816547c75462285ae8f5e99eb |
| tree | fa8d29a65b4c85737161180394a1357acb32ead1 |
| parent | fc6e111b76764ae00e2c868ad46f39235837e239 |
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 | 14209 | if (inst_data.size != .One) { |
| 14210 | 14210 | return sema.fail(block, elem_ty_src, "function pointers must be single pointers", .{}); |
| 14211 | 14211 | } |
| 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 | { | |
| 14214 | 14216 | return sema.fail(block, align_src, "function pointer alignment disagrees with function alignment", .{}); |
| 14215 | 14217 | } |
| 14216 | 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 | 16 | var a: *align(2) fn () void = undefined; |
| 17 | 17 | _ = a; |
| 18 | 18 | } |
| 19 | comptime { | |
| 20 | var a: *align(1) fn () align(2) void = undefined; | |
| 21 | _ = a; | |
| 22 | } | |
| 19 | 23 | |
| 20 | 24 | // error |
| 21 | 25 | // backend=stage2 |
| 22 | // target=x86_64-linux | |
| 26 | // target=native | |
| 23 | 27 | // |
| 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 |