| ... | @@ -971,7 +971,6 @@ fn analyzeBodyInner( | ... | @@ -971,7 +971,6 @@ fn analyzeBodyInner( |
| 971 | .optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false), | 971 | .optional_payload_unsafe_ptr => try sema.zirOptionalPayloadPtr(block, inst, false), |
| 972 | .optional_type => try sema.zirOptionalType(block, inst), | 972 | .optional_type => try sema.zirOptionalType(block, inst), |
| 973 | .ptr_type => try sema.zirPtrType(block, inst), | 973 | .ptr_type => try sema.zirPtrType(block, inst), |
| 974 | .overflow_arithmetic_ptr => try sema.zirOverflowArithmeticPtr(block, inst), | | |
| 975 | .ref => try sema.zirRef(block, inst), | 974 | .ref => try sema.zirRef(block, inst), |
| 976 | .ret_err_value_code => try sema.zirRetErrValueCode(inst), | 975 | .ret_err_value_code => try sema.zirRetErrValueCode(inst), |
| 977 | .shr => try sema.zirShr(block, inst, .shr), | 976 | .shr => try sema.zirShr(block, inst, .shr), |
| ... | @@ -993,7 +992,6 @@ fn analyzeBodyInner( | ... | @@ -993,7 +992,6 @@ fn analyzeBodyInner( |
| 993 | .bit_size_of => try sema.zirBitSizeOf(block, inst), | 992 | .bit_size_of => try sema.zirBitSizeOf(block, inst), |
| 994 | .typeof => try sema.zirTypeof(block, inst), | 993 | .typeof => try sema.zirTypeof(block, inst), |
| 995 | .typeof_builtin => try sema.zirTypeofBuiltin(block, inst), | 994 | .typeof_builtin => try sema.zirTypeofBuiltin(block, inst), |
| 996 | .log2_int_type => try sema.zirLog2IntType(block, inst), | | |
| 997 | .typeof_log2_int_type => try sema.zirTypeofLog2IntType(block, inst), | 995 | .typeof_log2_int_type => try sema.zirTypeofLog2IntType(block, inst), |
| 998 | .xor => try sema.zirBitwise(block, inst, .xor), | 996 | .xor => try sema.zirBitwise(block, inst, .xor), |
| 999 | .struct_init_empty => try sema.zirStructInitEmpty(block, inst), | 997 | .struct_init_empty => try sema.zirStructInitEmpty(block, inst), |
| ... | @@ -11762,7 +11760,7 @@ fn zirShl( | ... | @@ -11762,7 +11760,7 @@ fn zirShl( |
| 11762 | if (scalar_ty.zigTypeTag() == .ComptimeInt) { | 11760 | if (scalar_ty.zigTypeTag() == .ComptimeInt) { |
| 11763 | break :val shifted.wrapped_result; | 11761 | break :val shifted.wrapped_result; |
| 11764 | } | 11762 | } |
| 11765 | if (shifted.overflowed.compareAllWithZero(.eq)) { | 11763 | if (shifted.overflow_bit.compareAllWithZero(.eq)) { |
| 11766 | break :val shifted.wrapped_result; | 11764 | break :val shifted.wrapped_result; |
| 11767 | } | 11765 | } |
| 11768 | return sema.fail(block, src, "operation caused overflow", .{}); | 11766 | return sema.fail(block, src, "operation caused overflow", .{}); |
| ... | @@ -13783,24 +13781,37 @@ fn zirOverflowArithmetic( | ... | @@ -13783,24 +13781,37 @@ fn zirOverflowArithmetic( |
| 13783 | const tracy = trace(@src()); | 13781 | const tracy = trace(@src()); |
| 13784 | defer tracy.end(); | 13782 | defer tracy.end(); |
| 13785 | | 13783 | |
| 13786 | const extra = sema.code.extraData(Zir.Inst.OverflowArithmetic, extended.operand).data; | 13784 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 13787 | const src = LazySrcLoc.nodeOffset(extra.node); | 13785 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 13788 | | 13786 | |
| 13789 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | 13787 | const lhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; |
| 13790 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | 13788 | const rhs_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; |
| 13791 | const ptr_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | | |
| 13792 | | 13789 | |
| 13793 | const lhs = try sema.resolveInst(extra.lhs); | 13790 | const uncasted_lhs = try sema.resolveInst(extra.lhs); |
| 13794 | const rhs = try sema.resolveInst(extra.rhs); | 13791 | const uncasted_rhs = try sema.resolveInst(extra.rhs); |
| 13795 | const ptr = try sema.resolveInst(extra.ptr); | | |
| 13796 | | 13792 | |
| 13797 | const lhs_ty = sema.typeOf(lhs); | 13793 | const lhs_ty = sema.typeOf(uncasted_lhs); |
| 13798 | const rhs_ty = sema.typeOf(rhs); | 13794 | const rhs_ty = sema.typeOf(uncasted_rhs); |
| 13799 | const mod = sema.mod; | 13795 | const mod = sema.mod; |
| 13800 | | 13796 | |
| 13801 | // Note, the types of lhs/rhs (also for shifting)/ptr are already correct as ensured by astgen. | | |
| 13802 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); | 13797 | try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src); |
| 13803 | const dest_ty = lhs_ty; | 13798 | |
| | 13799 | const instructions = &[_]Air.Inst.Ref{ uncasted_lhs, uncasted_rhs }; |
| | 13800 | const dest_ty = if (zir_tag == .shl_with_overflow) |
| | 13801 | lhs_ty |
| | 13802 | else |
| | 13803 | try sema.resolvePeerTypes(block, src, instructions, .{ |
| | 13804 | .override = &[_]LazySrcLoc{ lhs_src, rhs_src }, |
| | 13805 | }); |
| | 13806 | |
| | 13807 | const rhs_dest_ty = if (zir_tag == .shl_with_overflow) |
| | 13808 | try sema.log2IntType(block, lhs_ty, src) |
| | 13809 | else |
| | 13810 | dest_ty; |
| | 13811 | |
| | 13812 | const lhs = try sema.coerce(block, dest_ty, uncasted_lhs, lhs_src); |
| | 13813 | const rhs = try sema.coerce(block, rhs_dest_ty, uncasted_rhs, rhs_src); |
| | 13814 | |
| 13804 | if (dest_ty.scalarType().zigTypeTag() != .Int) { | 13815 | if (dest_ty.scalarType().zigTypeTag() != .Int) { |
| 13805 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)}); | 13816 | return sema.fail(block, src, "expected vector of integers or integer tag type, found '{}'", .{dest_ty.fmt(mod)}); |
| 13806 | } | 13817 | } |
| ... | @@ -13809,14 +13820,11 @@ fn zirOverflowArithmetic( | ... | @@ -13809,14 +13820,11 @@ fn zirOverflowArithmetic( |
| 13809 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); | 13820 | const maybe_rhs_val = try sema.resolveMaybeUndefVal(rhs); |
| 13810 | | 13821 | |
| 13811 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); | 13822 | const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty); |
| 13812 | // TODO: Remove and use `ov_ty` instead. | 13823 | |
| 13813 | // This is a temporary type used until overflow arithmetic properly returns `u1` instead of `bool`. | 13824 | var result: struct { |
| 13814 | const overflowed_ty = if (dest_ty.zigTypeTag() == .Vector) try Type.vector(sema.arena, dest_ty.vectorLen(), Type.bool) else Type.bool; | 13825 | inst: Air.Inst.Ref = .none, |
| 13815 | | 13826 | wrapped: Value = Value.initTag(.unreachable_value), |
| 13816 | const result: struct { | 13827 | overflow_bit: Value, |
| 13817 | /// TODO: Rename to `overflow_bit` and make of type `u1`. | | |
| 13818 | overflowed: Air.Inst.Ref, | | |
| 13819 | wrapped: Air.Inst.Ref, | | |
| 13820 | } = result: { | 13828 | } = result: { |
| 13821 | switch (zir_tag) { | 13829 | switch (zir_tag) { |
| 13822 | .add_with_overflow => { | 13830 | .add_with_overflow => { |
| ... | @@ -13825,24 +13833,22 @@ fn zirOverflowArithmetic( | ... | @@ -13825,24 +13833,22 @@ fn zirOverflowArithmetic( |
| 13825 | // Otherwise, if either of the argument is undefined, undefined is returned. | 13833 | // Otherwise, if either of the argument is undefined, undefined is returned. |
| 13826 | if (maybe_lhs_val) |lhs_val| { | 13834 | if (maybe_lhs_val) |lhs_val| { |
| 13827 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 13835 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13828 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 13836 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = rhs }; |
| 13829 | } | 13837 | } |
| 13830 | } | 13838 | } |
| 13831 | if (maybe_rhs_val) |rhs_val| { | 13839 | if (maybe_rhs_val) |rhs_val| { |
| 13832 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 13840 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13833 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13841 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13834 | } | 13842 | } |
| 13835 | } | 13843 | } |
| 13836 | if (maybe_lhs_val) |lhs_val| { | 13844 | if (maybe_lhs_val) |lhs_val| { |
| 13837 | if (maybe_rhs_val) |rhs_val| { | 13845 | if (maybe_rhs_val) |rhs_val| { |
| 13838 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 13846 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 13839 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 13847 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 13840 | } | 13848 | } |
| 13841 | | 13849 | |
| 13842 | const result = try sema.intAddWithOverflow(lhs_val, rhs_val, dest_ty); | 13850 | const result = try sema.intAddWithOverflow(lhs_val, rhs_val, dest_ty); |
| 13843 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13851 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; |
| 13844 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | | |
| 13845 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | | |
| 13846 | } | 13852 | } |
| 13847 | } | 13853 | } |
| 13848 | }, | 13854 | }, |
| ... | @@ -13851,18 +13857,16 @@ fn zirOverflowArithmetic( | ... | @@ -13851,18 +13857,16 @@ fn zirOverflowArithmetic( |
| 13851 | // Otherwise, if either result is undefined, both results are undefined. | 13857 | // Otherwise, if either result is undefined, both results are undefined. |
| 13852 | if (maybe_rhs_val) |rhs_val| { | 13858 | if (maybe_rhs_val) |rhs_val| { |
| 13853 | if (rhs_val.isUndef()) { | 13859 | if (rhs_val.isUndef()) { |
| 13854 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 13860 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 13855 | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13861 | } else if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13856 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13862 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13857 | } else if (maybe_lhs_val) |lhs_val| { | 13863 | } else if (maybe_lhs_val) |lhs_val| { |
| 13858 | if (lhs_val.isUndef()) { | 13864 | if (lhs_val.isUndef()) { |
| 13859 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 13865 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 13860 | } | 13866 | } |
| 13861 | | 13867 | |
| 13862 | const result = try sema.intSubWithOverflow(lhs_val, rhs_val, dest_ty); | 13868 | const result = try sema.intSubWithOverflow(lhs_val, rhs_val, dest_ty); |
| 13863 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13869 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; |
| 13864 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | | |
| 13865 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | | |
| 13866 | } | 13870 | } |
| 13867 | } | 13871 | } |
| 13868 | }, | 13872 | }, |
| ... | @@ -13873,9 +13877,9 @@ fn zirOverflowArithmetic( | ... | @@ -13873,9 +13877,9 @@ fn zirOverflowArithmetic( |
| 13873 | if (maybe_lhs_val) |lhs_val| { | 13877 | if (maybe_lhs_val) |lhs_val| { |
| 13874 | if (!lhs_val.isUndef()) { | 13878 | if (!lhs_val.isUndef()) { |
| 13875 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13879 | if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13876 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13880 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13877 | } else if (try sema.compareAll(lhs_val, .eq, Value.one, dest_ty)) { | 13881 | } else if (try sema.compareAll(lhs_val, .eq, try maybeRepeated(sema, dest_ty, Value.one), dest_ty)) { |
| 13878 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 13882 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = rhs }; |
| 13879 | } | 13883 | } |
| 13880 | } | 13884 | } |
| 13881 | } | 13885 | } |
| ... | @@ -13883,9 +13887,9 @@ fn zirOverflowArithmetic( | ... | @@ -13883,9 +13887,9 @@ fn zirOverflowArithmetic( |
| 13883 | if (maybe_rhs_val) |rhs_val| { | 13887 | if (maybe_rhs_val) |rhs_val| { |
| 13884 | if (!rhs_val.isUndef()) { | 13888 | if (!rhs_val.isUndef()) { |
| 13885 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { | 13889 | if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) { |
| 13886 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = rhs }; | 13890 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = rhs }; |
| 13887 | } else if (try sema.compareAll(rhs_val, .eq, Value.one, dest_ty)) { | 13891 | } else if (try sema.compareAll(rhs_val, .eq, try maybeRepeated(sema, dest_ty, Value.one), dest_ty)) { |
| 13888 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13892 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13889 | } | 13893 | } |
| 13890 | } | 13894 | } |
| 13891 | } | 13895 | } |
| ... | @@ -13893,13 +13897,11 @@ fn zirOverflowArithmetic( | ... | @@ -13893,13 +13897,11 @@ fn zirOverflowArithmetic( |
| 13893 | if (maybe_lhs_val) |lhs_val| { | 13897 | if (maybe_lhs_val) |lhs_val| { |
| 13894 | if (maybe_rhs_val) |rhs_val| { | 13898 | if (maybe_rhs_val) |rhs_val| { |
| 13895 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 13899 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 13896 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 13900 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 13897 | } | 13901 | } |
| 13898 | | 13902 | |
| 13899 | const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, mod); | 13903 | const result = try lhs_val.intMulWithOverflow(rhs_val, dest_ty, sema.arena, mod); |
| 13900 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13904 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; |
| 13901 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | | |
| 13902 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | | |
| 13903 | } | 13905 | } |
| 13904 | } | 13906 | } |
| 13905 | }, | 13907 | }, |
| ... | @@ -13909,24 +13911,22 @@ fn zirOverflowArithmetic( | ... | @@ -13909,24 +13911,22 @@ fn zirOverflowArithmetic( |
| 13909 | // Oterhwise if either of the arguments is undefined, both results are undefined. | 13911 | // Oterhwise if either of the arguments is undefined, both results are undefined. |
| 13910 | if (maybe_lhs_val) |lhs_val| { | 13912 | if (maybe_lhs_val) |lhs_val| { |
| 13911 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 13913 | if (!lhs_val.isUndef() and (try lhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13912 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13914 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13913 | } | 13915 | } |
| 13914 | } | 13916 | } |
| 13915 | if (maybe_rhs_val) |rhs_val| { | 13917 | if (maybe_rhs_val) |rhs_val| { |
| 13916 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { | 13918 | if (!rhs_val.isUndef() and (try rhs_val.compareAllWithZeroAdvanced(.eq, sema))) { |
| 13917 | break :result .{ .overflowed = try sema.addBool(overflowed_ty, false), .wrapped = lhs }; | 13919 | break :result .{ .overflow_bit = try maybeRepeated(sema, dest_ty, Value.zero), .inst = lhs }; |
| 13918 | } | 13920 | } |
| 13919 | } | 13921 | } |
| 13920 | if (maybe_lhs_val) |lhs_val| { | 13922 | if (maybe_lhs_val) |lhs_val| { |
| 13921 | if (maybe_rhs_val) |rhs_val| { | 13923 | if (maybe_rhs_val) |rhs_val| { |
| 13922 | if (lhs_val.isUndef() or rhs_val.isUndef()) { | 13924 | if (lhs_val.isUndef() or rhs_val.isUndef()) { |
| 13923 | break :result .{ .overflowed = try sema.addConstUndef(overflowed_ty), .wrapped = try sema.addConstUndef(dest_ty) }; | 13925 | break :result .{ .overflow_bit = Value.undef, .wrapped = Value.undef }; |
| 13924 | } | 13926 | } |
| 13925 | | 13927 | |
| 13926 | const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod); | 13928 | const result = try lhs_val.shlWithOverflow(rhs_val, dest_ty, sema.arena, sema.mod); |
| 13927 | const overflowed = try sema.addConstant(overflowed_ty, result.overflowed); | 13929 | break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result }; |
| 13928 | const wrapped = try sema.addConstant(dest_ty, result.wrapped_result); | | |
| 13929 | break :result .{ .overflowed = overflowed, .wrapped = wrapped }; | | |
| 13930 | } | 13930 | } |
| 13931 | } | 13931 | } |
| 13932 | }, | 13932 | }, |
| ... | @@ -13944,7 +13944,7 @@ fn zirOverflowArithmetic( | ... | @@ -13944,7 +13944,7 @@ fn zirOverflowArithmetic( |
| 13944 | const runtime_src = if (maybe_lhs_val == null) lhs_src else rhs_src; | 13944 | const runtime_src = if (maybe_lhs_val == null) lhs_src else rhs_src; |
| 13945 | try sema.requireRuntimeBlock(block, src, runtime_src); | 13945 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| 13946 | | 13946 | |
| 13947 | const tuple = try block.addInst(.{ | 13947 | return block.addInst(.{ |
| 13948 | .tag = air_tag, | 13948 | .tag = air_tag, |
| 13949 | .data = .{ .ty_pl = .{ | 13949 | .data = .{ .ty_pl = .{ |
| 13950 | .ty = try block.sema.addType(tuple_ty), | 13950 | .ty = try block.sema.addType(tuple_ty), |
| ... | @@ -13954,16 +13954,32 @@ fn zirOverflowArithmetic( | ... | @@ -13954,16 +13954,32 @@ fn zirOverflowArithmetic( |
| 13954 | }), | 13954 | }), |
| 13955 | } }, | 13955 | } }, |
| 13956 | }); | 13956 | }); |
| | 13957 | }; |
| 13957 | | 13958 | |
| 13958 | const wrapped = try sema.tupleFieldValByIndex(block, src, tuple, 0, tuple_ty); | 13959 | if (result.inst != .none) { |
| 13959 | try sema.storePtr2(block, src, ptr, ptr_src, wrapped, src, .store); | 13960 | if (try sema.resolveMaybeUndefVal(result.inst)) |some| { |
| | 13961 | result.wrapped = some; |
| | 13962 | result.inst = .none; |
| | 13963 | } |
| | 13964 | } |
| 13960 | | 13965 | |
| 13961 | const overflow_bit = try sema.tupleFieldValByIndex(block, src, tuple, 1, tuple_ty); | 13966 | if (result.inst == .none) { |
| 13962 | return block.addBitCast(overflowed_ty, overflow_bit); | 13967 | const values = try sema.arena.alloc(Value, 2); |
| 13963 | }; | 13968 | values[0] = result.wrapped; |
| | 13969 | values[1] = result.overflow_bit; |
| | 13970 | const tuple_val = try Value.Tag.aggregate.create(sema.arena, values); |
| | 13971 | return sema.addConstant(tuple_ty, tuple_val); |
| | 13972 | } |
| | 13973 | |
| | 13974 | const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2); |
| | 13975 | element_refs[0] = result.inst; |
| | 13976 | element_refs[1] = try sema.addConstant(tuple_ty.structFieldType(1), result.overflow_bit); |
| | 13977 | return block.addAggregateInit(tuple_ty, element_refs); |
| | 13978 | } |
| 13964 | | 13979 | |
| 13965 | try sema.storePtr2(block, src, ptr, ptr_src, result.wrapped, src, .store); | 13980 | fn maybeRepeated(sema: *Sema, ty: Type, val: Value) !Value { |
| 13966 | return result.overflowed; | 13981 | if (ty.zigTypeTag() != .Vector) return val; |
| | 13982 | return Value.Tag.repeated.create(sema.arena, val); |
| 13967 | } | 13983 | } |
| 13968 | | 13984 | |
| 13969 | fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type { | 13985 | fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type { |
| ... | @@ -16211,14 +16227,6 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -16211,14 +16227,6 @@ fn zirTypeofLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 16211 | return sema.addType(res_ty); | 16227 | return sema.addType(res_ty); |
| 16212 | } | 16228 | } |
| 16213 | | 16229 | |
| 16214 | fn zirLog2IntType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | | |
| 16215 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | | |
| 16216 | const src = inst_data.src(); | | |
| 16217 | const operand = try sema.resolveType(block, src, inst_data.operand); | | |
| 16218 | const res_ty = try sema.log2IntType(block, operand, src); | | |
| 16219 | return sema.addType(res_ty); | | |
| 16220 | } | | |
| 16221 | | | |
| 16222 | fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type { | 16230 | fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) CompileError!Type { |
| 16223 | switch (operand.zigTypeTag()) { | 16231 | switch (operand.zigTypeTag()) { |
| 16224 | .ComptimeInt => return Type.comptime_int, | 16232 | .ComptimeInt => return Type.comptime_int, |
| ... | @@ -17039,24 +17047,6 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool { | ... | @@ -17039,24 +17047,6 @@ fn floatOpAllowed(tag: Zir.Inst.Tag) bool { |
| 17039 | }; | 17047 | }; |
| 17040 | } | 17048 | } |
| 17041 | | 17049 | |
| 17042 | fn zirOverflowArithmeticPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | | |
| 17043 | const tracy = trace(@src()); | | |
| 17044 | defer tracy.end(); | | |
| 17045 | | | |
| 17046 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | | |
| 17047 | const elem_ty_src = inst_data.src(); | | |
| 17048 | const elem_type = try sema.resolveType(block, elem_ty_src, inst_data.operand); | | |
| 17049 | const ty = try Type.ptr(sema.arena, sema.mod, .{ | | |
| 17050 | .pointee_type = elem_type, | | |
| 17051 | .@"addrspace" = .generic, | | |
| 17052 | .mutable = true, | | |
| 17053 | .@"allowzero" = false, | | |
| 17054 | .@"volatile" = false, | | |
| 17055 | .size = .One, | | |
| 17056 | }); | | |
| 17057 | return sema.addType(ty); | | |
| 17058 | } | | |
| 17059 | | | |
| 17060 | fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | 17050 | fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 17061 | const tracy = trace(@src()); | 17051 | const tracy = trace(@src()); |
| 17062 | defer tracy.end(); | 17052 | defer tracy.end(); |
| ... | @@ -32613,11 +32603,11 @@ fn intSubWithOverflow( | ... | @@ -32613,11 +32603,11 @@ fn intSubWithOverflow( |
| 32613 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32603 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| 32614 | const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf); | 32604 | const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf); |
| 32615 | const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType()); | 32605 | const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType()); |
| 32616 | overflowed_data[i] = of_math_result.overflowed; | 32606 | overflowed_data[i] = of_math_result.overflow_bit; |
| 32617 | scalar.* = of_math_result.wrapped_result; | 32607 | scalar.* = of_math_result.wrapped_result; |
| 32618 | } | 32608 | } |
| 32619 | return Value.OverflowArithmeticResult{ | 32609 | return Value.OverflowArithmeticResult{ |
| 32620 | .overflowed = try Value.Tag.aggregate.create(sema.arena, overflowed_data), | 32610 | .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data), |
| 32621 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), | 32611 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 32622 | }; | 32612 | }; |
| 32623 | } | 32613 | } |
| ... | @@ -32645,7 +32635,7 @@ fn intSubWithOverflowScalar( | ... | @@ -32645,7 +32635,7 @@ fn intSubWithOverflowScalar( |
| 32645 | const overflowed = result_bigint.subWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits); | 32635 | const overflowed = result_bigint.subWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits); |
| 32646 | const wrapped_result = try Value.fromBigInt(sema.arena, result_bigint.toConst()); | 32636 | const wrapped_result = try Value.fromBigInt(sema.arena, result_bigint.toConst()); |
| 32647 | return Value.OverflowArithmeticResult{ | 32637 | return Value.OverflowArithmeticResult{ |
| 32648 | .overflowed = Value.makeBool(overflowed), | 32638 | .overflow_bit = Value.boolToInt(overflowed), |
| 32649 | .wrapped_result = wrapped_result, | 32639 | .wrapped_result = wrapped_result, |
| 32650 | }; | 32640 | }; |
| 32651 | } | 32641 | } |
| ... | @@ -32964,11 +32954,11 @@ fn intAddWithOverflow( | ... | @@ -32964,11 +32954,11 @@ fn intAddWithOverflow( |
| 32964 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); | 32954 | const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf); |
| 32965 | const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf); | 32955 | const rhs_elem = rhs.elemValueBuffer(sema.mod, i, &rhs_buf); |
| 32966 | const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType()); | 32956 | const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType()); |
| 32967 | overflowed_data[i] = of_math_result.overflowed; | 32957 | overflowed_data[i] = of_math_result.overflow_bit; |
| 32968 | scalar.* = of_math_result.wrapped_result; | 32958 | scalar.* = of_math_result.wrapped_result; |
| 32969 | } | 32959 | } |
| 32970 | return Value.OverflowArithmeticResult{ | 32960 | return Value.OverflowArithmeticResult{ |
| 32971 | .overflowed = try Value.Tag.aggregate.create(sema.arena, overflowed_data), | 32961 | .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data), |
| 32972 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), | 32962 | .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data), |
| 32973 | }; | 32963 | }; |
| 32974 | } | 32964 | } |
| ... | @@ -32996,7 +32986,7 @@ fn intAddWithOverflowScalar( | ... | @@ -32996,7 +32986,7 @@ fn intAddWithOverflowScalar( |
| 32996 | const overflowed = result_bigint.addWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits); | 32986 | const overflowed = result_bigint.addWrap(lhs_bigint, rhs_bigint, info.signedness, info.bits); |
| 32997 | const result = try Value.fromBigInt(sema.arena, result_bigint.toConst()); | 32987 | const result = try Value.fromBigInt(sema.arena, result_bigint.toConst()); |
| 32998 | return Value.OverflowArithmeticResult{ | 32988 | return Value.OverflowArithmeticResult{ |
| 32999 | .overflowed = Value.makeBool(overflowed), | 32989 | .overflow_bit = Value.boolToInt(overflowed), |
| 33000 | .wrapped_result = result, | 32990 | .wrapped_result = result, |
| 33001 | }; | 32991 | }; |
| 33002 | } | 32992 | } |