[libc-commits] [libc] [libc] Fix BigInt's operator %= (PR #98484)
via libc-commits
libc-commits at lists.llvm.org
Thu Jul 11 07:00:13 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Mikhail R. Gadelha (mikhailramalho)
<details>
<summary>Changes</summary>
This patch fixes cases where we try to do var %= 1. Previously this operator was calling .div directly since it would perform the inplace division and return the remainder, however, as an early exit condition a division by one returns zero as the remainder. The remainder being returned by div was not being assigned to var.
---
Full diff: https://github.com/llvm/llvm-project/pull/98484.diff
1 Files Affected:
- (modified) libc/src/__support/big_int.h (+2-1)
``````````diff
diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h
index 82a5251418854..8eeb4db9d650b 100644
--- a/libc/src/__support/big_int.h
+++ b/libc/src/__support/big_int.h
@@ -732,7 +732,8 @@ struct BigInt {
}
LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
- return *this->div(other);
+ *this = *this % other;
+ return *this;
}
LIBC_INLINE constexpr BigInt &operator*=(const BigInt &other) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/98484
More information about the libc-commits
mailing list