| ... | ... | @@ -4624,6 +4624,8 @@ fn validateUnionInit( |
| 4624 | 4624 | // If the union is comptime, we want `first_block_index` |
| 4625 | 4625 | // to point at %c so that the bitcast becomes the last instruction in the block. |
| 4626 | 4626 | // |
| 4627 | // Store instruction may be missing; if field type has only one possible value, this case is handled below. |
| 4628 | // |
| 4627 | 4629 | // In the case of a comptime-known pointer to a union, the |
| 4628 | 4630 | // the field_ptr instruction is missing, so we have to pattern-match |
| 4629 | 4631 | // based only on the store instructions. |
| ... | ... | @@ -4634,7 +4636,10 @@ fn validateUnionInit( |
| 4634 | 4636 | var init_val: ?Value = null; |
| 4635 | 4637 | while (block_index > 0) : (block_index -= 1) { |
| 4636 | 4638 | const store_inst = block.instructions.items[block_index]; |
| 4637 | | if (store_inst.toRef() == field_ptr_ref) break; |
| 4639 | if (store_inst.toRef() == field_ptr_ref) { |
| 4640 | first_block_index = block_index; |
| 4641 | break; |
| 4642 | } |
| 4638 | 4643 | switch (air_tags[@intFromEnum(store_inst)]) { |
| 4639 | 4644 | .store, .store_safe => {}, |
| 4640 | 4645 | else => continue, |
| ... | ... | @@ -4659,6 +4664,11 @@ fn validateUnionInit( |
| 4659 | 4664 | |
| 4660 | 4665 | const tag_ty = union_ty.unionTagTypeHypothetical(mod); |
| 4661 | 4666 | const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index); |
| 4667 | const field_type = union_ty.unionFieldType(tag_val, mod).?; |
| 4668 | |
| 4669 | if (try sema.typeHasOnePossibleValue(field_type)) |field_only_value| { |
| 4670 | init_val = field_only_value; |
| 4671 | } |
| 4662 | 4672 | |
| 4663 | 4673 | if (init_val) |val| { |
| 4664 | 4674 | // Our task is to delete all the `field_ptr` and `store` instructions, and insert |