aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2022-12-03 03:39:28 -0500
committerJacob Young <jacobly0@users.noreply.github.com>2022-12-03 08:21:03 -0500
commit81c271cc6298bf164b202a194ef18b56665ce2d9 (patch)
treeb5f6c7e64853d3cd7c1e1297e8b74fe61b5549d4 /src/codegen/c.zig
parent2cfc08ba0d5ad2f0f4cef71ad4365dfd0e71b9bd (diff)
downloadzig-81c271cc6298bf164b202a194ef18b56665ce2d9.tar.gz
zig-81c271cc6298bf164b202a194ef18b56665ce2d9.zip
cbe: don't emit extern decls that are already exported
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index ef125c6aee..48719d6efe 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -2427,11 +2427,15 @@ pub fn genFunc(f: *Function) !void {
defer tracy.end();
const o = &f.object;
+ const tv: TypedValue = .{
+ .ty = o.dg.decl.ty,
+ .val = o.dg.decl.val,
+ };
o.code_header = std.ArrayList(u8).init(f.object.dg.gpa);
defer o.code_header.deinit();
- const is_global = o.dg.module.decl_exports.contains(f.func.owner_decl);
+ const is_global = o.dg.declIsGlobal(tv);
const fwd_decl_writer = o.dg.fwd_decl.writer();
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
try o.dg.renderFunctionSignature(fwd_decl_writer, .Forward);
@@ -2478,14 +2482,11 @@ pub fn genDecl(o: *Object) !void {
try fwd_decl_writer.writeAll(";\n");
} else if (tv.val.castTag(.variable)) |var_payload| {
const variable: *Module.Var = var_payload.data;
+
const is_global = o.dg.declIsGlobal(tv) or variable.is_extern;
const fwd_decl_writer = o.dg.fwd_decl.writer();
- const decl_c_value: CValue = if (is_global) .{
- .bytes = mem.span(o.dg.decl.name),
- } else .{
- .decl = o.dg.decl_index,
- };
+ const decl_c_value = CValue{ .decl = o.dg.decl_index };
try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
if (variable.is_threadlocal) try fwd_decl_writer.writeAll("zig_threadlocal ");