GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Diagnose const arithmetic overflow with E0080

Ensures Rust's const evaluation correctly diagnoses arithmetic overflow for both signed and unsigned types.

GCC’s Rust frontend (gccrs) previously only diagnosed arithmetic overflow for signed integers during constant evaluation, allowing unsigned integers to wrap around silently. This commit enhances the constant evaluation process to detect and report overflow for both signed and unsigned types, aligning with Rust’s language specification (E0080 error). The change involves modifying how arithmetic expressions are built and checked, ensuring proper location information is available for error reporting.

In Details

In gccrs, the constant evaluation (rust-constexpr.cc) now correctly diagnoses arithmetic overflow for both signed and unsigned integer operations, emitting the Rust E0080 error. Previously, TREE_OVERFLOW was only set for signed operations, and unsigned overflow resulted in silent wrapping. This commit changes arithmetic_or_logical_expression in rust-gcc.cc to use build2_loc instead of fold_build2_loc, allowing the const folder to see the operation and its operands. A new function eval_check_overflow_p is introduced to check for overflow on both signednesses before it's used in…

For Context
gccrs
The Rust frontend for GCC. It aims to provide a first-class Rust compiler experience using the GCC infrastructure.
const evaluation
The process by which the compiler evaluates expressions at compile time if they are known to be constant. This is common in Rust for static variables, array sizes, and other compile-time determined values.
arithmetic overflow
A condition that occurs when an arithmetic operation produces a result that is too large to be stored in the available memory space or exceeds the maximum representable value for a given data type.
E0080
A specific error code in the Rust language, indicating an arithmetic overflow during compile-time constant evaluation.
INTEGER_CST
GCC's internal representation for an integer constant value within its tree-based intermediate representation (IR).
Filed Under: gccrsRustconst evaluationoverflowdiagnostics