GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c-family Performance Win

Define __UNSAFE_MATH_OPTIMIZATIONS__ macro.

GCC now defines __UNSAFE_MATH_OPTIMIZATIONS__ when -funsafe-math-optimizations is used.

This change introduces the predefined macro __UNSAFE_MATH_OPTIMIZATIONS__ in GCC. This macro is defined when the -funsafe-math-optimizations compiler flag is enabled, allowing code, particularly in headers like glibc’s vector math declarations, to detect and conditionally adapt to these potentially less accurate optimizations. The macro is also handled correctly for #pragma GCC optimize directives.

In Details

The -funsafe-math-optimizations flag enables optimizations that may violate strict IEEE 754 floating-point standards for performance gains. While GCC predefines macros for specific flags like -ffast-math, it did not previously have a macro for the -funsafe-math-optimizations option itself. This commit adds __UNSAFE_MATH_OPTIMIZATIONS__ to c-cppbuiltin.cc and cppbuiltin.cc, ensuring that libraries depending on this flag can reliably detect its presence, even when applied via pragmas.

For Context
-funsafe-math-optimizations
A GCC compiler flag that enables optimizations for floating-point arithmetic that may not adhere to strict IEEE 754 standards, potentially leading to less precise results but faster execution.
IEEE 754
A technical standard for floating-point arithmetic, defining formats for representing fractional numbers and rules for operations like addition, subtraction, multiplication, and division.
predefined macro
A macro that is automatically defined by the compiler before the source code is processed. These often indicate specific compiler features, target architectures, or enabled flags.
#pragma GCC optimize
A GCC-specific pragma directive that allows enabling or disabling optimization flags for specific sections of code.
Filed Under: c-familycompiler flagsmacromath optimizations