authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 18:57:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 18:57:07-05:00
log7eb5acdc800b6683e4f3ce9312f707e568bb641e
tree38605ab88df0684e342a8916c3d8ef505c791719
parent217a5090ffed74f071a5c33798e3de029a2ee3fa
signaturelock-open Commit is signed but in an unrecognized format.

fix casting `[N:x]T` to `[N]T` memcpying too many bytes


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

src/ir.cpp+13-1
......@@ -16333,7 +16333,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1633316333 if (!type_has_bits(value_type)) {
1633416334 parent_ptr_align = 0;
1633516335 }
16336 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
16336 // If we're casting from a sentinel-terminated array to a non-sentinel-terminated array,
16337 // we actually need the result location pointer to *not* have a sentinel. Otherwise the generated
16338 // memcpy will write an extra byte to the destination, and THAT'S NO GOOD.
16339 ZigType *ptr_elem_type;
16340 if (value_type->id == ZigTypeIdArray && value_type->data.array.sentinel != nullptr &&
16341 dest_type->id == ZigTypeIdArray && dest_type->data.array.sentinel == nullptr)
16342 {
16343 ptr_elem_type = get_array_type(ira->codegen, value_type->data.array.child_type,
16344 value_type->data.array.len, nullptr);
16345 } else {
16346 ptr_elem_type = value_type;
16347 }
16348 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ptr_elem_type,
1633716349 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
1633816350 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1633916351