[libc-commits] [libc] [libc][cmake] Respect the configured optimization level for tests (PR #234363)
Prabhu Rajasekaran via libc-commits
libc-commits at lists.llvm.org
Wed Oct 21 13:57:59 PDT 2026
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/234363
>From 8968a68414d09e491a88f8e9322662245059d276 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 21 Oct 2026 13:43:34 -0700
Subject: [PATCH 1/2] [libc][cmake] Respect the configured optimization level
for math and stdfix tests
Follow up to #126322 and #233964: the math and stdfix tests still force ${libc_opt_high_flag}. Drop the overrides so the tests use the optimization level configured by CMake like the rest of the library.
---
libc/test/src/math/CMakeLists.txt | 6 ------
libc/test/src/math/exhaustive/CMakeLists.txt | 16 ----------------
libc/test/src/math/smoke/CMakeLists.txt | 8 --------
libc/test/src/stdfix/CMakeLists.txt | 16 ----------------
4 files changed, 46 deletions(-)
diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 764dd56d95b138..6dfe1cf5aeccaf 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -2029,8 +2029,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.sqrtf
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
@@ -2045,8 +2043,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.sqrt
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
@@ -2061,8 +2057,6 @@ add_fp_unittest(
DEPENDS
libc.src.math.sqrtl
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
diff --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
index bc5873bb31f92b..d31dd4e71f4be6 100644
--- a/libc/test/src/math/exhaustive/CMakeLists.txt
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -337,8 +337,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
fmabf16_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.math.fmabf16
@@ -420,8 +418,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
hypotbf16_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.math.hypotbf16
@@ -438,8 +434,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
hypotf_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.math.hypotf
@@ -456,8 +450,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
hypotf16_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.math.hypotf16
@@ -773,8 +765,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
bfloat16_add_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.__support.FPUtil.bfloat16
@@ -791,8 +781,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
bfloat16_div_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.__support.FPUtil.bfloat16
@@ -809,8 +797,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
bfloat16_mul_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.__support.FPUtil.bfloat16
@@ -827,8 +813,6 @@ add_fp_unittest(
libc_math_exhaustive_tests
SRCS
bfloat16_sub_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
.exhaustive_test
libc.src.__support.FPUtil.bfloat16
diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt
index ca299171fc6b8f..b0d37f169b6fa2 100644
--- a/libc/test/src/math/smoke/CMakeLists.txt
+++ b/libc/test/src/math/smoke/CMakeLists.txt
@@ -3699,8 +3699,6 @@ add_fp_unittest(
SqrtTest.h
DEPENDS
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
@@ -3713,8 +3711,6 @@ add_fp_unittest(
SqrtTest.h
DEPENDS
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
@@ -3727,8 +3723,6 @@ add_fp_unittest(
SqrtTest.h
DEPENDS
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
@@ -3745,8 +3739,6 @@ add_fp_unittest(
libc.src.math.sqrtf128
libc.src.__support.FPUtil.float128
libc.src.__support.FPUtil.generic.sqrt
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_fp_unittest(
diff --git a/libc/test/src/stdfix/CMakeLists.txt b/libc/test/src/stdfix/CMakeLists.txt
index f669c237481775..70b7cb519c9116 100644
--- a/libc/test/src/stdfix/CMakeLists.txt
+++ b/libc/test/src/stdfix/CMakeLists.txt
@@ -13,8 +13,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
AbsTest.h
SRCS
abs${suffix}_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.abs${suffix}
libc.src.__support.fixed_point.fx_bits
@@ -30,8 +28,6 @@ foreach(suffix IN ITEMS uhr ur ulr uhk uk)
SqrtTest.h
SRCS
sqrt${suffix}_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.sqrt${suffix}
libc.src.__support.CPP.bit
@@ -51,8 +47,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
RoundTest.h
SRCS
round${suffix}_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.round${suffix}
libc.src.__support.fixed_point.fx_bits
@@ -66,8 +60,6 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
FxBitsTest.h
SRCS
${suffix}bits_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.${suffix}bits
libc.src.__support.CPP.bit
@@ -172,8 +164,6 @@ add_libc_test(
ISqrtTest.h
SRCS
uhksqrtus_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.uhksqrtus
libc.src.__support.CPP.bit
@@ -191,8 +181,6 @@ add_libc_test(
ISqrtTest.h
SRCS
uksqrtui_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.uksqrtui
libc.src.__support.CPP.bit
@@ -210,8 +198,6 @@ add_libc_test(
ExpTest.h
SRCS
exphk_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.exphk
libc.src.math.exp
@@ -228,8 +214,6 @@ add_libc_test(
ExpTest.h
SRCS
expk_test.cpp
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
DEPENDS
libc.src.stdfix.expk
libc.src.math.exp
>From 3832b27aa4c577aeddf2bab149a1333d22846a65 Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 21 Oct 2026 13:57:46 -0700
Subject: [PATCH 2/2] [libc][cmake] Respect the configured optimization level
for hash_test and the MPFR wrappers
Same cleanup as the math and stdfix tests: drop the remaining optimization overrides on the test side so they use the optimization level configured by CMake.
---
libc/test/src/__support/CMakeLists.txt | 2 --
libc/utils/MPFRWrapper/CMakeLists.txt | 4 ++--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 765eec6b421780..0b5b559cf92995 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -286,8 +286,6 @@ add_libc_test(
libc.src.stdlib.rand
libc.src.stdlib.srand
libc.src.string.memset
- COMPILE_OPTIONS
- ${libc_opt_high_flag}
)
add_libc_test(
diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt
index 53ad5ef4aa48cd..ad5cbe5eabf713 100644
--- a/libc/utils/MPFRWrapper/CMakeLists.txt
+++ b/libc/utils/MPFRWrapper/CMakeLists.txt
@@ -7,7 +7,7 @@ if(LIBC_TESTS_CAN_USE_MPFR OR LIBC_TESTS_CAN_USE_MPC)
_get_common_test_compile_options(compile_options "" "")
# mpfr/gmp headers do not work with -ffreestanding flag.
list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPCommon PRIVATE -O3 ${compile_options})
+ target_compile_options(libcMPCommon PRIVATE ${compile_options})
add_dependencies(
libcMPCommon
libc.hdr.stdint_proxy
@@ -38,7 +38,7 @@ if(LIBC_TESTS_CAN_USE_MPFR)
_get_common_test_compile_options(compile_options "" "")
# mpfr/gmp headers do not work with -ffreestanding flag.
list(REMOVE_ITEM compile_options "-ffreestanding")
- target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
+ target_compile_options(libcMPFRWrapper PRIVATE ${compile_options})
add_dependencies(
libcMPFRWrapper
libcMPCommon
More information about the libc-commits
mailing list