| ... | @@ -2658,12 +2658,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -2658,12 +2658,14 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 2658 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | 2658 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; |
| 2659 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; | 2659 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2660 | const ptr_ty = f.air.typeOf(bin_op.lhs); | 2660 | const ptr_ty = f.air.typeOf(bin_op.lhs); |
| | 2661 | const child_ty = ptr_ty.childType(); |
| 2661 | | 2662 | |
| 2662 | const ptr = try f.resolveInst(bin_op.lhs); | 2663 | const ptr = try f.resolveInst(bin_op.lhs); |
| | 2664 | if (!child_ty.hasRuntimeBitsIgnoreComptime()) return ptr; |
| 2663 | const index = try f.resolveInst(bin_op.rhs); | 2665 | const index = try f.resolveInst(bin_op.rhs); |
| | 2666 | |
| 2664 | const writer = f.object.writer(); | 2667 | const writer = f.object.writer(); |
| 2665 | const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const); | 2668 | const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const); |
| 2666 | | | |
| 2667 | try writer.writeAll(" = &("); | 2669 | try writer.writeAll(" = &("); |
| 2668 | if (ptr_ty.ptrSize() == .One) { | 2670 | if (ptr_ty.ptrSize() == .One) { |
| 2669 | // It's a pointer to an array, so we need to de-reference. | 2671 | // It's a pointer to an array, so we need to de-reference. |
| ... | @@ -2717,15 +2719,23 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -2717,15 +2719,23 @@ fn airSliceElemPtr(f: *Function, inst: Air.Inst.Index) !CValue { |
| 2717 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; | 2719 | const ty_pl = f.air.instructions.items(.data)[inst].ty_pl; |
| 2718 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; | 2720 | const bin_op = f.air.extraData(Air.Bin, ty_pl.payload).data; |
| 2719 | | 2721 | |
| | 2722 | const slice_ty = f.air.typeOf(bin_op.lhs); |
| | 2723 | const child_ty = slice_ty.elemType2(); |
| 2720 | const slice = try f.resolveInst(bin_op.lhs); | 2724 | const slice = try f.resolveInst(bin_op.lhs); |
| 2721 | const index = try f.resolveInst(bin_op.rhs); | 2725 | |
| 2722 | const writer = f.object.writer(); | 2726 | const writer = f.object.writer(); |
| 2723 | const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const); | 2727 | const local = try f.allocLocal(f.air.typeOfIndex(inst), .Const); |
| 2724 | try writer.writeAll(" = &"); | 2728 | try writer.writeAll(" = "); |
| | 2729 | if (child_ty.hasRuntimeBitsIgnoreComptime()) try writer.writeByte('&'); |
| 2725 | try f.writeCValue(writer, slice, .Other); | 2730 | try f.writeCValue(writer, slice, .Other); |
| 2726 | try writer.writeAll(".ptr["); | 2731 | try writer.writeAll(".ptr"); |
| 2727 | try f.writeCValue(writer, index, .Other); | 2732 | if (child_ty.hasRuntimeBitsIgnoreComptime()) { |
| 2728 | try writer.writeAll("];\n"); | 2733 | const index = try f.resolveInst(bin_op.rhs); |
| | 2734 | try writer.writeByte('['); |
| | 2735 | try f.writeCValue(writer, index, .Other); |
| | 2736 | try writer.writeByte(']'); |
| | 2737 | } |
| | 2738 | try writer.writeAll(";\n"); |
| 2729 | return local; | 2739 | return local; |
| 2730 | } | 2740 | } |
| 2731 | | 2741 | |