rust-lang/rust · error
tried to get overflow intrinsic for op applied to non-int ty
Error message
tried to get overflow intrinsic for op applied to non-int type
What it means
`Builder::gcc_checked_binop` (overflow-checking add/sub/mul) matches on `typ.kind()` and only handles `Int`/`Uint`. Any other `TyKind` (e.g. a pointer-sized type that wasn't normalized, a `Bool`, a char, or an enum/struct) reaches the panic arm. The function is meant to be called only for integer overflow intrinsics, so a non-int type indicates a dispatch bug upstream.
Source
Thrown at compiler/rustc_codegen_gcc/src/int.rs:284
self.multiplicative_operation(BinaryOp::Divide, "div", false, a, b)
}
pub fn gcc_checked_binop(
&self,
oop: OverflowOp,
typ: Ty<'_>,
lhs: <Self as BackendTypes>::Value,
rhs: <Self as BackendTypes>::Value,
) -> (<Self as BackendTypes>::Value, <Self as BackendTypes>::Value) {
use rustc_middle::ty::IntTy::*;
use rustc_middle::ty::UintTy::*;
use rustc_middle::ty::{Int, Uint};
let new_kind = match *typ.kind() {
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)),
t @ (Uint(_) | Int(_)) => t,
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
};
// FIXME(antoyo): remove duplication with intrinsic?
let name = if self.is_native_int_type(lhs.get_type()) {
match oop {
OverflowOp::Add => "__builtin_add_overflow",
OverflowOp::Sub => "__builtin_sub_overflow",
OverflowOp::Mul => "__builtin_mul_overflow",
}
} else {
let (func_name, width) = match oop {
OverflowOp::Add => match new_kind {
Int(I128) => ("__rust_i128_addo", 128),
Uint(U128) => ("__rust_u128_addo", 128),
_ => unreachable!(),
},
OverflowOp::Sub => match new_kind {
Int(I128) => ("__rust_i128_subo", 128),View on GitHub (pinned to 22057b88b0)
Solutions
- Identify the offending `typ` by dumping `typ.kind()` at the panic site; trace back to the MIR `BinOp`/`OverflowOp` that produced it.
- If the type is logically an integer (e.g. char-as-u32), normalize it before calling `gcc_checked_binop`, or handle the case in the caller.
- Guard the call site in the SSA layer so overflow intrinsics are only requested for integer types.
- Add a regression test exercising the offending MIR construct on the i128/non-native path.
Example fix
// before
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
// after (actionable message including the kind)
other => panic!(
"gcc_checked_binop: non-int type {:?} for op {:?}",
other, oop,
), Defensive patterns
Strategy: type-guard
Validate before calling
// gcc_checked_binop panics when typ.kind() is not Int/Uint. Narrow first.
use rustc_middle::ty::{Int, Uint, TyKind};
match *typ.kind() {
TyKind::Int(_) | TyKind::Uint(_) => builder.gcc_checked_binop(oop, typ, lhs, rhs),
_ => return Err(format!("checked overflow on non-int type {:?}", typ)),
} Type guard
use rustc_middle::ty::{Int, Uint, TyKind};
/// True only for integer (signed or unsigned) Rust types.
fn ty_is_integer<'tcx>(typ: rustc_middle::ty::Ty<'tcx>) -> bool {
matches!(typ.kind(), TyKind::Int(_) | TyKind::Uint(_))
}
if ty_is_integer(typ) {
builder.gcc_checked_binop(oop, typ, lhs, rhs)
} Prevention
- Overflow ops (wrapping_add, checked_*, saturating_*) are only defined on integers in Rust; never pass pointer, float, char, or enum types into a checked-binop codegen path.
- If you need overflow detection on a newtype, delegate to the inner integer field, not the wrapper type.
- Normalize isize/usize to a concrete width (via normalize(target.pointer_width)) before calling gcc_checked_binop so the kind stays Int/Uint.
When it happens
Trigger: `rustc_codegen_ssa` calls `gcc_checked_binop(oop, typ, lhs, rhs)` with a `typ` whose `TyKind` is not `Int(_)` or `Uint(_)` (after `Isize`/`Usize` normalization). Occurs when an overflow check is emitted for an operand whose type the middle end did not constrain to an integer.
Common situations: Triggered by edge cases in MIR: overflow checks on `char` arithmetic, raw-pointer offsetting that lowers to a checked binop, or after a rustc upgrade that introduces a new `TyKind` not yet reflected here. Symptom of an upstream type-system mismatch rather than user code.
Related errors
- internal error: entered unreachable code
- non-array a value
- unexpected integer size
- element type
- get element type
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/45bb2c77894e3704.json.
Report an issue: GitHub.