Skip to content

Commit 4dd9e99

Browse files
authored
[libc] Fix constexpr add_with_carry/sub_with_borrow (#154282)
The previous version of the code would prevent the use of the compiler builtins.
1 parent 52a2e68 commit 4dd9e99

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/src/__support/math_extras.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ template <typename T>
6666

6767
#define RETURN_IF(TYPE, BUILTIN) \
6868
if constexpr (cpp::is_same_v<T, TYPE>) \
69-
return BUILTIN(a, b, carry_in, carry_out);
69+
return BUILTIN(a, b, carry_in, &carry_out);
7070

7171
// Returns the result of 'a + b' taking into account 'carry_in'.
7272
// The carry out is stored in 'carry_out' it not 'nullptr', dropped otherwise.
7373
// We keep the pass by pointer interface for consistency with the intrinsic.
7474
template <typename T>
7575
[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
7676
add_with_carry(T a, T b, T carry_in, T &carry_out) {
77-
if constexpr (!cpp::is_constant_evaluated()) {
77+
if (!cpp::is_constant_evaluated()) {
7878
#if __has_builtin(__builtin_addcb)
7979
RETURN_IF(unsigned char, __builtin_addcb)
8080
#elif __has_builtin(__builtin_addcs)
@@ -100,7 +100,7 @@ add_with_carry(T a, T b, T carry_in, T &carry_out) {
100100
template <typename T>
101101
[[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
102102
sub_with_borrow(T a, T b, T carry_in, T &carry_out) {
103-
if constexpr (!cpp::is_constant_evaluated()) {
103+
if (!cpp::is_constant_evaluated()) {
104104
#if __has_builtin(__builtin_subcb)
105105
RETURN_IF(unsigned char, __builtin_subcb)
106106
#elif __has_builtin(__builtin_subcs)

0 commit comments

Comments
 (0)