Skip to content

Commit 6d9dac2

Browse files
committed
[libc] Make LIBC_MATH_NO_ERRNO imply -fno-math-errno
This partially reverts llvm#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 53d6e59 commit 6d9dac2

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
@@ -28,13 +28,6 @@ function(_get_compile_options_from_flags output_var)
2828
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
2929
list(APPEND compile_options "-D__LIBC_RISCV_USE_FMA")
3030
endif()
31-
# For clang, we will build the math functions with `-fno-math-errno` so that
32-
# __builtin_fma* will generate the fused-mutliply-add instructions. We
33-
# don't put the control flag to the public config yet, and see if it makes
34-
# sense to just enable this flag by default.
35-
if(LIBC_ADD_FNO_MATH_ERRNO)
36-
list(APPEND compile_options "-fno-math-errno")
37-
endif()
3831
endif()
3932
if(ADD_ROUND_OPT_FLAG)
4033
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
@@ -71,6 +64,9 @@ function(_get_compile_options_from_flags output_var)
7164
"SHELL:-Xclang -target-feature -Xclang +fullfp16")
7265
endif()
7366
endif()
67+
if(LIBC_CONF_MATH_OPTIMIZATIONS MATCHES "LIBC_MATH_NO_ERRNO")
68+
list(APPEND compile_options "-fno-math-errno")
69+
endif()
7470
elseif(MSVC)
7571
if(ADD_FMA_FLAG)
7672
list(APPEND compile_options "/arch:AVX2")

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
function(_get_common_test_compile_options output_var c_test flags)
22
_get_compile_options_from_flags(compile_flags ${flags})
33

4-
# Remove -fno-math-errno if it was added.
5-
if(LIBC_ADD_FNO_MATH_ERRNO)
6-
list(REMOVE_ITEM compile_options "-fno-math-errno")
7-
endif()
8-
94
set(compile_options
105
${LIBC_COMPILE_OPTIONS_DEFAULT}
116
${LIBC_TEST_COMPILE_OPTIONS_DEFAULT}

libc/config/baremetal/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"math": {
3030
"LIBC_CONF_MATH_OPTIMIZATIONS": {
31-
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)"
31+
"value": "(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES | LIBC_MATH_NO_ERRNO)"
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)