| ... | ... | @@ -957,11 +957,11 @@ pub const DeclGen = struct { |
| 957 | 957 | |
| 958 | 958 | switch (ty.zigTypeTag()) { |
| 959 | 959 | .Int => { |
| 960 | | const int_bits = if (ty.isSignedInt()) |
| 961 | | @bitCast(u64, val.toSignedInt(target)) |
| 962 | | else |
| 963 | | val.toUnsignedInt(target); |
| 964 | | try self.genConstInt(result_ty_ref, result_id, int_bits); |
| 960 | if (ty.isSignedInt()) { |
| 961 | try self.genConstInt(result_ty_ref, result_id, val.toSignedInt(target)); |
| 962 | } else { |
| 963 | try self.genConstInt(result_ty_ref, result_id, val.toUnsignedInt(target)); |
| 964 | } |
| 965 | 965 | }, |
| 966 | 966 | .Bool => { |
| 967 | 967 | const operands = .{ .id_result_type = result_ty_id, .id_result = result_id }; |
| ... | ... | @@ -1717,6 +1717,8 @@ pub const DeclGen = struct { |
| 1717 | 1717 | .is_null => try self.airIsNull(inst, .is_null), |
| 1718 | 1718 | .is_non_null => try self.airIsNull(inst, .is_non_null), |
| 1719 | 1719 | |
| 1720 | .optional_payload => try self.airUnwrapOptional(inst), |
| 1721 | |
| 1720 | 1722 | .assembly => try self.airAssembly(inst), |
| 1721 | 1723 | |
| 1722 | 1724 | .call => try self.airCall(inst, .auto), |
| ... | ... | @@ -2694,6 +2696,23 @@ pub const DeclGen = struct { |
| 2694 | 2696 | }; |
| 2695 | 2697 | } |
| 2696 | 2698 | |
| 2699 | fn airUnwrapOptional(self: *DeclGen, inst: Air.Inst.Index) !?IdRef { |
| 2700 | if (self.liveness.isUnused(inst)) return null; |
| 2701 | |
| 2702 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 2703 | const operand_id = try self.resolve(ty_op.operand); |
| 2704 | const optional_ty = self.air.typeOf(ty_op.operand); |
| 2705 | const payload_ty = self.air.typeOfIndex(inst); |
| 2706 | |
| 2707 | if (!payload_ty.hasRuntimeBitsIgnoreComptime()) return null; |
| 2708 | |
| 2709 | if (optional_ty.optionalReprIsPayload()) { |
| 2710 | return operand_id; |
| 2711 | } |
| 2712 | |
| 2713 | return try self.extractField(payload_ty, operand_id, 0); |
| 2714 | } |
| 2715 | |
| 2697 | 2716 | fn airSwitchBr(self: *DeclGen, inst: Air.Inst.Index) !void { |
| 2698 | 2717 | const target = self.getTarget(); |
| 2699 | 2718 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |