ir: More changes to sentinel-terminated const arrays
* Don't add an extra slot for the sentinel. Most of the code keeps using the constant value from the type descriptor, let's harmonize all the code dealing with sentinels. * Properly write out sentinel values when reinterpreting pointers at comptime. * Allow the reading of the 0th element in a `[0:S]T` type.
This commit is contained in:
@@ -20578,11 +20578,6 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
|
||||
}
|
||||
|
||||
if (array_type->id == ZigTypeIdArray) {
|
||||
if (array_type->data.array.len == 0) {
|
||||
ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
|
||||
buf_sprintf("index 0 outside array of size 0"));
|
||||
return ira->codegen->invalid_inst_gen;
|
||||
}
|
||||
ZigType *child_type = array_type->data.array.child_type;
|
||||
if (ptr_type->data.pointer.host_int_bytes == 0) {
|
||||
return_type = get_pointer_to_type_extra(ira->codegen, child_type,
|
||||
@@ -27657,6 +27652,9 @@ static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue
|
||||
buf_write_value_bytes(codegen, &buf[buf_i], elem);
|
||||
buf_i += type_size(codegen, elem->type);
|
||||
}
|
||||
if (val->type->id == ZigTypeIdArray && val->type->data.array.sentinel != nullptr) {
|
||||
buf_write_value_bytes(codegen, &buf[buf_i], val->type->data.array.sentinel);
|
||||
}
|
||||
}
|
||||
|
||||
static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) {
|
||||
|
||||
Reference in New Issue
Block a user