From d686113bd2b2e2207137de6ef81e515bc4a3aa07 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Dec 2017 22:38:02 -0500 Subject: fix crash when implicitly casting array of len 0 to slice closes #660 --- src/codegen.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 7fe4f95f85..7546416090 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2722,6 +2722,9 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru } static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRef *instruction) { + if (!type_has_bits(instruction->base.value.type)) { + return nullptr; + } LLVMValueRef value = ir_llvm_value(g, instruction->value); if (handle_is_ptr(instruction->value->value.type)) { return value; @@ -3013,6 +3016,15 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst add_bounds_check(g, end_val, LLVMIntEQ, nullptr, LLVMIntULE, array_end); } } + if (!type_has_bits(array_type)) { + LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, ""); + + // TODO if debug safety is on, store 0xaaaaaaa in ptr field + LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, ""); + gen_store_untyped(g, len_value, len_field_ptr, 0, false); + return tmp_struct_ptr; + } + LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_ptr_index, ""); LLVMValueRef indices[] = { -- cgit v1.2.3