aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-06-13 11:40:20 +0300
committerVeikka Tuominen <git@vexu.eu>2022-06-17 18:57:02 +0300
commitffa6f895fff52846bc4b82cc9b449d0f7224d7d9 (patch)
tree84eb9a9bacbaf6fe077e834658d5f2ad6c624463 /src/Sema.zig
parentd506275a06dd5e9ad8be63f9e44abb7d8bea88b3 (diff)
downloadzig-ffa6f895fff52846bc4b82cc9b449d0f7224d7d9.tar.gz
zig-ffa6f895fff52846bc4b82cc9b449d0f7224d7d9.zip
Sema: validateArrayInit detect bitcast before store
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index a769194776..af3e824855 100644
--- 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;