Skip to content

Commit ba78d79

Browse files
committed
Zir: fix instruction tracking when function signatures are given
1 parent d02c2c7 commit ba78d79

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

lib/std/zig/Zir.zig

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4481,11 +4481,18 @@ fn findTrackableInner(
44814481
.func,
44824482
.func_inferred,
44834483
=> {
4484+
const inst_data = datas[@intFromEnum(inst)].pl_node;
4485+
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
4486+
4487+
if (extra.data.body_len == 0) {
4488+
// This is just a prototype. No need to track.
4489+
assert(extra.data.ret_body_len < 2);
4490+
return;
4491+
}
4492+
44844493
assert(contents.func_decl == null);
44854494
contents.func_decl = inst;
44864495

4487-
const inst_data = datas[@intFromEnum(inst)].pl_node;
4488-
const extra = zir.extraData(Inst.Func, inst_data.payload_index);
44894496
var extra_index: usize = extra.end;
44904497
switch (extra.data.ret_body_len) {
44914498
0 => {},
@@ -4500,11 +4507,19 @@ fn findTrackableInner(
45004507
return zir.findTrackableBody(gpa, contents, defers, body);
45014508
},
45024509
.func_fancy => {
4510+
const inst_data = datas[@intFromEnum(inst)].pl_node;
4511+
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
4512+
4513+
if (extra.data.body_len == 0) {
4514+
// This is just a prototype. No need to track.
4515+
assert(!extra.data.bits.has_cc_body);
4516+
assert(!extra.data.bits.has_ret_ty_body);
4517+
return;
4518+
}
4519+
45034520
assert(contents.func_decl == null);
45044521
contents.func_decl = inst;
45054522

4506-
const inst_data = datas[@intFromEnum(inst)].pl_node;
4507-
const extra = zir.extraData(Inst.FuncFancy, inst_data.payload_index);
45084523
var extra_index: usize = extra.end;
45094524

45104525
if (extra.data.bits.has_cc_body) {
@@ -5026,10 +5041,16 @@ pub fn assertTrackable(zir: Zir, inst_idx: Zir.Inst.Index) void {
50265041
.struct_init_ref,
50275042
.struct_init_anon,
50285043
=> {}, // tracked in order, as the owner instructions of anonymous struct types
5029-
.func,
5030-
.func_inferred,
5031-
.func_fancy,
5032-
=> {}, // tracked in order, as the owner instructions of function bodies
5044+
.func, .func_inferred => {
5045+
// These are tracked provided they are actual function declarations, not just bodies.
5046+
const extra = zir.extraData(Inst.Func, inst.data.pl_node.payload_index);
5047+
assert(extra.data.body_len != 0);
5048+
},
5049+
.func_fancy => {
5050+
// These are tracked provided they are actual function declarations, not just bodies.
5051+
const extra = zir.extraData(Inst.FuncFancy, inst.data.pl_node.payload_index);
5052+
assert(extra.data.body_len != 0);
5053+
},
50335054
.declaration => {}, // tracked by correlating names in the namespace of the parent container
50345055
.extended => switch (inst.data.extended.opcode) {
50355056
.struct_decl,

0 commit comments

Comments
 (0)