Skip to content

Commit 6dbe542

Browse files
authored
[libc] Use ${libc_opt_high_flag} instead of -O3 (#123233)
This is preferable since `${libc_opt_high_flag}` will be set correctly for the compiler used.
1 parent 427b24a commit 6dbe542

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ function(create_libc_unittest fq_target_name)
223223

224224
_get_common_test_compile_options(compile_options "${LIBC_UNITTEST_C_TEST}"
225225
"${LIBC_UNITTEST_FLAGS}")
226+
# TODO: Ideally we would have a separate function for link options.
227+
set(link_options ${compile_options})
226228
list(APPEND compile_options ${LIBC_UNITTEST_COMPILE_OPTIONS})
227229

228230
if(SHOW_INTERMEDIATE_OBJECTS)
@@ -277,7 +279,7 @@ function(create_libc_unittest fq_target_name)
277279
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
278280
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
279281
target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
280-
target_link_options(${fq_build_target_name} PRIVATE ${compile_options})
282+
target_link_options(${fq_build_target_name} PRIVATE ${link_options})
281283

282284
if(NOT LIBC_UNITTEST_CXX_STANDARD)
283285
set(LIBC_UNITTEST_CXX_STANDARD ${CMAKE_CXX_STANDARD})

libc/src/math/generic/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ add_entrypoint_object(
534534
libc.src.__support.macros.optimization
535535
libc.src.__support.macros.properties.types
536536
COMPILE_OPTIONS
537-
-O3
537+
${libc_opt_high_flag}
538538
)
539539

540540
add_entrypoint_object(

libc/test/src/__support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ add_libc_test(
234234
libc.src.stdlib.srand
235235
libc.src.string.memset
236236
COMPILE_OPTIONS
237-
-O3
237+
${libc_opt_high_flag}
238238
UNIT_TEST_ONLY
239239
# Aligned Allocation is not supported in hermetic builds.
240240
)

libc/test/src/math/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ add_fp_unittest(
15971597
libc.src.math.sqrtf
15981598
libc.src.__support.FPUtil.generic.sqrt
15991599
COMPILE_OPTIONS
1600-
-O3
1600+
${libc_opt_high_flag}
16011601
)
16021602

16031603
add_fp_unittest(
@@ -1613,7 +1613,7 @@ add_fp_unittest(
16131613
libc.src.math.sqrt
16141614
libc.src.__support.FPUtil.generic.sqrt
16151615
COMPILE_OPTIONS
1616-
-O3
1616+
${libc_opt_high_flag}
16171617
)
16181618

16191619
add_fp_unittest(
@@ -1629,7 +1629,7 @@ add_fp_unittest(
16291629
libc.src.math.sqrtl
16301630
libc.src.__support.FPUtil.generic.sqrt
16311631
COMPILE_OPTIONS
1632-
-O3
1632+
${libc_opt_high_flag}
16331633
)
16341634

16351635
add_fp_unittest(

libc/test/src/math/exhaustive/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ add_fp_unittest(
305305
SRCS
306306
hypotf_test.cpp
307307
COMPILE_OPTIONS
308-
-O3
308+
${libc_opt_high_flag}
309309
DEPENDS
310310
.exhaustive_test
311311
libc.src.math.hypotf

libc/test/src/math/smoke/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ add_fp_unittest(
29932993
DEPENDS
29942994
libc.src.__support.FPUtil.generic.sqrt
29952995
COMPILE_OPTIONS
2996-
-O3
2996+
${libc_opt_high_flag}
29972997
)
29982998

29992999
add_fp_unittest(
@@ -3007,7 +3007,7 @@ add_fp_unittest(
30073007
DEPENDS
30083008
libc.src.__support.FPUtil.generic.sqrt
30093009
COMPILE_OPTIONS
3010-
-O3
3010+
${libc_opt_high_flag}
30113011
)
30123012

30133013
add_fp_unittest(
@@ -3021,7 +3021,7 @@ add_fp_unittest(
30213021
DEPENDS
30223022
libc.src.__support.FPUtil.generic.sqrt
30233023
COMPILE_OPTIONS
3024-
-O3
3024+
${libc_opt_high_flag}
30253025
)
30263026

30273027
add_fp_unittest(
@@ -3038,7 +3038,7 @@ add_fp_unittest(
30383038
libc.src.math.sqrtf128
30393039
libc.src.__support.FPUtil.generic.sqrt
30403040
COMPILE_OPTIONS
3041-
-O3
3041+
${libc_opt_high_flag}
30423042
)
30433043

30443044
add_fp_unittest(

libc/test/src/stdfix/CMakeLists.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk)
1414
SRCS
1515
abs${suffix}_test.cpp
1616
COMPILE_OPTIONS
17-
-O3
17+
${libc_opt_high_flag}
1818
DEPENDS
1919
libc.src.stdfix.abs${suffix}
2020
libc.src.__support.fixed_point.fx_bits
@@ -31,7 +31,7 @@ foreach(suffix IN ITEMS uhr ur ulr uhk uk)
3131
SRCS
3232
sqrt${suffix}_test.cpp
3333
COMPILE_OPTIONS
34-
-O3
34+
${libc_opt_high_flag}
3535
DEPENDS
3636
libc.src.stdfix.sqrt${suffix}
3737
libc.src.__support.CPP.bit
@@ -52,7 +52,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
5252
SRCS
5353
round${suffix}_test.cpp
5454
COMPILE_OPTIONS
55-
-O3
55+
${libc_opt_high_flag}
5656
DEPENDS
5757
libc.src.stdfix.round${suffix}
5858
libc.src.__support.fixed_point.fx_bits
@@ -67,7 +67,7 @@ foreach(suffix IN ITEMS hr r lr hk k lk uhr ur ulr uhk uk ulk)
6767
SRCS
6868
${suffix}bits_test.cpp
6969
COMPILE_OPTIONS
70-
-O3
70+
${libc_opt_high_flag}
7171
DEPENDS
7272
libc.src.stdfix.${suffix}bits
7373
libc.src.__support.CPP.bit
@@ -84,7 +84,7 @@ add_libc_test(
8484
SRCS
8585
uhksqrtus_test.cpp
8686
COMPILE_OPTIONS
87-
-O3
87+
${libc_opt_high_flag}
8888
DEPENDS
8989
libc.src.stdfix.uhksqrtus
9090
libc.src.__support.CPP.bit
@@ -103,7 +103,7 @@ add_libc_test(
103103
SRCS
104104
uksqrtui_test.cpp
105105
COMPILE_OPTIONS
106-
-O3
106+
${libc_opt_high_flag}
107107
DEPENDS
108108
libc.src.stdfix.uksqrtui
109109
libc.src.__support.CPP.bit
@@ -122,7 +122,7 @@ add_libc_test(
122122
SRCS
123123
exphk_test.cpp
124124
COMPILE_OPTIONS
125-
-O3
125+
${libc_opt_high_flag}
126126
DEPENDS
127127
libc.src.stdfix.exphk
128128
libc.src.math.exp
@@ -140,7 +140,7 @@ add_libc_test(
140140
SRCS
141141
expk_test.cpp
142142
COMPILE_OPTIONS
143-
-O3
143+
${libc_opt_high_flag}
144144
DEPENDS
145145
libc.src.stdfix.expk
146146
libc.src.math.exp

libc/utils/MPFRWrapper/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if(LIBC_TESTS_CAN_USE_MPFR)
3434
_get_common_test_compile_options(compile_options "" "")
3535
# mpfr/gmp headers do not work with -ffreestanding flag.
3636
list(REMOVE_ITEM compile_options "-ffreestanding")
37-
target_compile_options(libcMPFRWrapper PRIVATE -O3 ${compile_options})
37+
target_compile_options(libcMPFRWrapper PRIVATE ${libc_opt_high_flag} ${compile_options})
3838
add_dependencies(
3939
libcMPFRWrapper
4040
libcMPCommon

0 commit comments

Comments
 (0)