mirror of
https://github.com/Z3Prover/z3
synced 2026-07-15 11:35:42 +00:00
Fix Windows ARM64 overflow detection build
This commit is contained in:
parent
468a1cb658
commit
685ca67c64
1 changed files with 23 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue