mirror of
https://github.com/ziglang/zig.git
synced 2026-01-09 17:05:16 +00:00
Sema: validateArrayInit detect bitcast before store
This commit is contained in:
parent
d506275a06
commit
ffa6f895ff
26
src/Sema.zig
26
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user