authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-17 20:11:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-19 09:53:55-04:00
log4435b05b6b007df9159058fb5ae6f8902eecd1d8
tree12cf6f9669b546acfd9089ecd8163c3c5b7027f8
parent2b4134459d468812ac106c124ee6fa5f5e8b9574
signature Commit is signed but in an unrecognized format.

fix regression when slicing 0-bit pointers


1 files changed, 13 insertions(+), 11 deletions(-)

src/codegen.cpp+13-11
...@@ -5513,6 +5513,15 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI...@@ -5513,6 +5513,15 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI
5513 }5513 }
5514 }5514 }
55155515
5516 if (!type_has_bits(g, array_type)) {
5517 LLVMValueRef tmp_struct_ptr = ir_llvm_value(g, instruction->result_loc);
5518 size_t gen_len_index = result_type->data.structure.fields[slice_len_index]->gen_index;
5519 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
5520 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
5521 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
5522 return tmp_struct_ptr;
5523 }
5524
5516 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");5525 LLVMValueRef slice_start_ptr = LLVMBuildInBoundsGEP(g->builder, array_ptr, &start_val, 1, "");
5517 if (result_type->id == ZigTypeIdPointer) {5526 if (result_type->id == ZigTypeIdPointer) {
5518 ir_assert(instruction->result_loc == nullptr, &instruction->base);5527 ir_assert(instruction->result_loc == nullptr, &instruction->base);
...@@ -5521,18 +5530,11 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI...@@ -5521,18 +5530,11 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI
5521 }5530 }
55225531
5523 LLVMValueRef tmp_struct_ptr = ir_llvm_value(g, instruction->result_loc);5532 LLVMValueRef tmp_struct_ptr = ir_llvm_value(g, instruction->result_loc);
5524 if (type_has_bits(g, array_type)) {5533 size_t gen_ptr_index = result_type->data.structure.fields[slice_ptr_index]->gen_index;
5525 size_t gen_ptr_index = result_type->data.structure.fields[slice_ptr_index]->gen_index;5534 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
5526 LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");5535 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
5527 gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
5528 }
5529
5530 size_t gen_len_index = result_type->data.structure.fields[slice_len_index]->gen_index;
5531 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
5532 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
5533 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
5534
5535 return tmp_struct_ptr;5536 return tmp_struct_ptr;
5537
5536 } else if (array_type->id == ZigTypeIdStruct) {5538 } else if (array_type->id == ZigTypeIdStruct) {
5537 assert(array_type->data.structure.special == StructSpecialSlice);5539 assert(array_type->data.structure.special == StructSpecialSlice);
5538 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);5540 assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);