authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-24 17:30:47+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-27 01:31:18+03:00
log4ac8ec4c5c80f6eca0ac7d7955c5486ef55ce042
tree2c3c82f5531e65b74d34b003a8048956a04b873c
parent4fc944dde813638410850515b0d1b156e5b6e920

AstGen: fix `ref`ing inferred allocs

Closes #13285

3 files changed, 21 insertions(+), 2 deletions(-)

src/AstGen.zig+8-1
......@@ -9709,7 +9709,7 @@ fn rvalue(
97099709 const result_index = refToIndex(result) orelse
97109710 return gz.addUnTok(.ref, result, src_token);
97119711 const zir_tags = gz.astgen.instructions.items(.tag);
9712 if (zir_tags[result_index].isParam())
9712 if (zir_tags[result_index].isParam() or astgen.isInferred(result))
97139713 return gz.addUnTok(.ref, result, src_token);
97149714 const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index);
97159715 if (!gop.found_existing) {
......@@ -12196,6 +12196,13 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
1219612196 .alloc_inferred_comptime_mut,
1219712197 => true,
1219812198
12199 .extended => {
12200 const zir_data = astgen.instructions.items(.data);
12201 if (zir_data[inst].extended.opcode != .alloc) return false;
12202 const small = @bitCast(Zir.Inst.AllocExtended.Small, zir_data[inst].extended.small);
12203 return !small.has_type;
12204 },
12205
1219912206 else => false,
1220012207 };
1220112208}
test/behavior.zig+2-1
......@@ -108,8 +108,9 @@ test {
108108 _ = @import("behavior/bugs/13112.zig");
109109 _ = @import("behavior/bugs/13128.zig");
110110 _ = @import("behavior/bugs/13164.zig");
111 _ = @import("behavior/bugs/13171.zig");
112111 _ = @import("behavior/bugs/13159.zig");
112 _ = @import("behavior/bugs/13171.zig");
113 _ = @import("behavior/bugs/13285.zig");
113114 _ = @import("behavior/byteswap.zig");
114115 _ = @import("behavior/byval_arg_var.zig");
115116 _ = @import("behavior/call.zig");
test/behavior/bugs/13285.zig created+11
......@@ -0,0 +1,11 @@
1const Crasher = struct {
2 lets_crash: u64 = 0,
3};
4
5test {
6 var a: Crasher = undefined;
7 var crasher_ptr = &a;
8 var crasher_local = crasher_ptr.*;
9 const crasher_local_ptr = &crasher_local;
10 crasher_local_ptr.lets_crash = 1;
11}