Skip to content

cg_clif: debuginfo checks ptr_type instead of pointee_type for wide pointer detection #448

@SebTardif

Description

@SebTardif

Bug

In compiler/rustc_codegen_cranelift/src/debuginfo/types.rs:133, the pointer_type() method checks whether the pointer type itself has metadata, instead of checking whether the pointee type has metadata:

fn pointer_type(..., ptr_type: Ty, pointee_type: Ty) -> UnitEntryId {
    // ...
    if !tcx.type_has_metadata(ptr_type, ...) {  // BUG: should be pointee_type

type_has_metadata on a pointer type (*const dyn Trait, &[u8]) always returns false because the pointer itself is a concrete sized type. The pointee (dyn Trait, [u8]) is what determines whether the pointer is wide (needs metadata).

This makes ALL pointers appear thin in DWARF debuginfo, causing debuggers to miss the vtable/length component of wide pointers.

Fix

Change ptr_type to pointee_type in the type_has_metadata call.

Impact

All wide pointers (&dyn Trait, &[T], *const dyn Trait, etc.) get incorrect DWARF debuginfo under the Cranelift backend, showing as thin pointers missing their metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: code generationI-wrongWrong result or data corruptionP-mediumMedium impact: affects specific usage patternsbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions