{"id":"6c173839d692fcc7","repo":"rust-lang/rust","slug":"i64-try-from","errorCode":null,"errorMessage":"i64::try_from","messagePattern":"i64::try_from","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_gcc/src/builder.rs","lineNumber":1534,"sourceCode":"        let array_type =\n            new_array_type(self.context, self.location, element_type, vec_num_units as u64);\n        let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();\n        self.context.new_array_access(self.location, array, idx).to_rvalue()\n    }\n\n    fn vector_splat(&mut self, _num_elts: usize, _elt: RValue<'gcc>) -> RValue<'gcc> {\n        unimplemented!();\n    }\n\n    fn extract_value(&mut self, aggregate_value: RValue<'gcc>, idx: u64) -> RValue<'gcc> {\n        // FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.\n        assert_eq!(idx as usize as u64, idx);\n        let value_type = aggregate_value.get_type();\n\n        if value_type.dyncast_array().is_some() {\n            let index = self\n                .context\n                .new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect(\"i64::try_from\"));\n            let element = self.context.new_array_access(self.location, aggregate_value, index);\n            element.get_address(self.location)\n        } else if value_type.dyncast_vector().is_some() {\n            panic!();\n        } else if let Some(struct_type) = value_type.is_struct() {\n            aggregate_value\n                .access_field(self.location, struct_type.get_field(idx as i32))\n                .to_rvalue()\n        } else {\n            panic!(\"Unexpected type {:?}\", value_type);\n        }\n    }\n\n    fn insert_value(\n        &mut self,\n        aggregate_value: RValue<'gcc>,\n        value: RValue<'gcc>,\n        idx: u64,","sourceCodeStart":1516,"sourceCodeEnd":1552,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/builder.rs#L1516-L1552","documentation":"Panics when the aggregate field index (a u64) cannot be converted to i64 during extract_value on an array type. rustc_codegen_gcc must pass the index to libgccjit's new_rvalue_from_long, which only accepts i64; on a 64-bit platform this triggers only for indices exceeding i64::MAX. It indicates the codegen backend received an implausibly large array element index from rustc.","triggerScenarios":"Calling extract_value on a dyncast_array aggregate with an idx value greater than i64::MAX (0x7FFFFFFFFFFFFFFF). The expect(\"i64::try_from\") fires after the earlier assert_eq!(idx as usize as u64, idx) check passes but the i64 downcast fails.","commonSituations":"Effectively unreachable in normal Rust compilation; would only surface from a corrupted MIR, an internal rustc bug producing an out-of-range field index, or a fuzzing/harness run feeding pathological indices. No developer configuration produces it.","solutions":["Treat as an internal compiler bug: capture the rustc revision and the offending crate/MIR and report it upstream against rustc_codegen_gcc.","If you are fuzzing the backend, clamp or reject idx before calling extract_value rather than relying on the panic.","Replace the expect with an explicit error path returning a compilation error instead of an ICE, if patching the backend locally."],"exampleFix":"// before\n.context\n.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect(\"i64::try_from\"));\n// after\nlet i = i64::try_from(idx)\n    .unwrap_or_else(|_| bug!(\"extract_value array index {idx} exceeds i64::MAX\"));\n.context.new_rvalue_from_long(self.u64_type, i);","handlingStrategy":"validation","validationCode":"fn check_aggregate_index(idx: u64) -> Result<(), String> {\n    if idx > i64::MAX as u64 {\n        return Err(format!(\n            \"aggregate index {0} exceeds i64::MAX ({1}); cg_gcc cannot address it\",\n            idx, i64::MAX\n        ));\n    }\n    Ok(())\n}\n// call before extract_value(aggregate, idx):\n// check_aggregate_index(idx).map_err(|e| report_codegen_bug(e))?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat any aggregate index > i64::MAX as a bug — it is unreachable for real arrays and means upstream computed a nonsensical index.","Prefer named struct field access over numeric extract_value for large or generated aggregates.","If you generate MIR/aggregate code programmatically, clamp every index into the i64 range before handing it to the codegen backend.","Add an assertion in your own codegen shim that wraps extract_value so the failure is reported with your context, not as a bare `.expect(\"i64::try_from\")`."],"tags":["codegen-gcc","panic","integer-overflow","internal-compiler-error"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}