Skip to content

Conversation

gchatelet
Copy link
Contributor

@gchatelet gchatelet commented Aug 19, 2025

The previous version of the code would prevent the use of the compiler builtins.

The previous version of the code would prevent the use of the add with
carry compiler builtin.
@llvmbot llvmbot added the libc label Aug 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2025

@llvm/pr-subscribers-libc

Author: Guillaume Chatelet (gchatelet)

Changes

The previous version of the code would prevent the use of the add with
carry compiler builtin.


Full diff: https://github.com/llvm/llvm-project/pull/154282.diff

1 Files Affected:

  • (modified) libc/src/__support/math_extras.h (+2-2)
diff --git a/libc/src/__support/math_extras.h b/libc/src/__support/math_extras.h
index 47df2a43250c8..0a0a2a829e1bf 100644
--- a/libc/src/__support/math_extras.h
+++ b/libc/src/__support/math_extras.h
@@ -66,7 +66,7 @@ template <typename T>
 
 #define RETURN_IF(TYPE, BUILTIN)                                               \
   if constexpr (cpp::is_same_v<T, TYPE>)                                       \
-    return BUILTIN(a, b, carry_in, carry_out);
+    return BUILTIN(a, b, carry_in, &carry_out);
 
 // Returns the result of 'a + b' taking into account 'carry_in'.
 // The carry out is stored in 'carry_out' it not 'nullptr', dropped otherwise.
@@ -74,7 +74,7 @@ template <typename T>
 template <typename T>
 [[nodiscard]] LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T>
 add_with_carry(T a, T b, T carry_in, T &carry_out) {
-  if constexpr (!cpp::is_constant_evaluated()) {
+  if (!cpp::is_constant_evaluated()) {
 #if __has_builtin(__builtin_addcb)
     RETURN_IF(unsigned char, __builtin_addcb)
 #elif __has_builtin(__builtin_addcs)

@gchatelet gchatelet changed the title [libc] Fix add_with_carry constexpr [libc] Fix constexpr add_with_carry/sub_with_borrow Aug 19, 2025
@gchatelet gchatelet requested a review from lntue August 19, 2025 08:17
@gchatelet gchatelet merged commit 4dd9e99 into llvm:main Aug 20, 2025
19 checks passed
@gchatelet gchatelet deleted the fix_add_with_carry_constexp branch August 20, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants