rust-lang/rust · error

pointee type

Error message

pointee type

What it means

Thrown by rustc_codegen_gcc inside gep() (the lowering of LLVM-style getelementptr / pointer arithmetic). While walking each index, the backend computes the stride by calling pointee_type.get_pointee().expect("pointee type") to advance by sizeof the pointed-to type. If the current GCC type is not a pointer (or libgccjit reports no pointee for it), the expect panics. It indicates pointer type information was lost - typically because the value was cast to a plain integer/byte pointer before GEP.

Source

Thrown at compiler/rustc_codegen_gcc/src/builder.rs:1218

    fn gep(
        &mut self,
        typ: Type<'gcc>,
        ptr: RValue<'gcc>,
        indices: &[RValue<'gcc>],
    ) -> RValue<'gcc> {
        // NOTE: due to opaque pointers now being used, we need to cast here.
        let ptr = self.context.new_cast(self.location, ptr, typ.make_pointer());
        let ptr_type = ptr.get_type();
        let mut pointee_type = ptr.get_type();
        // NOTE: we cannot use array indexing here like in inbounds_gep because array indexing is
        // always considered in bounds in GCC (FIXME(antoyo): to be verified).
        // So, we have to cast to a number.
        let mut result = self.context.new_bitcast(self.location, ptr, self.sizet_type);
        // FIXME(antoyo): if there were more than 1 index, this code is probably wrong and would
        // require dereferencing the pointer.
        for index in indices {
            pointee_type = pointee_type.get_pointee().expect("pointee type");
            #[cfg(feature = "master")]
            let pointee_size = {
                let size = self.cx.context.new_sizeof(pointee_type);
                self.context.new_cast(self.location, size, index.get_type())
            };
            #[cfg(not(feature = "master"))]
            let pointee_size =
                self.context.new_rvalue_from_int(index.get_type(), pointee_type.get_size() as i32);
            result = result + self.gcc_int_cast(*index * pointee_size, self.sizet_type);
        }
        self.context.new_bitcast(self.location, result, ptr_type)
    }

    fn inbounds_gep(
        &mut self,
        typ: Type<'gcc>,
        ptr: RValue<'gcc>,
        indices: &[RValue<'gcc>],

View on GitHub (pinned to 22057b88b0)

Solutions

  1. Update/pin libgccjit to the version compatible with this rustc_codegen_gcc release (opaque-pointer get_pointee support is version-sensitive).
  2. Avoid raw-pointer arithmetic through integer/usize casts; index typed &[T] or *const T directly so the element type is preserved through to GEP.
  3. Switch the affected crate to the LLVM backend to confirm and bypass the gccjit-specific panic while it is reproduced.
  4. File an issue / patch gep() in builder.rs to reconstruct the pointee type from the typ parameter (which carries the intended element type) instead of relying on get_pointee() (upstream).

Example fix

// before - pointer cast to usize loses pointee type before GEP
let p = x as usize;
let item = unsafe { &*(p as *const u8).add(offset * size) };

// after - keep a typed pointer/slice so GEP has a pointee type
let slice: &[u8] = &data;
let item = &slice[offset * size];
Defensive patterns

Strategy: type-guard

Validate before calling

// Avoid `ptr::from_exposed_addr` / int->reference casts that force cg_gcc
// to derive a pointee type from an opaque integer (builder.rs:1218).
let re = regex::Regex::new(r"(from_exposed_addr|transmute::<(?:usize|u\d+),\s*&)").unwrap();
if re.is_match(&src) { eprintln!("cg_gcc cannot infer pointee type; refactor to typed ptrs."); }

Type guard

// Always carry the pointee type in the pointer — never bare usize.
fn typed_ptr<T>(p: *mut T) -> *mut T { p } // identity, but forces T to be known
// Reject opaque-address APIs at the type level:
pub struct OpaqueAddr(pub usize); // do NOT transmute this to *mut T
pub struct TypedPtr<T>(*mut T);   // do use this instead

Try / catch

// Compile-time panic in cg_gcc; cannot be caught. Resolve by giving the
// pointer a concrete pointee type or by compiling the crate with LLVM.

Prevention

When it happens

Trigger: Indexing into a pointer/array via GEP where the GCC type of the pointer has no recoverable pointee: e.g. GEP on a value bitcast through sizet_type (as gep itself does internally) without re-attaching element-type info, indexing a *const T whose T was erased by a prior opaque cast, or multi-index GEP where the FIXME note in the source says dereferencing is unimplemented. Most common with slices, arrays, and &[T] indexing under the gcc backend.

Common situations: libgccjit version where get_pointee() returns None for opaque/integer-cast pointers; code that does heavy raw-pointer arithmetic (parsers, allocators, FFI buffers) compiled with the gcc backend; gcc 13->14 opaque-pointer transition that stopped tagging pointee types on casts.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/12b8e7bc2367099f.json. Report an issue: GitHub.