Commit 25f3be32db

Andrew Kelley <andrew@ziglang.org>
2022-07-22 00:16:59
Sema: fix fn pointer align disagrees with fn align error
Check the specified function alignment rather than the effective function alignment.
1 parent fc6e111
Changed files (2)
src
test
cases
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) {
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