Skip to content

Commit 52f8695

Browse files
committed
fix runtime slice of pointer not setting length
1 parent 6bf3503 commit 52f8695

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/codegen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,9 +5530,16 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrI
55305530
}
55315531

55325532
LLVMValueRef tmp_struct_ptr = ir_llvm_value(g, instruction->result_loc);
5533+
55335534
size_t gen_ptr_index = result_type->data.structure.fields[slice_ptr_index]->gen_index;
55345535
LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_ptr_index, "");
55355536
gen_store_untyped(g, slice_start_ptr, ptr_field_ptr, 0, false);
5537+
5538+
size_t gen_len_index = result_type->data.structure.fields[slice_len_index]->gen_index;
5539+
LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, gen_len_index, "");
5540+
LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
5541+
gen_store_untyped(g, len_value, len_field_ptr, 0, false);
5542+
55365543
return tmp_struct_ptr;
55375544

55385545
} else if (array_type->id == ZigTypeIdStruct) {

0 commit comments

Comments
 (0)