[libc-commits] [libc] [libc] Clean up copt naming (PR #218230)

via libc-commits libc-commits at lists.llvm.org
Sun Aug 23 04:26:48 PDT 2026


https://github.com/Sukumarsawant created https://github.com/llvm/llvm-project/pull/218230

resolves #133505

(Draft/WIP)

>From 2e26b3797571b8663f3e8e135b9dd2745bc41b6b Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 23 Aug 2026 16:19:02 +0530
Subject: [PATCH 1/2] LIBC_QSORT_IMPL

---
 .../modules/LLVMLibCCompileOptionRules.cmake      |  2 +-
 libc/src/stdlib/qsort_util.h                      | 15 ++++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 99defb24d249a..6009c19741ae3 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -116,7 +116,7 @@ function(_get_compile_options_from_config output_var)
   endif()
 
   if(LIBC_CONF_QSORT_IMPL)
-    libc_add_definition(config_options "LIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
+    libc_add_definition(config_options "LIBC_COPT_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
   endif()
 
   libc_add_definition(config_options "LIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
diff --git a/libc/src/stdlib/qsort_util.h b/libc/src/stdlib/qsort_util.h
index 2f0438d624d14..3efb2c6b9939b 100644
--- a/libc/src/stdlib/qsort_util.h
+++ b/libc/src/stdlib/qsort_util.h
@@ -15,13 +15,13 @@
 #define LIBC_QSORT_QUICK_SORT 1
 #define LIBC_QSORT_HEAP_SORT 2
 
-#ifndef LIBC_QSORT_IMPL
-#define LIBC_QSORT_IMPL LIBC_QSORT_QUICK_SORT
-#endif // LIBC_QSORT_IMPL
+#ifndef LIBC_COPT_QSORT_IMPL
+#define LIBC_COPT_QSORT_IMPL LIBC_QSORT_QUICK_SORT
+#endif // LIBC_COPT_QSORT_IMPL
 
-#if (LIBC_QSORT_IMPL != LIBC_QSORT_QUICK_SORT &&                               \
-     LIBC_QSORT_IMPL != LIBC_QSORT_HEAP_SORT)
-#error "LIBC_QSORT_IMPL is not recognized."
+#if (LIBC_COPT_QSORT_IMPL != LIBC_QSORT_QUICK_SORT &&                          \
+     LIBC_COPT_QSORT_IMPL != LIBC_QSORT_HEAP_SORT)
+#error "LIBC_COPT_QSORT_IMPL is not recognized."
 #endif
 
 namespace LIBC_NAMESPACE_DECL {
@@ -66,7 +66,8 @@ LIBC_INLINE void unstable_sort_impl(void *array, size_t array_len,
 template <typename F>
 LIBC_INLINE void unstable_sort_dispatch(void *array, size_t array_len,
                                         size_t elem_size, F is_less) {
-  constexpr bool USE_QUICK_SORT = (LIBC_QSORT_IMPL == LIBC_QSORT_QUICK_SORT);
+  constexpr bool USE_QUICK_SORT =
+      (LIBC_COPT_QSORT_IMPL == LIBC_QSORT_QUICK_SORT);
   unstable_sort_impl<USE_QUICK_SORT>(array, array_len, elem_size, is_less);
 }
 

>From d8685a3e86f0b63d4089932ff7f1d99db11db0b7 Mon Sep 17 00:00:00 2001
From: Sukumarsawant <sawantsukumar at gmail.com>
Date: Sun, 23 Aug 2026 16:49:31 +0530
Subject: [PATCH 2/2] FREXP

---
 .../modules/LLVMLibCCompileOptionRules.cmake   |  2 +-
 .../__support/FPUtil/ManipulationFunctions.h   |  8 ++++----
 libc/test/src/math/smoke/FrexpTest.h           | 18 +++++++++---------
 3 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index 6009c19741ae3..e4df2b3a33600 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -139,7 +139,7 @@ function(_get_compile_options_from_config output_var)
   endif()
 
   if(NOT "${LIBC_CONF_FREXP_INF_NAN_EXPONENT}" STREQUAL "")
-    libc_add_definition(config_options "LIBC_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
+    libc_add_definition(config_options "LIBC_COPT_FREXP_INF_NAN_EXPONENT=${LIBC_CONF_FREXP_INF_NAN_EXPONENT}")
   endif()
 
   if(LIBC_CONF_MATH_OPTIMIZATIONS)
diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h
index 02dded2f47913..9f1369a073a1b 100644
--- a/libc/src/__support/FPUtil/ManipulationFunctions.h
+++ b/libc/src/__support/FPUtil/ManipulationFunctions.h
@@ -32,13 +32,13 @@ template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
 LIBC_INLINE constexpr T frexp(T x, int &exp) {
   FPBits<T> bits(x);
   if (bits.is_inf_or_nan()) {
-#ifdef LIBC_FREXP_INF_NAN_EXPONENT
+#ifdef LIBC_COPT_FREXP_INF_NAN_EXPONENT
     // The value written back to the second parameter when calling
     // frexp/frexpf/frexpl` with `+/-Inf`/`NaN` is unspecified in the standard.
     // Set the exp value for Inf/NaN inputs explicitly to
-    // LIBC_FREXP_INF_NAN_EXPONENT if it is defined.
-    exp = LIBC_FREXP_INF_NAN_EXPONENT;
-#endif // LIBC_FREXP_INF_NAN_EXPONENT
+    // LIBC_COPT_FREXP_INF_NAN_EXPONENT if it is defined.
+    exp = LIBC_COPT_FREXP_INF_NAN_EXPONENT;
+#endif // LIBC_COPT_FREXP_INF_NAN_EXPONENT
     return x;
   }
   if (bits.is_zero()) {
diff --git a/libc/test/src/math/smoke/FrexpTest.h b/libc/test/src/math/smoke/FrexpTest.h
index 3fb3a2e1688c8..72cadfc85f289 100644
--- a/libc/test/src/math/smoke/FrexpTest.h
+++ b/libc/test/src/math/smoke/FrexpTest.h
@@ -21,19 +21,19 @@ class FrexpTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
   void testSpecialNumbers(FrexpFunc func) {
     int exponent;
     EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN, &exponent));
-#ifdef LIBC_FREXP_INF_NAN_EXPONENT
-    EXPECT_EQ(LIBC_FREXP_INF_NAN_EXPONENT, exponent);
-#endif // LIBC_FREXP_INF_NAN_EXPONENT
+#ifdef LIBC_COPT_FREXP_INF_NAN_EXPONENT
+    EXPECT_EQ(LIBC_COPT_FREXP_INF_NAN_EXPONENT, exponent);
+#endif // LIBC_COPT_FREXP_INF_NAN_EXPONENT
 
     EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf, &exponent));
-#ifdef LIBC_FREXP_INF_NAN_EXPONENT
-    EXPECT_EQ(LIBC_FREXP_INF_NAN_EXPONENT, exponent);
-#endif // LIBC_FREXP_INF_NAN_EXPONENT
+#ifdef LIBC_COPT_FREXP_INF_NAN_EXPONENT
+    EXPECT_EQ(LIBC_COPT_FREXP_INF_NAN_EXPONENT, exponent);
+#endif // LIBC_COPT_FREXP_INF_NAN_EXPONENT
 
     EXPECT_FP_EQ_ALL_ROUNDING(neg_inf, func(neg_inf, &exponent));
-#ifdef LIBC_FREXP_INF_NAN_EXPONENT
-    EXPECT_EQ(LIBC_FREXP_INF_NAN_EXPONENT, exponent);
-#endif // LIBC_FREXP_INF_NAN_EXPONENT
+#ifdef LIBC_COPT_FREXP_INF_NAN_EXPONENT
+    EXPECT_EQ(LIBC_COPT_FREXP_INF_NAN_EXPONENT, exponent);
+#endif // LIBC_COPT_FREXP_INF_NAN_EXPONENT
 
     EXPECT_FP_EQ_ALL_ROUNDING(zero, func(zero, &exponent));
     EXPECT_EQ(exponent, 0);



More information about the libc-commits mailing list