Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Don't use __builtin_mul_overflow
  • Loading branch information
ambv committed Jan 23, 2025
commit 3a87da45a4fb2adc4bfa2f3f66634341e84ed524
15 changes: 6 additions & 9 deletions Modules/_testexternalinspection.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,13 @@ read_py_long(pid_t pid, _Py_DebugOffsets* offsets, uintptr_t address)

long value = 0;

// In theory this can overflow, but because of llvm/llvm-project#16778
// we can't use __builtin_mul_overflow because it fails to link with
// __muloti4 on aarch64. In practice this is fine because all we're
// testing here are task numbers that would fit in a single byte.
for (ssize_t i = 0; i < size; ++i) {
long long factor;
if (__builtin_mul_overflow(digits[i], (1UL << (ssize_t)(shift * i)),
&factor)
) {
goto error;
}
if (__builtin_add_overflow(value, factor, &value)) {
goto error;
}
long long factor = digits[i] * (1UL << (ssize_t)(shift * i));
value += factor;
}
PyMem_RawFree(digits);
if (negative) {
Expand Down