From ab658e32bdfa234b6c33f0718cac7a23fbd4074f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 24 Apr 2022 20:07:39 -0700 Subject: [PATCH] Sema: fix export with Internal linkage The Export tables should only be populated with non-internal exports. --- src/Sema.zig | 4 ++++ test/behavior/export.zig | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Sema.zig b/src/Sema.zig index 14511fe82d..72256d6ae5 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4321,6 +4321,10 @@ pub fn analyzeExport( const Export = Module.Export; const mod = sema.mod; + if (borrowed_options.linkage == .Internal) { + return; + } + try mod.ensureDeclAnalyzed(exported_decl_index); const exported_decl = mod.declPtr(exported_decl_index); // TODO run the same checks as we do for C ABI struct fields diff --git a/test/behavior/export.zig b/test/behavior/export.zig index 5f8ccf02d4..3943fd2834 100644 --- a/test/behavior/export.zig +++ b/test/behavior/export.zig @@ -45,3 +45,13 @@ test "exporting enum type and value" { }; try expect(S.e == .two); } + +test "exporting with internal linkage" { + const S = struct { + fn foo() callconv(.C) void {} + comptime { + @export(foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .Internal }); + } + }; + S.foo(); +}