GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

Correctly handle COMPCODE_FALSE/TRUE trapping in combine_comparisons

Fixes floating-point exception handling by ensuring combine_comparisons doesn't incorrectly flag boolean comparison results as trapping.

This commit corrects a bug in GCC’s combine_comparisons function where COMPCODE_FALSE and COMPCODE_TRUE were erroneously treated as trapping operations when floating-point trapping was enabled. This led to the elimination of necessary IEEE exceptions. The fix modifies the condition that determines if a comparison traps, ensuring that these boolean outcomes do not trigger the trapping logic, thereby preserving correct floating-point exception behavior.

In Details

In the fold-const.cc file, the combine_comparisons function aims to preserve IEEE exception behavior when combining comparisons, particularly when flag_trapping_math is enabled. The existing logic incorrectly computed the trap variable as true for compcode values of COMPCODE_FALSE or COMPCODE_TRUE. This commit adjusts the trap computation to exclude these specific compcode values from being considered trapping, thereby preventing the erroneous elimination of IEEE exceptions for such comparisons.

For Context
combine_comparisons
A function within GCC that attempts to combine multiple comparison operations into a single, potentially more efficient comparison, while preserving the original program semantics, including floating-point exception behavior.
COMPCODE_FALSE
An internal representation indicating that a comparison resulted in a false value.
COMPCODE_TRUE
An internal representation indicating that a comparison resulted in a true value.
flag_trapping_math
A compiler flag that, when enabled, instructs the compiler to preserve the trapping behavior of floating-point operations, meaning that exceptional conditions like overflow or NaN should raise exceptions rather than being handled in a way that might discard the exception.
IEEE exceptions
Exceptional conditions defined by the IEEE 754 standard for floating-point arithmetic, such as invalid operation, division by zero, overflow, underflow, and inexact result. Compilers may need to preserve the trapping behavior of these exceptions.
Filed Under: optimizationfloating-pointbugfix