| ... | ... | @@ -6732,7 +6732,7 @@ fn airAggFieldVal(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6732 | 6732 | if (field_ty.isInt(zcu)) return result_id; |
| 6733 | 6733 | return try cg.bitCast(field_ty, field_int_ty, result_id); |
| 6734 | 6734 | }, |
| 6735 | | else => return try cg.extractField(field_ty, object_id, field_index), |
| 6735 | else => return try cg.extractField(field_ty, object_id, cg.memberIndex(object_ty, field_index)), |
| 6736 | 6736 | }, |
| 6737 | 6737 | .@"union" => switch (object_ty.containerLayout(zcu)) { |
| 6738 | 6738 | .@"packed" => { |
| ... | ... | @@ -6882,7 +6882,8 @@ fn structFieldPtr( |
| 6882 | 6882 | return result_id; |
| 6883 | 6883 | }, |
| 6884 | 6884 | .auto, .@"extern" => { |
| 6885 | | return try cg.accessChain(result_ty_id, object_ptr, &.{field_index}); |
| 6885 | const member_index = cg.memberIndex(object_ty, field_index); |
| 6886 | return try cg.accessChain(result_ty_id, object_ptr, &.{member_index}); |
| 6886 | 6887 | }, |
| 6887 | 6888 | }, |
| 6888 | 6889 | .@"union" => switch (object_ty.containerLayout(zcu)) { |
| ... | ... | @@ -6937,6 +6938,33 @@ fn structFieldPtr( |
| 6937 | 6938 | } |
| 6938 | 6939 | } |
| 6939 | 6940 | |
| 6941 | fn memberIndex(cg: *CodeGen, struct_ty: Type, field_index: u32) u32 { |
| 6942 | const zcu = cg.zcu; |
| 6943 | const ip = &zcu.intern_pool; |
| 6944 | var index: u32 = 0; |
| 6945 | switch (ip.indexToKey(struct_ty.toIntern())) { |
| 6946 | .tuple_type => |tuple| { |
| 6947 | const types = tuple.types.get(ip)[0..field_index]; |
| 6948 | for (types, tuple.values.get(ip)[0..field_index]) |field_ty_index, field_val| { |
| 6949 | const field_ty: Type = .fromInterned(field_ty_index); |
| 6950 | if (field_val != .none or !field_ty.hasRuntimeBits(zcu)) continue; |
| 6951 | index += 1; |
| 6952 | } |
| 6953 | }, |
| 6954 | .struct_type => { |
| 6955 | const struct_type = ip.loadStructType(struct_ty.toIntern()); |
| 6956 | var it = struct_type.iterateRuntimeOrder(ip); |
| 6957 | while (it.next()) |i| { |
| 6958 | if (i == field_index) break; |
| 6959 | const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[i]); |
| 6960 | if (field_ty.hasRuntimeBits(zcu)) index += 1; |
| 6961 | } |
| 6962 | }, |
| 6963 | else => unreachable, |
| 6964 | } |
| 6965 | return index; |
| 6966 | } |
| 6967 | |
| 6940 | 6968 | fn airStructFieldPtr(cg: *CodeGen, inst: Air.Inst.Index) !?Id { |
| 6941 | 6969 | const ty_pl = cg.air.instructions.items(.data)[@backingInt(inst)].ty_pl; |
| 6942 | 6970 | const struct_field = cg.air.extraData(Air.StructField, ty_pl.payload).data; |