{"id":"d38115a88b42a5df","repo":"rust-lang/rust","slug":"unexpected-integer-size","errorCode":null,"errorMessage":"unexpected integer size","messagePattern":"unexpected integer size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_gcc/src/int.rs","lineNumber":363,"sourceCode":"        let overflow_param_type = overflow_type.make_pointer();\n        let res_type = a_type;\n\n        let overflow_value =\n            self.current_func().new_local(self.location, overflow_type, \"overflow\");\n        let overflow_addr = overflow_value.get_address(self.location);\n\n        let param_a = self.context.new_parameter(self.location, a_type, \"a\");\n        let param_b = self.context.new_parameter(self.location, b_type, \"b\");\n        let param_overflow =\n            self.context.new_parameter(self.location, overflow_param_type, \"overflow\");\n\n        let a_elem_type = a_type.dyncast_array().expect(\"non-array a value\");\n        debug_assert!(a_elem_type.is_integral());\n        let res_ty = match width {\n            32 => self.tcx.types.i32,\n            64 => self.tcx.types.i64,\n            128 => self.tcx.types.i128,\n            _ => unreachable!(\"unexpected integer size\"),\n        };\n        let layout = self\n            .tcx\n            .layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(res_ty))\n            .unwrap();\n\n        let arg_abi = ArgAbi { layout, mode: PassMode::Direct(ArgAttributes::new()) };\n        let mut fn_abi = FnAbi {\n            args: vec![arg_abi.clone(), arg_abi.clone(), arg_abi.clone()].into_boxed_slice(),\n            ret: arg_abi,\n            c_variadic: false,\n            fixed_count: 3,\n            conv: CanonAbi::C,\n            can_unwind: false,\n        };\n        fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false });\n\n        let ret_indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/int.rs#L345-L381","documentation":"In `operation_with_overflow`, after recovering the element type, the code selects the result `Ty` based on `width`: `32 => i32`, `64 => i64`, `128 => i128`. Any other width (e.g. 16, or a non-power-of-two passed by a caller) hits `unreachable!(\"unexpected integer size\")`. Width is propagated from `gcc_checked_binop`'s literal `32/64/128` constants, so a different value implies the caller was extended without updating this match.","triggerScenarios":"`operation_with_overflow(func_name, lhs, rhs, width)` is invoked with a `width` not in `{32, 64, 128}`. Currently only reachable if a new arm is added to the upstream match in `gcc_checked_binop` (errors 134–136) passing a novel width.","commonSituations":"A patch adding support for a new non-native width (e.g. 16-bit overflow) without extending this match. Not user-facing; an internal invariant.","solutions":["Trace the `width` argument back to `gcc_checked_binop` and confirm which arm produced it.","Add an arm here for the new width mapping to the corresponding `tcx.types.i*`.","Alternatively, derive `res_ty` directly from `width`/element type instead of a hardcoded match, to keep the two sites in sync."],"exampleFix":"// before\nlet res_ty = match width {\n    32 => self.tcx.types.i32,\n    64 => self.tcx.types.i64,\n    128 => self.tcx.types.i128,\n    _ => unreachable!(\"unexpected integer size\"),\n};\n\n// after\nlet res_ty = match width {\n    32 => self.tcx.types.i32,\n    64 => self.tcx.types.i64,\n    128 => self.tcx.types.i128,\n    other => unreachable!(\"operation_with_overflow: unsupported width {}\", other),\n};","handlingStrategy":"validation","validationCode":"// operation_with_overflow only accepts width in {32, 64, 128}.\nconst SUPPORTED: [u64; 3] = [32, 64, 128];\nif !SUPPORTED.contains(&width) {\n    return Err(format!(\"operation_with_overflow: width {} not in {{32,64,128}}\", width));\n}\nbuilder.operation_with_overflow(func_name, lhs, rhs, width)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only 32-, 64-, and 128-bit overflow helpers are linked from compiler-rt (__mulosi4, __mulodi4, __rust_*128_*o); never request another width.","Derive width from the integer TyKind rather than computing it ad hoc, so a mis-sized type cannot reach this match.","If you introduce a new width, also wire the corresponding compiler-rt intrinsic name and width constant into the match arm."],"tags":["rustc-codegen-gcc","ice","overflow","integer-width","i128"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}