{"id":"31e5204359c0cc60","repo":"rust-lang/rust","slug":"internal-error-entered-unreachable-code-31e520","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_gcc/src/int.rs","lineNumber":299,"sourceCode":"            Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),\n            Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)),\n            t @ (Uint(_) | Int(_)) => t,\n            _ => panic!(\"tried to get overflow intrinsic for op applied to non-int type\"),\n        };\n\n        // FIXME(antoyo): remove duplication with intrinsic?\n        let name = if self.is_native_int_type(lhs.get_type()) {\n            match oop {\n                OverflowOp::Add => \"__builtin_add_overflow\",\n                OverflowOp::Sub => \"__builtin_sub_overflow\",\n                OverflowOp::Mul => \"__builtin_mul_overflow\",\n            }\n        } else {\n            let (func_name, width) = match oop {\n                OverflowOp::Add => match new_kind {\n                    Int(I128) => (\"__rust_i128_addo\", 128),\n                    Uint(U128) => (\"__rust_u128_addo\", 128),\n                    _ => unreachable!(),\n                },\n                OverflowOp::Sub => match new_kind {\n                    Int(I128) => (\"__rust_i128_subo\", 128),\n                    Uint(U128) => (\"__rust_u128_subo\", 128),\n                    _ => unreachable!(),\n                },\n                OverflowOp::Mul => match new_kind {\n                    Int(I32) => (\"__mulosi4\", 32),\n                    Int(I64) => (\"__mulodi4\", 64),\n                    Int(I128) => (\"__rust_i128_mulo\", 128), // FIXME(antoyo): use __muloti4d instead?\n                    Uint(U128) => (\"__rust_u128_mulo\", 128),\n                    _ => unreachable!(),\n                },\n            };\n            return self.operation_with_overflow(func_name, lhs, rhs, width);\n        };\n\n        let intrinsic = self.context.get_builtin_function(name);","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/int.rs#L281-L317","documentation":"Inside `gcc_checked_binop`, on the non-native-int path for `OverflowOp::Add`, the match on `new_kind` only arms `Int(I128)` and `Uint(U128)` (mapping to `__rust_i128_addo`/`__rust_u128_addo`). Any other width reaching this branch is unreachable: on a platform where the int is non-native, only i128/u128 qualify; i8–i64 are expected to be native and use `__builtin_add_overflow`.","triggerScenarios":"`is_native_int_type(lhs.get_type())` returns false for a type whose `new_kind` is not `I128`/`U128` (e.g. an i64 wrongly classified as non-native). The contradiction between type classification and width trips the unreachable.","commonSituations":"Misclassification of an integer's native-ness for the current target pointer width (32-bit target treating i64 as non-native, or a custom ABI). Also appears after changes to `is_native_int_type` that desync from the `new_kind` derivation.","solutions":["Verify `is_native_int_type` against the target pointer width: i8/i16/i32/i64 must be native on 64-bit, i8/i16/i32 on 32-bit.","Dump `lhs.get_type()` and `new_kind` at the call to confirm which one is wrong.","If a genuinely non-native width is needed (e.g. non-native i64), add an arm with the correct compiler-rt symbol (`__mulosi4`-style for add).","Add a target-specific test for the platform that triggered it."],"exampleFix":"// before\nOverflowOp::Add => match new_kind {\n    Int(I128) => (\"__rust_i128_addo\", 128),\n    Uint(U128) => (\"__rust_u128_addo\", 128),\n    _ => unreachable!(),\n},\n\n// after\nOverflowOp::Add => match new_kind {\n    Int(I128) => (\"__rust_i128_addo\", 128),\n    Uint(U128) => (\"__rust_u128_addo\", 128),\n    other => unreachable!(\"non-native add overflow for unexpected kind {:?}\", other),\n},","handlingStrategy":"fallback","validationCode":"// Non-native overflow Add is only implemented for i128/u128 (width 128).\n// If lhs is non-native but the resolved kind is not 128-bit, route elsewhere.\nuse rustc_middle::ty::{IntTy::*, UintTy::*, Int, Uint};\nlet native = builder.is_native_int_type(lhs.get_type());\nlet width_ok = match *typ.kind() {\n    Int(I128) | Uint(U128) => true,\n    _ => native, // native ints use __builtin_add_overflow and are fine\n};\nif !width_ok {\n    return Err(\"overflow Add: gcc backend only emulates i128/u128; rebuild with LLVM backend\");\n}","typeGuard":null,"tryCatchPattern":"// gcc backend panics on non-native overflow Add for non-128 widths.\n// Catch the unwind and retry compilation with the LLVM backend.\nuse std::panic::{catch_unwind, AssertUnwindSafe};\nlet res = catch_unwind(AssertUnwindSafe(|| {\n    builder.gcc_checked_binop(OverflowOp::Add, typ, lhs, rhs)\n}));\nmatch res {\n    Ok(v) => v,\n    Err(_) => {\n        eprintln!(\"gcc backend cannot emulate overflow Add for {:?}; falling back to LLVM\");\n        rebuild_with_backend(\"llvm\")?;\n    }\n}","preventionTips":["Overflow-Add emulation on the gcc backend is restricted to 128-bit non-native ints; avoid checked_add on exotic widths when targeting 32-bit platforms with -Ccodegen-backend=gcc.","When in doubt about a width, compile the offending crate with the LLVM backend (drop -Ccodegen-backend=gcc) instead of patching around the panic.","Unit-test new integer widths against gcc_checked_binop in Release before shipping; debug builds hide unreachable! behind the optimizer."],"tags":["rustc-codegen-gcc","ice","overflow","i128","compiler-rt"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}