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

Fix integer overflow pattern for abs((convert)a)

Corrected a GCC pattern for abs((convert)a) to prevent integer overflow and undefined behavior.

A pattern in GCC’s pattern matching for (trunc)abs((ext)a) was fixed to prevent potential integer overflow and undefined behavior. The pattern has been restricted to non-integral types, ensuring that integer types are handled by a separate, more appropriate pattern. This resolves a bug where casting from unsigned types could lead to incorrect results.

In Details

In gcc/match.pd, the pattern for (trunc)abs((ext)a) was modified. It's now placed after abs((ext)a) and restricted to non-integral types. This prevents it from incorrectly handling integer types, which are now exclusively managed by the abs((ext)a) pattern. This change addresses PR tree-optimization/127689 by avoiding potential undefined behavior from integer overflow when casting from unsigned types.

Filed Under: optimizationinteger overflowpattern matchingundefined behavior