AstGen: fix refing inferred allocs

Closes  #13285
This commit is contained in:
Veikka Tuominen 2022-10-24 17:30:47 +03:00
parent 4fc944dde8
commit 4ac8ec4c5c
3 changed files with 21 additions and 2 deletions

View File

@ -9709,7 +9709,7 @@ fn rvalue(
const result_index = refToIndex(result) orelse
return gz.addUnTok(.ref, result, src_token);
const zir_tags = gz.astgen.instructions.items(.tag);
if (zir_tags[result_index].isParam())
if (zir_tags[result_index].isParam() or astgen.isInferred(result))
return gz.addUnTok(.ref, result, src_token);
const gop = try astgen.ref_table.getOrPut(astgen.gpa, result_index);
if (!gop.found_existing) {
@ -12196,6 +12196,13 @@ fn isInferred(astgen: *AstGen, ref: Zir.Inst.Ref) bool {
.alloc_inferred_comptime_mut,
=> true,
.extended => {
const zir_data = astgen.instructions.items(.data);
if (zir_data[inst].extended.opcode != .alloc) return false;
const small = @bitCast(Zir.Inst.AllocExtended.Small, zir_data[inst].extended.small);
return !small.has_type;
},
else => false,
};
}

View File

@ -108,8 +108,9 @@ test {
_ = @import("behavior/bugs/13112.zig");
_ = @import("behavior/bugs/13128.zig");
_ = @import("behavior/bugs/13164.zig");
_ = @import("behavior/bugs/13171.zig");
_ = @import("behavior/bugs/13159.zig");
_ = @import("behavior/bugs/13171.zig");
_ = @import("behavior/bugs/13285.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,11 @@
const Crasher = struct {
lets_crash: u64 = 0,
};
test {
var a: Crasher = undefined;
var crasher_ptr = &a;
var crasher_local = crasher_ptr.*;
const crasher_local_ptr = &crasher_local;
crasher_local_ptr.lets_crash = 1;
}