Skip to content

Use NumPy macros for overflow detection #55977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions pandas/_libs/src/vendored/numpy/datetime/np_datetime.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,19 @@ This file is derived from NumPy 1.7. See NUMPY_LICENSE.txt
#else
#if defined __has_builtin
#if __has_builtin(__builtin_add_overflow)
#if _LP64 || __LP64__ || _ILP64 || __ILP64__
#define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res)
#else
#define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res)
#endif
#define checked_int64_add(a, b, res) __builtin_add_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_sub_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_mul_overflow(a, b, res)
#else
_Static_assert(0,
"Overflow checking not detected; please try a newer compiler");
#endif
// __has_builtin was added in gcc 10, but our muslinux_1_1 build environment
// only has gcc-9.3, so fall back to __GNUC__ macro as long as we have that
#elif __GNUC__ > 7
#if _LP64 || __LP64__ || _ILP64 || __ILP64__
#define checked_int64_add(a, b, res) __builtin_saddl_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_ssubl_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_smull_overflow(a, b, res)
#else
#define checked_int64_add(a, b, res) __builtin_saddll_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_ssubll_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_smulll_overflow(a, b, res)
#endif
#define checked_int64_add(a, b, res) __builtin_add_overflow(a, b, res)
#define checked_int64_sub(a, b, res) __builtin_sub_overflow(a, b, res)
#define checked_int64_mul(a, b, res) __builtin_mul_overflow(a, b, res)
#else
_Static_assert(0, "__has_builtin not detected; please try a newer compiler");
#endif
Expand Down