From 685ca67c64a1d75d6faef6aba2620d0a6bb25c7f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Jul 2026 05:12:57 +0000 Subject: [PATCH] Fix Windows ARM64 overflow detection build --- src/util/mpz.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index 2d3dd17640..f2e6f20604 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -31,12 +31,33 @@ static bool mul_overflows(int64_t a, int64_t b, int64_t & result) { return std::ckd_mul(&result, a, b); #elif defined(__GNUC__) return __builtin_mul_overflow(a, b, &result); -#elif defined(_MSC_VER) - // MSVC _mul128 intrinsic +#elif defined(_MSC_VER) && !defined(_M_ARM64) + // MSVC _mul128 intrinsic is unavailable when targeting ARM64. __int64 high; result = _mul128(a, b, &high); // Overflow if high bits are not the sign extension of result return high != (result >> 63); +#elif defined(_MSC_VER) + if (a > 0) { + if (b > 0) { + if (a > INT64_MAX / b) + return true; + } + else if (b < INT64_MIN / a) { + return true; + } + } + else if (a < 0) { + if (b > 0) { + if (a < INT64_MIN / b) + return true; + } + else if (b < 0 && b < INT64_MAX / a) { + return true; + } + } + result = a * b; + return false; #else static_assert(false); #endif