authorgravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-10-25 00:08:41-07:00
committergravatar for david@vortan.devDavid Rubin <david@vortan.dev> 2024-10-25 00:08:41-07:00
log97e584a6b9786ad942e4c8db0ce5b3b948ddad7e
treefce85bf8f7653f9f849c31a1934579c5e013dfb8
parent0d8330422877b2a4438b27c2706c8def20038f45
signaturelock-open Commit is signed but in an unrecognized format.

use `cCallingConvention` instead of `.C` in Sema

using `.C` in Sema is incorrect since it will be resolved under the target that Zig was compiled with, not the target build configuration. This is easily solved by just calling `cCallingConvention` on the target to resolve it.

1 files changed, 16 insertions(+), 1 deletions(-)

src/Sema.zig+16-1
...@@ -26619,6 +26619,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26619,6 +26619,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2661926619
26620 const pt = sema.pt;26620 const pt = sema.pt;
26621 const zcu = pt.zcu;26621 const zcu = pt.zcu;
26622 const ip = &zcu.intern_pool;
26622 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;26623 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
26623 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);26624 const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index);
26624 const target = zcu.getTarget();26625 const target = zcu.getTarget();
...@@ -26793,7 +26794,21 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -26793,7 +26794,21 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2679326794
26794 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&zcu.intern_pool) orelse return error.AnalysisFail)[0];26795 const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&zcu.intern_pool) orelse return error.AnalysisFail)[0];
26795 if (zir_decl.flags.is_export) {26796 if (zir_decl.flags.is_export) {
26796 break :cc .C;26797 break :cc target.cCallingConvention() orelse {
26798 // This target has no default C calling convention. We sometimes trigger a similar
26799 // error by trying to evaluate `std.builtin.CallingConvention.c`, so for consistency,
26800 // let's eval that now and just get the transitive error. (It's guaranteed to error
26801 // because it does the exact `cCallingConvention` call we just did.)
26802 const cc_type = try sema.getBuiltinType("CallingConvention");
26803 _ = try sema.namespaceLookupVal(
26804 block,
26805 LazySrcLoc.unneeded,
26806 cc_type.getNamespaceIndex(zcu),
26807 try ip.getOrPutString(sema.gpa, pt.tid, "c", .no_embedded_nulls),
26808 );
26809 // The above should have errored.
26810 @panic("std.builtin is corrupt");
26811 };
26797 }26812 }
26798 }26813 }
26799 break :cc .auto;26814 break :cc .auto;