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 14:33:26-08:00
logf91df39ad2a54bc5367ba562ca703e564dd4a38d
tree490b5ee62acd2c0ba3708510f4cda30d6efab020
parent3bc1c719bd632e6baccb574bf75cb93f0bdef08f

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
......@@ -3343,7 +3343,7 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen
33433343 LLVMValueRef expr_val = ir_llvm_value(g, instruction->operand);
33443344 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, expr_val, indices, 2, "");
33453345 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
3346 } else if (ir_want_runtime_safety(g, &instruction->base)) {
3346 } else if (ir_want_runtime_safety(g, &instruction->base) && ptr_index != SIZE_MAX) {
33473347 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, result_loc, ptr_index, "");
33483348 gen_undef_init(g, slice_ptr_type, slice_ptr_type, ptr_field_ptr);
33493349 }
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}