Skip to content

Commit 543932f

Browse files
authored
[libc] Make LIBC_MATH_NO_ERRNO imply -fno-math-errno (#125794)
This partially reverts #124200. Rather than using a CMake option to control whether to enable `-fno-math-errno`, use LIBC_MATH_NO_ERRNO configuration option. While there might be other cases when we want to set `-fno-math-errno`, having LIBC_MATH_NO_ERRNO imply it should be always safe and represents a reasonable starting point.
1 parent 467487f commit 543932f

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ function(_get_compile_options_from_flags output_var)
2626
list(APPEND compile_options "-mavx2")
2727
list(APPEND compile_options "-mfma")
2828
endif()
29-
# For clang, we will build the math functions with `-fno-math-errno` so that
30-
# __builtin_fma* will generate the fused-mutliply-add instructions. We
31-
# don't put the control flag to the public config yet, and see if it makes
32-
# sense to just enable this flag by default.
33-
if(LIBC_ADD_FNO_MATH_ERRNO)
34-
list(APPEND compile_options "-fno-math-errno")
35-
endif()
3629
endif()
3730
if(ADD_ROUND_OPT_FLAG)
3831
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
@@ -102,6 +95,9 @@ function(_get_compile_options_from_config output_var)
10295

10396
if(LIBC_CONF_MATH_OPTIMIZATIONS)
10497
list(APPEND config_options "-DLIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
98+
if(LIBC_CONF_MATH_OPTIMIZATIONS MATCHES "LIBC_MATH_NO_ERRNO")
99+
list(APPEND config_options "-fno-math-errno")
100+
endif()
105101
endif()
106102

107103
if(LIBC_CONF_ERRNO_MODE)

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ function(_get_common_test_compile_options output_var c_test flags)
33
_get_compile_options_from_config(config_flags)
44
_get_compile_options_from_arch(arch_flags)
55

6-
# Remove -fno-math-errno if it was added.
7-
if(LIBC_ADD_FNO_MATH_ERRNO)
8-
list(REMOVE_ITEM compile_flags "-fno-math-errno")
9-
endif()
10-
116
# Death test executor is only available in Linux for now.
127
if(NOT ${LIBC_TARGET_OS} STREQUAL "linux")
138
list(REMOVE_ITEM config_flags "-DLIBC_ADD_NULL_CHECKS")

libc/config/baremetal/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"math": {
3838
"LIBC_CONF_MATH_OPTIMIZATIONS": {
39-
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)"
39+
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO)"
4040
}
4141
},
4242
"general": {

0 commit comments

Comments
 (0)