| ... | ... | @@ -2731,17 +2731,49 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2731 | 2731 | // instructions from the block, replacing the inst_map entry |
| 2732 | 2732 | // corresponding to the ZIR alloc instruction with a constant |
| 2733 | 2733 | // decl_ref pointing at our new Decl. |
| 2734 | // dbg_stmt instructions may be interspersed into this pattern |
| 2735 | // which must be ignored. |
| 2734 | 2736 | if (block.instructions.items.len < 3) break :ct; |
| 2735 | | // zig fmt: off |
| 2736 | | const const_inst = block.instructions.items[block.instructions.items.len - 3]; |
| 2737 | | const bitcast_inst = block.instructions.items[block.instructions.items.len - 2]; |
| 2738 | | const store_inst = block.instructions.items[block.instructions.items.len - 1]; |
| 2739 | | const air_tags = sema.air_instructions.items(.tag); |
| 2737 | var search_index: usize = block.instructions.items.len; |
| 2738 | const air_tags = sema.air_instructions.items(.tag); |
| 2740 | 2739 | const air_datas = sema.air_instructions.items(.data); |
| 2741 | | if (air_tags[const_inst] != .constant) break :ct; |
| 2742 | | if (air_tags[bitcast_inst] != .bitcast ) break :ct; |
| 2743 | | if (air_tags[store_inst] != .store ) break :ct; |
| 2744 | | // zig fmt: on |
| 2740 | |
| 2741 | const store_inst = while (true) { |
| 2742 | if (search_index == 0) break :ct; |
| 2743 | search_index -= 1; |
| 2744 | |
| 2745 | const candidate = block.instructions.items[search_index]; |
| 2746 | switch (air_tags[candidate]) { |
| 2747 | .dbg_stmt => continue, |
| 2748 | .store => break candidate, |
| 2749 | else => break :ct, |
| 2750 | } |
| 2751 | } else unreachable; // TODO shouldn't need this |
| 2752 | |
| 2753 | const bitcast_inst = while (true) { |
| 2754 | if (search_index == 0) break :ct; |
| 2755 | search_index -= 1; |
| 2756 | |
| 2757 | const candidate = block.instructions.items[search_index]; |
| 2758 | switch (air_tags[candidate]) { |
| 2759 | .dbg_stmt => continue, |
| 2760 | .bitcast => break candidate, |
| 2761 | else => break :ct, |
| 2762 | } |
| 2763 | } else unreachable; // TODO shouldn't need this |
| 2764 | |
| 2765 | const const_inst = while (true) { |
| 2766 | if (search_index == 0) break :ct; |
| 2767 | search_index -= 1; |
| 2768 | |
| 2769 | const candidate = block.instructions.items[search_index]; |
| 2770 | switch (air_tags[candidate]) { |
| 2771 | .dbg_stmt => continue, |
| 2772 | .constant => break candidate, |
| 2773 | else => break :ct, |
| 2774 | } |
| 2775 | } else unreachable; // TODO shouldn't need this |
| 2776 | |
| 2745 | 2777 | const store_op = air_datas[store_inst].bin_op; |
| 2746 | 2778 | const store_val = (try sema.resolveMaybeUndefVal(block, src, store_op.rhs)) orelse break :ct; |
| 2747 | 2779 | if (store_op.lhs != Air.indexToRef(bitcast_inst)) break :ct; |