From 3b28cc99776d2045ec055109af070890cf879c2f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Jul 2026 05:40:49 +0000 Subject: [PATCH] Clarify MSVC target-specific overflow paths --- src/util/mpz.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/mpz.cpp b/src/util/mpz.cpp index f26a0f98b4..56b48f145d 100644 --- a/src/util/mpz.cpp +++ b/src/util/mpz.cpp @@ -35,13 +35,13 @@ static bool mul_overflows(int64_t a, int64_t b, int64_t & result) { #elif defined(__GNUC__) return __builtin_mul_overflow(a, b, &result); #elif defined(_MSC_VER) && !defined(_M_ARM64) && !defined(_M_ARM64EC) - // MSVC _mul128 is available on the non-ARM64 targets that still use this path. + // MSVC exposes _mul128 on x64 targets, but not on ARM64/ARM64EC. __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) - // Unsigned negation preserves the magnitude of INT64_MIN without signed overflow. + // Unsigned negation preserves the magnitude of every negative int64_t, including INT64_MIN. uint64_t x = a < 0 ? -static_cast(a) : static_cast(a); uint64_t y = b < 0 ? -static_cast(b) : static_cast(b); bool is_neg = (a < 0) != (b < 0);