authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-26 23:07:47+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-27 15:34:13-07:00
log288b8b535face92941b3f6c7f3eb09baf347a558
treeedb3c7bf63fa7436d2c63b7909db9b692631e575
parent36b8f5d194c1c88e25eee3da111000edbe9eb3ea

stage1: Fix crash in *[N]T to []T conversion with zst

Prevent the crash by not making the codegen try to access the non-existing ptr field in the slice. Closes #6951

2 files changed, 7 insertions(+), 1 deletions(-)

src/stage1/codegen.cpp+1-1
......@@ -3349,7 +3349,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen
33493349 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);
33503350 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, expr_val, indices, 2, "");
33513351 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
3352 } else if (ir_want_runtime_safety(g, &instruction->base)) {
3352 } else if (ir_want_runtime_safety(g, &instruction->base) && ptr_index != SIZE_MAX) {
33533353 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, "");
33543354 gen_undef_init(g, slice_ptr_type, slice_ptr_type, ptr_field_ptr);
33553355 }
test/stage1/behavior/cast.zig+6
......@@ -908,3 +908,9 @@ test "cast from ?[*]T to ??[*]T" {
908908 const a: ??[*]u8 = @as(?[*]u8, null);
909909 expect(a != null and a.? == null);
910910}
911
912test "cast between *[N]void and []void" {
913 var a: [4]void = undefined;
914 var b: []void = &a;
915 expect(b.len == 4);
916}