From 0d8330422877b2a4438b27c2706c8def20038f45 Mon Sep 17 00:00:00 2001 From: David Rubin Date: Thu, 24 Oct 2024 23:23:15 -0700 Subject: [PATCH 1/2] remove leak from linker --- src/Compilation.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilation.zig b/src/Compilation.zig index fac1ad4baa..73185a91ea 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1962,6 +1962,7 @@ pub fn destroy(comp: *Compilation) void { comp.failed_win32_resources.deinit(gpa); comp.link_diags.deinit(); + comp.link_task_queue.deinit(gpa); comp.clearMiscFailures(); From 97e584a6b9786ad942e4c8db0ce5b3b948ddad7e Mon Sep 17 00:00:00 2001 From: David Rubin Date: Fri, 25 Oct 2024 00:08:41 -0700 Subject: [PATCH 2/2] 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. --- src/Sema.zig | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Sema.zig b/src/Sema.zig index 9912a610ff..400e08bed5 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26619,6 +26619,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A const pt = sema.pt; const zcu = pt.zcu; + const ip = &zcu.intern_pool; const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; const extra = sema.code.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); const target = zcu.getTarget(); @@ -26793,7 +26794,21 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A const zir_decl = sema.code.getDeclaration(decl_inst.resolve(&zcu.intern_pool) orelse return error.AnalysisFail)[0]; if (zir_decl.flags.is_export) { - break :cc .C; + break :cc target.cCallingConvention() orelse { + // This target has no default C calling convention. We sometimes trigger a similar + // error by trying to evaluate `std.builtin.CallingConvention.c`, so for consistency, + // let's eval that now and just get the transitive error. (It's guaranteed to error + // because it does the exact `cCallingConvention` call we just did.) + const cc_type = try sema.getBuiltinType("CallingConvention"); + _ = try sema.namespaceLookupVal( + block, + LazySrcLoc.unneeded, + cc_type.getNamespaceIndex(zcu), + try ip.getOrPutString(sema.gpa, pt.tid, "c", .no_embedded_nulls), + ); + // The above should have errored. + @panic("std.builtin is corrupt"); + }; } } break :cc .auto;