Skip to content

Commit b34147f

Browse files
bmehta001Copilot
andcommitted
Drop -ffast-math from Unix REL_FLAGS
PR microsoft#1416 inadvertently regressed PR microsoft#1415 by removing -fno-finite-math-only from the three Unix REL_FLAGS branches and silencing the resulting Clang warning via -Wno-nan-infinity-disabled. That left -ffast-math implying -ffinite-math-only on Clang/AppleClang, which folds std::isnan / std::isinf to false in nlohmann::json (lib/include/mat/json.hpp) and breaks the IEEE 754 invariants that SQLite relies on for sqlite3_bind_double / sqlite3IsNaN. Rather than restore -fno-finite-math-only, address the root cause by removing -ffast-math entirely from all three Unix REL_FLAGS branches (GCC, AppleClang, generic Clang). For a telemetry library: - The hot paths are string concatenation, Bond/JSON serialization, HTTP I/O, and SQLite reads/writes - there is essentially no floating-point arithmetic for -ffast-math to optimize. - Defining __FAST_MATH__ causes some libc++ / glibc headers to shortcut isnan / isinf even with -fno-finite-math-only set, silently corrupting NaN handling in nlohmann::json output. - On x86 Linux, -ffast-math links crtfastmath.o which sets MXCSR FTZ/DAZ bits process-wide at startup, leaking flush-to-zero behavior into client applications that link this SDK - a contract violation for any consumer doing scientific compute or audio DSP. - SQLite source explicitly recommends against -ffast-math. This subsumes the partial mitigation from microsoft#1415 (-fno-finite-math-only is no longer needed once -ffast-math itself is gone) and aligns with the intent of the long-standing draft PR microsoft#1392 by ThomsonTan, extended to the GCC branch as well (GCC's -ffast-math has the same finite-math-only and crtfastmath.o behavior on x86 Linux). Also drop -Wno-nan-infinity-disabled from the Clang WARN_FLAGS - it only existed to silence the warning that flagged this exact bug, and is unnecessary once -ffast-math is no longer pulling in -ffinite-math-only. Validation: - cmake configure + Release build of UnitTests on macOS arm64 (AppleClang 21): no warnings, no -Wnan-infinity-disabled hits. - ./out/tests/unittests/UnitTests: 486/486 pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 953ff8b commit b34147f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,20 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
121121
set(WARN_FLAGS "-Wall -Werror -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable")
122122
else()
123123
# No -pedantic -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments
124-
set(WARN_FLAGS "-Wall -Werror -Wextra -Wno-unused-parameter -Wno-unknown-warning-option -Wno-unused-but-set-variable -Wno-nan-infinity-disabled")
124+
set(WARN_FLAGS "-Wall -Werror -Wextra -Wno-unused-parameter -Wno-unknown-warning-option -Wno-unused-but-set-variable")
125125
endif()
126126

127127
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
128128
# Using GCC with -s and -Wl linker flags
129-
set(REL_FLAGS "-s -Wl,--gc-sections -Os ${WARN_FLAGS} -ffunction-sections -fdata-sections -fmerge-all-constants -ffast-math")
129+
set(REL_FLAGS "-s -Wl,--gc-sections -Os ${WARN_FLAGS} -ffunction-sections -fdata-sections -fmerge-all-constants")
130130
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
131131
set(REL_FLAGS "${WARN_FLAGS}")
132132
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
133133
# AppleClang does not support -ffunction-sections and -fdata-sections with the -fembed-bitcode and -fembed-bitcode-marker
134-
set(REL_FLAGS "-Os ${WARN_FLAGS} -fmerge-all-constants -ffast-math")
134+
set(REL_FLAGS "-Os ${WARN_FLAGS} -fmerge-all-constants")
135135
else()
136136
# Using clang - strip unsupported GCC options
137-
set(REL_FLAGS "-Os ${WARN_FLAGS} -ffunction-sections -fmerge-all-constants -ffast-math")
137+
set(REL_FLAGS "-Os ${WARN_FLAGS} -ffunction-sections -fmerge-all-constants")
138138
endif()
139139

140140
## Uncomment this to reduce the volume of note warnings on RPi4 w/gcc-8 Ref. https://gcc.gnu.org/ml/gcc/2017-05/msg00073.html

0 commit comments

Comments
 (0)