rust-lang/rust · critical
i64::try_from
Error message
i64::try_from
What it means
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.
Source
Thrown at compiler/rustc_codegen_gcc/src/builder.rs:1534
let array_type =
new_array_type(self.context, self.location, element_type, vec_num_units as u64);
let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();
self.context.new_array_access(self.location, array, idx).to_rvalue()
}
fn vector_splat(&mut self, _num_elts: usize, _elt: RValue<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
fn extract_value(&mut self, aggregate_value: RValue<'gcc>, idx: u64) -> RValue<'gcc> {
// FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.
assert_eq!(idx as usize as u64, idx);
let value_type = aggregate_value.get_type();
if value_type.dyncast_array().is_some() {
let index = self
.context
.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
let element = self.context.new_array_access(self.location, aggregate_value, index);
element.get_address(self.location)
} else if value_type.dyncast_vector().is_some() {
panic!();
} else if let Some(struct_type) = value_type.is_struct() {
aggregate_value
.access_field(self.location, struct_type.get_field(idx as i32))
.to_rvalue()
} else {
panic!("Unexpected type {:?}", value_type);
}
}
fn insert_value(
&mut self,
aggregate_value: RValue<'gcc>,
value: RValue<'gcc>,
idx: u64,View on GitHub (pinned to 22057b88b0)
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.
Example fix
// before
.context
.new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect("i64::try_from"));
// after
let i = i64::try_from(idx)
.unwrap_or_else(|_| bug!("extract_value array index {idx} exceeds i64::MAX"));
.context.new_rvalue_from_long(self.u64_type, i); Defensive patterns
Strategy: validation
Validate before calling
fn check_aggregate_index(idx: u64) -> Result<(), String> {
if idx > i64::MAX as u64 {
return Err(format!(
"aggregate index {0} exceeds i64::MAX ({1}); cg_gcc cannot address it",
idx, i64::MAX
));
}
Ok(())
}
// call before extract_value(aggregate, idx):
// check_aggregate_index(idx).map_err(|e| report_codegen_bug(e))?; Prevention
- 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")`.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected type {:?}
- vector type
- mask should be of struct type
- Size::bits: {bytes} bytes in bits doesn't fit in u64
- Size::add: {} + {} doesn't fit in u64
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/6c173839d692fcc7.json.
Report an issue: GitHub.