authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-10-25 10:07:41-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-25 19:57:02-07:00
log51f7e5412afd4e934da8a5e93ad91e6de5ae02ca
tree6c1a5e1ce641ab69d093cef46887d2c11b543c84
parent405ba2680f180541cb91323fad579e2ca5cf5eb0

cbe: update `DeclGen.decl_index` to support anon decls


3 files changed, 68 insertions(+), 70 deletions(-)

src/Compilation.zig+1-1
...@@ -3556,7 +3556,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v...@@ -3556,7 +3556,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
3556 .gpa = gpa,3556 .gpa = gpa,
3557 .module = module,3557 .module = module,
3558 .error_msg = null,3558 .error_msg = null,
3559 .decl_index = decl_index.toOptional(),3559 .pass = .{ .decl = decl_index },
3560 .is_naked_fn = false,3560 .is_naked_fn = false,
3561 .fwd_decl = fwd_decl.toManaged(gpa),3561 .fwd_decl = fwd_decl.toManaged(gpa),
3562 .ctypes = .{},3562 .ctypes = .{},
src/codegen/c.zig+55-55
...@@ -522,7 +522,7 @@ pub const Object = struct {...@@ -522,7 +522,7 @@ pub const Object = struct {
522pub const DeclGen = struct {522pub const DeclGen = struct {
523 gpa: mem.Allocator,523 gpa: mem.Allocator,
524 module: *Module,524 module: *Module,
525 decl_index: Decl.OptionalIndex,525 pass: Pass,
526 is_naked_fn: bool,526 is_naked_fn: bool,
527 /// This is a borrowed reference from `link.C`.527 /// This is a borrowed reference from `link.C`.
528 fwd_decl: std.ArrayList(u8),528 fwd_decl: std.ArrayList(u8),
...@@ -533,10 +533,16 @@ pub const DeclGen = struct {...@@ -533,10 +533,16 @@ pub const DeclGen = struct {
533 anon_decl_deps: std.AutoArrayHashMapUnmanaged(InternPool.Index, C.DeclBlock),533 anon_decl_deps: std.AutoArrayHashMapUnmanaged(InternPool.Index, C.DeclBlock),
534 aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment),534 aligned_anon_decls: std.AutoArrayHashMapUnmanaged(InternPool.Index, Alignment),
535535
536 pub const Pass = union(enum) {
537 decl: Decl.Index,
538 anon: InternPool.Index,
539 flush,
540 };
541
536 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {542 fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } {
537 @setCold(true);543 @setCold(true);
538 const mod = dg.module;544 const mod = dg.module;
539 const decl_index = dg.decl_index.unwrap().?;545 const decl_index = dg.pass.decl;
540 const decl = mod.declPtr(decl_index);546 const decl = mod.declPtr(decl_index);
541 const src = LazySrcLoc.nodeOffset(0);547 const src = LazySrcLoc.nodeOffset(0);
542 const src_loc = src.toSrcLoc(decl, mod);548 const src_loc = src.toSrcLoc(decl, mod);
...@@ -1566,18 +1572,11 @@ pub const DeclGen = struct {...@@ -1566,18 +1572,11 @@ pub const DeclGen = struct {
1566 else => unreachable,1572 else => unreachable,
1567 }1573 }
1568 }1574 }
1569 if (fn_decl.val.getFunction(mod)) |func| if (func.analysis(ip).is_cold) try w.writeAll("zig_cold ");1575 if (fn_decl.val.getFunction(mod)) |func| if (func.analysis(ip).is_cold)
1576 try w.writeAll("zig_cold ");
1570 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");1577 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
15711578
1572 const trailing = try renderTypePrefix(1579 const trailing = try renderTypePrefix(dg.pass, store.*, mod, w, fn_cty_idx, .suffix, .{});
1573 dg.decl_index,
1574 store.*,
1575 mod,
1576 w,
1577 fn_cty_idx,
1578 .suffix,
1579 .{},
1580 );
1581 try w.print("{}", .{trailing});1580 try w.print("{}", .{trailing});
15821581
1583 if (toCallingConvention(fn_info.cc)) |call_conv| {1582 if (toCallingConvention(fn_info.cc)) |call_conv| {
...@@ -1597,7 +1596,7 @@ pub const DeclGen = struct {...@@ -1597,7 +1596,7 @@ pub const DeclGen = struct {
1597 }1596 }
15981597
1599 try renderTypeSuffix(1598 try renderTypeSuffix(
1600 dg.decl_index,1599 dg.pass,
1601 store.*,1600 store.*,
1602 mod,1601 mod,
1603 w,1602 w,
...@@ -1652,8 +1651,8 @@ pub const DeclGen = struct {...@@ -1652,8 +1651,8 @@ pub const DeclGen = struct {
1652 fn renderCType(dg: *DeclGen, w: anytype, idx: CType.Index) error{ OutOfMemory, AnalysisFail }!void {1651 fn renderCType(dg: *DeclGen, w: anytype, idx: CType.Index) error{ OutOfMemory, AnalysisFail }!void {
1653 const store = &dg.ctypes.set;1652 const store = &dg.ctypes.set;
1654 const mod = dg.module;1653 const mod = dg.module;
1655 _ = try renderTypePrefix(dg.decl_index, store.*, mod, w, idx, .suffix, .{});1654 _ = try renderTypePrefix(dg.pass, store.*, mod, w, idx, .suffix, .{});
1656 try renderTypeSuffix(dg.decl_index, store.*, mod, w, idx, .suffix, .{});1655 try renderTypeSuffix(dg.pass, store.*, mod, w, idx, .suffix, .{});
1657 }1656 }
16581657
1659 const IntCastContext = union(enum) {1658 const IntCastContext = union(enum) {
...@@ -1799,11 +1798,10 @@ pub const DeclGen = struct {...@@ -1799,11 +1798,10 @@ pub const DeclGen = struct {
1799 .gt => try w.print("zig_align({}) ", .{alignas.toByteUnits()}),1798 .gt => try w.print("zig_align({}) ", .{alignas.toByteUnits()}),
1800 }1799 }
18011800
1802 const trailing =1801 const trailing = try renderTypePrefix(dg.pass, store.*, mod, w, cty_idx, .suffix, qualifiers);
1803 try renderTypePrefix(dg.decl_index, store.*, mod, w, cty_idx, .suffix, qualifiers);
1804 try w.print("{}", .{trailing});1802 try w.print("{}", .{trailing});
1805 try dg.writeCValue(w, name);1803 try dg.writeCValue(w, name);
1806 try renderTypeSuffix(dg.decl_index, store.*, mod, w, cty_idx, .suffix, .{});1804 try renderTypeSuffix(dg.pass, store.*, mod, w, cty_idx, .suffix, .{});
1807 }1805 }
18081806
1809 fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool {1807 fn declIsGlobal(dg: *DeclGen, tv: TypedValue) bool {
...@@ -2070,7 +2068,7 @@ fn renderTypeName(...@@ -2070,7 +2068,7 @@ fn renderTypeName(
2070 }2068 }
2071}2069}
2072fn renderTypePrefix(2070fn renderTypePrefix(
2073 decl: Decl.OptionalIndex,2071 pass: DeclGen.Pass,
2074 store: CType.Store.Set,2072 store: CType.Store.Set,
2075 mod: *Module,2073 mod: *Module,
2076 w: anytype,2074 w: anytype,
...@@ -2128,7 +2126,7 @@ fn renderTypePrefix(...@@ -2128,7 +2126,7 @@ fn renderTypePrefix(
2128 => |tag| {2126 => |tag| {
2129 const child_idx = cty.cast(CType.Payload.Child).?.data;2127 const child_idx = cty.cast(CType.Payload.Child).?.data;
2130 const child_trailing = try renderTypePrefix(2128 const child_trailing = try renderTypePrefix(
2131 decl,2129 pass,
2132 store,2130 store,
2133 mod,2131 mod,
2134 w,2132 w,
...@@ -2152,15 +2150,8 @@ fn renderTypePrefix(...@@ -2152,15 +2150,8 @@ fn renderTypePrefix(
2152 .vector,2150 .vector,
2153 => {2151 => {
2154 const child_idx = cty.cast(CType.Payload.Sequence).?.data.elem_type;2152 const child_idx = cty.cast(CType.Payload.Sequence).?.data.elem_type;
2155 const child_trailing = try renderTypePrefix(2153 const child_trailing =
2156 decl,2154 try renderTypePrefix(pass, store, mod, w, child_idx, .suffix, qualifiers);
2157 store,
2158 mod,
2159 w,
2160 child_idx,
2161 .suffix,
2162 qualifiers,
2163 );
2164 switch (parent_fix) {2155 switch (parent_fix) {
2165 .prefix => {2156 .prefix => {
2166 try w.print("{}(", .{child_trailing});2157 try w.print("{}(", .{child_trailing});
...@@ -2172,10 +2163,11 @@ fn renderTypePrefix(...@@ -2172,10 +2163,11 @@ fn renderTypePrefix(
21722163
2173 .fwd_anon_struct,2164 .fwd_anon_struct,
2174 .fwd_anon_union,2165 .fwd_anon_union,
2175 => if (decl.unwrap()) |decl_index|2166 => switch (pass) {
2176 try w.print("anon__{d}_{d}", .{ @intFromEnum(decl_index), idx })2167 .decl => |decl_index| try w.print("decl__{d}_{d}", .{ @intFromEnum(decl_index), idx }),
2177 else2168 .anon => |anon_decl| try w.print("anon__{d}_{d}", .{ @intFromEnum(anon_decl), idx }),
2178 try renderTypeName(mod, w, idx, cty, ""),2169 .flush => try renderTypeName(mod, w, idx, cty, ""),
2170 },
21792171
2180 .fwd_struct,2172 .fwd_struct,
2181 .fwd_union,2173 .fwd_union,
...@@ -2201,7 +2193,7 @@ fn renderTypePrefix(...@@ -2201,7 +2193,7 @@ fn renderTypePrefix(
2201 .packed_struct,2193 .packed_struct,
2202 .packed_union,2194 .packed_union,
2203 => return renderTypePrefix(2195 => return renderTypePrefix(
2204 decl,2196 pass,
2205 store,2197 store,
2206 mod,2198 mod,
2207 w,2199 w,
...@@ -2214,7 +2206,7 @@ fn renderTypePrefix(...@@ -2214,7 +2206,7 @@ fn renderTypePrefix(
2214 .varargs_function,2206 .varargs_function,
2215 => {2207 => {
2216 const child_trailing = try renderTypePrefix(2208 const child_trailing = try renderTypePrefix(
2217 decl,2209 pass,
2218 store,2210 store,
2219 mod,2211 mod,
2220 w,2212 w,
...@@ -2241,7 +2233,7 @@ fn renderTypePrefix(...@@ -2241,7 +2233,7 @@ fn renderTypePrefix(
2241 return trailing;2233 return trailing;
2242}2234}
2243fn renderTypeSuffix(2235fn renderTypeSuffix(
2244 decl: Decl.OptionalIndex,2236 pass: DeclGen.Pass,
2245 store: CType.Store.Set,2237 store: CType.Store.Set,
2246 mod: *Module,2238 mod: *Module,
2247 w: anytype,2239 w: anytype,
...@@ -2295,7 +2287,7 @@ fn renderTypeSuffix(...@@ -2295,7 +2287,7 @@ fn renderTypeSuffix(
2295 .pointer_volatile,2287 .pointer_volatile,
2296 .pointer_const_volatile,2288 .pointer_const_volatile,
2297 => try renderTypeSuffix(2289 => try renderTypeSuffix(
2298 decl,2290 pass,
2299 store,2291 store,
2300 mod,2292 mod,
2301 w,2293 w,
...@@ -2314,7 +2306,7 @@ fn renderTypeSuffix(...@@ -2314,7 +2306,7 @@ fn renderTypeSuffix(
23142306
2315 try w.print("[{}]", .{cty.cast(CType.Payload.Sequence).?.data.len});2307 try w.print("[{}]", .{cty.cast(CType.Payload.Sequence).?.data.len});
2316 try renderTypeSuffix(2308 try renderTypeSuffix(
2317 decl,2309 pass,
2318 store,2310 store,
2319 mod,2311 mod,
2320 w,2312 w,
...@@ -2356,9 +2348,9 @@ fn renderTypeSuffix(...@@ -2356,9 +2348,9 @@ fn renderTypeSuffix(
2356 if (need_comma) try w.writeAll(", ");2348 if (need_comma) try w.writeAll(", ");
2357 need_comma = true;2349 need_comma = true;
2358 const trailing =2350 const trailing =
2359 try renderTypePrefix(decl, store, mod, w, param_type, .suffix, qualifiers);2351 try renderTypePrefix(pass, store, mod, w, param_type, .suffix, qualifiers);
2360 if (qualifiers.contains(.@"const")) try w.print("{}a{d}", .{ trailing, param_i });2352 if (qualifiers.contains(.@"const")) try w.print("{}a{d}", .{ trailing, param_i });
2361 try renderTypeSuffix(decl, store, mod, w, param_type, .suffix, .{});2353 try renderTypeSuffix(pass, store, mod, w, param_type, .suffix, .{});
2362 }2354 }
2363 switch (tag) {2355 switch (tag) {
2364 .function => {},2356 .function => {},
...@@ -2372,7 +2364,7 @@ fn renderTypeSuffix(...@@ -2372,7 +2364,7 @@ fn renderTypeSuffix(
2372 if (!need_comma) try w.writeAll("void");2364 if (!need_comma) try w.writeAll("void");
2373 try w.writeByte(')');2365 try w.writeByte(')');
23742366
2375 try renderTypeSuffix(decl, store, mod, w, data.return_type, .suffix, .{});2367 try renderTypeSuffix(pass, store, mod, w, data.return_type, .suffix, .{});
2376 },2368 },
2377 }2369 }
2378}2370}
...@@ -2392,9 +2384,9 @@ fn renderAggregateFields(...@@ -2392,9 +2384,9 @@ fn renderAggregateFields(
2392 .eq => {},2384 .eq => {},
2393 .gt => try writer.print("zig_align({}) ", .{field.alignas.toByteUnits()}),2385 .gt => try writer.print("zig_align({}) ", .{field.alignas.toByteUnits()}),
2394 }2386 }
2395 const trailing = try renderTypePrefix(.none, store, mod, writer, field.type, .suffix, .{});2387 const trailing = try renderTypePrefix(.flush, store, mod, writer, field.type, .suffix, .{});
2396 try writer.print("{}{ }", .{ trailing, fmtIdent(mem.span(field.name)) });2388 try writer.print("{}{ }", .{ trailing, fmtIdent(mem.span(field.name)) });
2397 try renderTypeSuffix(.none, store, mod, writer, field.type, .suffix, .{});2389 try renderTypeSuffix(.flush, store, mod, writer, field.type, .suffix, .{});
2398 try writer.writeAll(";\n");2390 try writer.writeAll(";\n");
2399 }2391 }
2400 try writer.writeByteNTimes(' ', indent);2392 try writer.writeByteNTimes(' ', indent);
...@@ -2406,18 +2398,18 @@ pub fn genTypeDecl(...@@ -2406,18 +2398,18 @@ pub fn genTypeDecl(
2406 writer: anytype,2398 writer: anytype,
2407 global_store: CType.Store.Set,2399 global_store: CType.Store.Set,
2408 global_idx: CType.Index,2400 global_idx: CType.Index,
2409 decl: Decl.OptionalIndex,2401 pass: DeclGen.Pass,
2410 decl_store: CType.Store.Set,2402 decl_store: CType.Store.Set,
2411 decl_idx: CType.Index,2403 decl_idx: CType.Index,
2412 found_existing: bool,2404 found_existing: bool,
2413) !void {2405) !void {
2414 const global_cty = global_store.indexToCType(global_idx);2406 const global_cty = global_store.indexToCType(global_idx);
2415 switch (global_cty.tag()) {2407 switch (global_cty.tag()) {
2416 .fwd_anon_struct => if (decl != .none) {2408 .fwd_anon_struct => if (pass != .flush) {
2417 try writer.writeAll("typedef ");2409 try writer.writeAll("typedef ");
2418 _ = try renderTypePrefix(.none, global_store, mod, writer, global_idx, .suffix, .{});2410 _ = try renderTypePrefix(.flush, global_store, mod, writer, global_idx, .suffix, .{});
2419 try writer.writeByte(' ');2411 try writer.writeByte(' ');
2420 _ = try renderTypePrefix(decl, decl_store, mod, writer, decl_idx, .suffix, .{});2412 _ = try renderTypePrefix(pass, decl_store, mod, writer, decl_idx, .suffix, .{});
2421 try writer.writeAll(";\n");2413 try writer.writeAll(";\n");
2422 },2414 },
24232415
...@@ -2435,7 +2427,15 @@ pub fn genTypeDecl(...@@ -2435,7 +2427,15 @@ pub fn genTypeDecl(
2435 .fwd_union,2427 .fwd_union,
2436 => {2428 => {
2437 const owner_decl = global_cty.cast(CType.Payload.FwdDecl).?.data;2429 const owner_decl = global_cty.cast(CType.Payload.FwdDecl).?.data;
2438 _ = try renderTypePrefix(.none, global_store, mod, writer, global_idx, .suffix, .{});2430 _ = try renderTypePrefix(
2431 .flush,
2432 global_store,
2433 mod,
2434 writer,
2435 global_idx,
2436 .suffix,
2437 .{},
2438 );
2439 try writer.writeAll("; // ");2439 try writer.writeAll("; // ");
2440 try mod.declPtr(owner_decl).renderFullyQualifiedName(mod, writer);2440 try mod.declPtr(owner_decl).renderFullyQualifiedName(mod, writer);
2441 try writer.writeByte('\n');2441 try writer.writeByte('\n');
...@@ -2552,7 +2552,7 @@ fn genExports(o: *Object) !void {...@@ -2552,7 +2552,7 @@ fn genExports(o: *Object) !void {
25522552
2553 const mod = o.dg.module;2553 const mod = o.dg.module;
2554 const ip = &mod.intern_pool;2554 const ip = &mod.intern_pool;
2555 const decl_index = o.dg.decl_index.unwrap().?;2555 const decl_index = o.dg.pass.decl;
2556 const decl = mod.declPtr(decl_index);2556 const decl = mod.declPtr(decl_index);
2557 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };2557 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };
2558 const fwd = o.dg.fwd_decl.writer();2558 const fwd = o.dg.fwd_decl.writer();
...@@ -2692,7 +2692,7 @@ pub fn genFunc(f: *Function) !void {...@@ -2692,7 +2692,7 @@ pub fn genFunc(f: *Function) !void {
2692 const o = &f.object;2692 const o = &f.object;
2693 const mod = o.dg.module;2693 const mod = o.dg.module;
2694 const gpa = o.dg.gpa;2694 const gpa = o.dg.gpa;
2695 const decl_index = o.dg.decl_index.unwrap().?;2695 const decl_index = o.dg.pass.decl;
2696 const decl = mod.declPtr(decl_index);2696 const decl = mod.declPtr(decl_index);
2697 const tv: TypedValue = .{2697 const tv: TypedValue = .{
2698 .ty = decl.ty,2698 .ty = decl.ty,
...@@ -2779,7 +2779,7 @@ pub fn genDecl(o: *Object) !void {...@@ -2779,7 +2779,7 @@ pub fn genDecl(o: *Object) !void {
2779 defer tracy.end();2779 defer tracy.end();
27802780
2781 const mod = o.dg.module;2781 const mod = o.dg.module;
2782 const decl_index = o.dg.decl_index.unwrap().?;2782 const decl_index = o.dg.pass.decl;
2783 const decl = mod.declPtr(decl_index);2783 const decl = mod.declPtr(decl_index);
2784 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };2784 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };
27852785
...@@ -2825,13 +2825,13 @@ pub fn genDeclValue(...@@ -2825,13 +2825,13 @@ pub fn genDeclValue(
2825 alignment: Alignment,2825 alignment: Alignment,
2826 link_section: InternPool.OptionalNullTerminatedString,2826 link_section: InternPool.OptionalNullTerminatedString,
2827) !void {2827) !void {
2828 const mod = o.dg.module;
2828 const fwd_decl_writer = o.dg.fwd_decl.writer();2829 const fwd_decl_writer = o.dg.fwd_decl.writer();
28292830
2830 try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");2831 try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static ");
2831 try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete);2832 try o.dg.renderTypeAndName(fwd_decl_writer, tv.ty, decl_c_value, Const, alignment, .complete);
2832 try fwd_decl_writer.writeAll(";\n");2833 try fwd_decl_writer.writeAll(";\n");
28332834
2834 const mod = o.dg.module;
2835 const w = o.writer();2835 const w = o.writer();
2836 if (!is_global) try w.writeAll("static ");2836 if (!is_global) try w.writeAll("static ");
2837 if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s|2837 if (mod.intern_pool.stringToSliceUnwrap(link_section)) |s|
...@@ -2848,7 +2848,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {...@@ -2848,7 +2848,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
2848 defer tracy.end();2848 defer tracy.end();
28492849
2850 const mod = dg.module;2850 const mod = dg.module;
2851 const decl_index = dg.decl_index.unwrap().?;2851 const decl_index = dg.pass.decl;
2852 const decl = mod.declPtr(decl_index);2852 const decl = mod.declPtr(decl_index);
2853 const tv: TypedValue = .{2853 const tv: TypedValue = .{
2854 .ty = decl.ty,2854 .ty = decl.ty,
...@@ -2861,7 +2861,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {...@@ -2861,7 +2861,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
2861 const is_global = dg.declIsGlobal(tv);2861 const is_global = dg.declIsGlobal(tv);
2862 if (is_global) {2862 if (is_global) {
2863 try writer.writeAll("zig_extern ");2863 try writer.writeAll("zig_extern ");
2864 try dg.renderFunctionSignature(writer, dg.decl_index.unwrap().?, .complete, .{ .export_index = 0 });2864 try dg.renderFunctionSignature(writer, dg.pass.decl, .complete, .{ .export_index = 0 });
2865 try dg.fwd_decl.appendSlice(";\n");2865 try dg.fwd_decl.appendSlice(";\n");
2866 }2866 }
2867 },2867 },
...@@ -7279,7 +7279,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7279,7 +7279,7 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue {
7279fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {7279fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
7280 const mod = f.object.dg.module;7280 const mod = f.object.dg.module;
7281 const inst_ty = f.typeOfIndex(inst);7281 const inst_ty = f.typeOfIndex(inst);
7282 const decl_index = f.object.dg.decl_index.unwrap().?;7282 const decl_index = f.object.dg.pass.decl;
7283 const decl = mod.declPtr(decl_index);7283 const decl = mod.declPtr(decl_index);
7284 const fn_cty = try f.typeToCType(decl.ty, .complete);7284 const fn_cty = try f.typeToCType(decl.ty, .complete);
7285 const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;7285 const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;
src/link/C.zig+12-14
...@@ -158,9 +158,7 @@ pub fn updateFunc(...@@ -158,9 +158,7 @@ pub fn updateFunc(
158 const decl_index = func.owner_decl;158 const decl_index = func.owner_decl;
159 const decl = module.declPtr(decl_index);159 const decl = module.declPtr(decl_index);
160 const gop = try self.decl_table.getOrPut(gpa, decl_index);160 const gop = try self.decl_table.getOrPut(gpa, decl_index);
161 if (!gop.found_existing) {161 if (!gop.found_existing) gop.value_ptr.* = .{};
162 gop.value_ptr.* = .{};
163 }
164 const ctypes = &gop.value_ptr.ctypes;162 const ctypes = &gop.value_ptr.ctypes;
165 const lazy_fns = &gop.value_ptr.lazy_fns;163 const lazy_fns = &gop.value_ptr.lazy_fns;
166 const fwd_decl = &self.fwd_decl_buf;164 const fwd_decl = &self.fwd_decl_buf;
...@@ -180,7 +178,7 @@ pub fn updateFunc(...@@ -180,7 +178,7 @@ pub fn updateFunc(
180 .gpa = gpa,178 .gpa = gpa,
181 .module = module,179 .module = module,
182 .error_msg = null,180 .error_msg = null,
183 .decl_index = decl_index.toOptional(),181 .pass = .{ .decl = decl_index },
184 .is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked,182 .is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked,
185 .fwd_decl = fwd_decl.toManaged(gpa),183 .fwd_decl = fwd_decl.toManaged(gpa),
186 .ctypes = ctypes.*,184 .ctypes = ctypes.*,
...@@ -235,7 +233,7 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {...@@ -235,7 +233,7 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
235 .gpa = gpa,233 .gpa = gpa,
236 .module = module,234 .module = module,
237 .error_msg = null,235 .error_msg = null,
238 .decl_index = .none,236 .pass = .{ .anon = anon_decl },
239 .is_naked_fn = false,237 .is_naked_fn = false,
240 .fwd_decl = fwd_decl.toManaged(gpa),238 .fwd_decl = fwd_decl.toManaged(gpa),
241 .ctypes = .{},239 .ctypes = .{},
...@@ -302,7 +300,7 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi...@@ -302,7 +300,7 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi
302 .gpa = gpa,300 .gpa = gpa,
303 .module = module,301 .module = module,
304 .error_msg = null,302 .error_msg = null,
305 .decl_index = decl_index.toOptional(),303 .pass = .{ .decl = decl_index },
306 .is_naked_fn = false,304 .is_naked_fn = false,
307 .fwd_decl = fwd_decl.toManaged(gpa),305 .fwd_decl = fwd_decl.toManaged(gpa),
308 .ctypes = ctypes.*,306 .ctypes = ctypes.*,
...@@ -438,14 +436,14 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo...@@ -438,14 +436,14 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo
438 // We need to flush lazy ctypes after flushing all decls but before flushing any decl ctypes.436 // We need to flush lazy ctypes after flushing all decls but before flushing any decl ctypes.
439 // This ensures that every lazy CType.Index exactly matches the global CType.Index.437 // This ensures that every lazy CType.Index exactly matches the global CType.Index.
440 assert(f.ctypes.count() == 0);438 assert(f.ctypes.count() == 0);
441 try self.flushCTypes(&f, .none, f.lazy_ctypes);439 try self.flushCTypes(&f, .flush, f.lazy_ctypes);
442440
443 for (self.anon_decls.values()) |decl_block| {441 for (self.anon_decls.keys(), self.anon_decls.values()) |anon_decl, decl_block| {
444 try self.flushCTypes(&f, .none, decl_block.ctypes);442 try self.flushCTypes(&f, .{ .anon = anon_decl }, decl_block.ctypes);
445 }443 }
446444
447 for (self.decl_table.keys(), self.decl_table.values()) |decl_index, decl_block| {445 for (self.decl_table.keys(), self.decl_table.values()) |decl_index, decl_block| {
448 try self.flushCTypes(&f, decl_index.toOptional(), decl_block.ctypes);446 try self.flushCTypes(&f, .{ .decl = decl_index }, decl_block.ctypes);
449 }447 }
450 }448 }
451449
...@@ -516,7 +514,7 @@ const FlushDeclError = error{...@@ -516,7 +514,7 @@ const FlushDeclError = error{
516fn flushCTypes(514fn flushCTypes(
517 self: *C,515 self: *C,
518 f: *Flush,516 f: *Flush,
519 decl_index: Module.Decl.OptionalIndex,517 pass: codegen.DeclGen.Pass,
520 decl_ctypes: codegen.CType.Store,518 decl_ctypes: codegen.CType.Store,
521) FlushDeclError!void {519) FlushDeclError!void {
522 const gpa = self.base.allocator;520 const gpa = self.base.allocator;
...@@ -591,7 +589,7 @@ fn flushCTypes(...@@ -591,7 +589,7 @@ fn flushCTypes(
591 writer,589 writer,
592 global_ctypes.set,590 global_ctypes.set,
593 global_idx,591 global_idx,
594 decl_index,592 pass,
595 decl_ctypes.set,593 decl_ctypes.set,
596 decl_idx,594 decl_idx,
597 gop.found_existing,595 gop.found_existing,
...@@ -610,7 +608,7 @@ fn flushErrDecls(self: *C, ctypes: *codegen.CType.Store) FlushDeclError!void {...@@ -610,7 +608,7 @@ fn flushErrDecls(self: *C, ctypes: *codegen.CType.Store) FlushDeclError!void {
610 .gpa = gpa,608 .gpa = gpa,
611 .module = self.base.options.module.?,609 .module = self.base.options.module.?,
612 .error_msg = null,610 .error_msg = null,
613 .decl_index = .none,611 .pass = .flush,
614 .is_naked_fn = false,612 .is_naked_fn = false,
615 .fwd_decl = fwd_decl.toManaged(gpa),613 .fwd_decl = fwd_decl.toManaged(gpa),
616 .ctypes = ctypes.*,614 .ctypes = ctypes.*,
...@@ -652,7 +650,7 @@ fn flushLazyFn(...@@ -652,7 +650,7 @@ fn flushLazyFn(
652 .gpa = gpa,650 .gpa = gpa,
653 .module = self.base.options.module.?,651 .module = self.base.options.module.?,
654 .error_msg = null,652 .error_msg = null,
655 .decl_index = .none,653 .pass = .flush,
656 .is_naked_fn = false,654 .is_naked_fn = false,
657 .fwd_decl = fwd_decl.toManaged(gpa),655 .fwd_decl = fwd_decl.toManaged(gpa),
658 .ctypes = ctypes.*,656 .ctypes = ctypes.*,