zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ffa6f895fff52846bc4b82cc9b449d0f7224d7d9 (tree)
parent d506275a06dd5e9ad8be63f9e44abb7d8bea88b3
Author: Veikka Tuominen <git@vexu.eu>
Date:   Mon, 13 Jun 2022 11:40:20 +0300

Sema: validateArrayInit detect bitcast before store

Diffstat:
Msrc/Sema.zig | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -3795,6 +3795,32 @@ fn zirValidateArrayInit( } continue; }, + .bitcast => { + // %a = bitcast(*arr_ty, %array_base) + // %b = ptr_elem_ptr(%a, %index) + // %c = bitcast(*elem_ty, %b) + // %d = store(%c, %val) + if (air_datas[next_air_inst].ty_op.operand != elem_ptr_air_ref) { + array_is_comptime = false; + continue; + } + const store_inst = block.instructions.items[block_index + 2]; + if (air_tags[store_inst] != .store) { + array_is_comptime = false; + continue; + } + const bin_op = air_datas[store_inst].bin_op; + if (bin_op.lhs != Air.indexToRef(next_air_inst)) { + array_is_comptime = false; + continue; + } + if (try sema.resolveMaybeUndefValAllowVariables(block, elem_src, bin_op.rhs)) |val| { + element_vals[i] = val; + } else { + array_is_comptime = false; + } + continue; + }, else => { array_is_comptime = false; continue;