aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-06-17 19:23:08 -0400
committerGitHub <noreply@github.com>2022-06-17 19:23:08 -0400
commit33cf6ef621114daad63d14067b6ff374e664d410 (patch)
tree9828aa24009a7f03a446433606c46e14f5667587 /src/Sema.zig
parentb66247c97af3deaa190d1ca8297166f932b022ff (diff)
parent28986a059075c2dce662c2f4e823b3efd283df87 (diff)
downloadzig-33cf6ef621114daad63d14067b6ff374e664d410.tar.gz
zig-33cf6ef621114daad63d14067b6ff374e664d410.zip
Merge pull request #11881 from Vexu/stage2
Stage2: fixes for bugs found while looking for miscompilations
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig38
1 files changed, 35 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 2b97c0624e..798dc06db1 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;
@@ -21772,7 +21798,7 @@ fn coerceTupleToArray(
) !Air.Inst.Ref {
const inst_ty = sema.typeOf(inst);
const inst_len = inst_ty.arrayLen();
- const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen());
+ const dest_len = dest_ty.arrayLen();
if (dest_len != inst_len) {
const msg = msg: {
@@ -21787,13 +21813,19 @@ fn coerceTupleToArray(
return sema.failWithOwnedErrorMsg(block, msg);
}
- const element_vals = try sema.arena.alloc(Value, dest_len);
- const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);
+ const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel());
+ const element_vals = try sema.arena.alloc(Value, dest_elems);
+ const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
const dest_elem_ty = dest_ty.childType();
var runtime_src: ?LazySrcLoc = null;
for (element_vals) |*elem, i_usize| {
const i = @intCast(u32, i_usize);
+ if (i_usize == inst_len) {
+ elem.* = dest_ty.sentinel().?;
+ element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*);
+ break;
+ }
const elem_src = inst_src; // TODO better source location
const elem_ref = try tupleField(sema, block, inst_src, inst, elem_src, i);
const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);