fix lazy value in ir_analyze_instruction_elem_ptr

This commit is contained in:
xackus 2020-04-06 09:44:06 +02:00 committed by Andrew Kelley
parent ed23dad487
commit 66b2477ab6
3 changed files with 14 additions and 1 deletions

View File

@ -21149,7 +21149,11 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
bool safety_check_on = elem_ptr_instruction->safety_check_on;
if (instr_is_comptime(casted_elem_index)) {
uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint);
ZigValue *index_val = ir_resolve_const(ira, casted_elem_index, UndefBad);
if (index_val == nullptr)
return ira->codegen->invalid_inst_gen;
uint64_t index = bigint_as_u64(&index_val->data.x_bigint);
if (array_type->id == ZigTypeIdArray) {
uint64_t array_len = array_type->data.array.len +
(array_type->data.array.sentinel != nullptr);

View File

@ -44,6 +44,7 @@ comptime {
_ = @import("behavior/bugs/4769_a.zig");
_ = @import("behavior/bugs/4769_b.zig");
_ = @import("behavior/bugs/4769_c.zig");
_ = @import("behavior/bugs/4954.zig");
_ = @import("behavior/bugs/394.zig");
_ = @import("behavior/bugs/421.zig");
_ = @import("behavior/bugs/529.zig");

View File

@ -0,0 +1,8 @@
fn f(buf: []u8) void {
var ptr = &buf[@sizeOf(u32)];
}
test "crash" {
var buf: [4096]u8 = undefined;
f(&buf);
}