diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-03-19 11:52:15 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-19 09:53:30 -0400 |
| commit | e3c92d05328d7b40927bed66e7c2500a7853cdc8 (patch) | |
| tree | 4e6a1b8e5ee17cf644288144bf66fe59f189c7b5 /src/ir.cpp | |
| parent | 7a361751e563c131399050f339dc47edf3c32325 (diff) | |
| download | zig-e3c92d05328d7b40927bed66e7c2500a7853cdc8.tar.gz zig-e3c92d05328d7b40927bed66e7c2500a7853cdc8.zip | |
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.
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index b9875a7efe..ef75744576 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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) { |
