GCC Newspaper
JULY 29, 2026
gcc Proposed Sentiment 7 / 10

Turn off trapping-math for C and C++ front-ends

GCC defaults to -ftrapping-math, but this has many issues. Proposal: disable it by default for C/C++ and file bugs for problematic cases.

Andrea Pinski proposes to disable -ftrapping-math by default for GCC’s C and C++ front-ends. The current default, -ftrapping-math, has been associated with various issues, including code transformations that incorrectly alter exception flag behavior. Pinski argues that this default has been problematic since at least GCC 3.4. The change aims to align GCC’s behavior with Clang/LLVM, which defaults to -fno-trapping-math, and to enable a fair comparison between the two compilers. The discussion also touches on the need for #pragma FENV_ACCESS support and potential diagnostics for calls to related functions.

In the Thread 4 participants
  1. Andrea Pinski proposer

    Proposes to disable -ftrapping-math by default for C and C++ front-ends due to existing issues with code transformations altering exception flag behavior.

  2. Martin Uecker contributor

    Agrees with the proposal and asks if #pragma FENV_ACCESS support can be added.

    “I think I agree, but is there a chance that we can also get #pragma FENV_ACCESS support?”
  3. Matthias Kretz contributor

    Supports changing the default and suggests adding a diagnostic for calls to relevant functions.

  4. Richard Biener reviewer

    Acknowledges the proposal and the associated problematic definition of -ftrapping-math.

Technical Tradeoffs

  • Disabling -ftrapping-math by default may improve performance and stability by avoiding issues with problematic optimizations, but could break code that relies on precise FP exception behavior.
  • Aligning with LLVM's default simplifies comparisons but requires addressing the underlying issues in GCC's implementation of -ftrapping-math.
  • Adding diagnostics for related functions improves user awareness but adds complexity to the compiler.

In Details

The -ftrapping-math flag in GCC controls whether floating-point operations are allowed to transform in ways that might alter the precise raising of FP exception flags or trap handlers. Historically, GCC has defaulted to enabling this flag, but this has led to issues where optimizations break the expected exception behavior. This proposal suggests disabling it by default for C/C++ to match LLVM's behavior and to address known problems, while also intending to fix individual cases where the flag might be mishandled.

For Context
-ftrapping-math
A GCC flag that enables floating-point exceptions and disallows certain code transformations that might affect exception flag behavior or trap handling.
#pragma FENV_ACCESS
A pragma that indicates whether a section of code accesses or modifies the floating-point environment, which can influence compiler optimizations related to floating-point operations.
DCE
Dead Code Elimination, a compiler optimization that removes code that does not affect the program's output.
Filed Under: gcccompiler-flagsfloating-pointoptimization