From 44ae891bd79cc8b2f9040a39c176317ebf4a4ef8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 6 Mar 2018 17:19:45 -0500 Subject: fix assertion when taking slice of zero-length array closes #788 --- src/ir.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 251c55df4f..61f04fef3d 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15821,9 +15821,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio TypeTableEntry *return_type; if (array_type->id == TypeTableEntryIdArray) { + uint32_t byte_alignment = ptr_type->data.pointer.alignment; + if (array_type->data.array.len == 0 && byte_alignment == 0) { + byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); + } TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, - ptr_type->data.pointer.alignment, 0, 0); + byte_alignment, 0, 0); return_type = get_slice_type(ira->codegen, slice_ptr_type); } else if (array_type->id == TypeTableEntryIdPointer) { TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, -- cgit v1.2.3