transform_instance in rustc_sanitizers::cfi::typeid::itanium_cxx_abi::transform - Rust
Description: Transforms an instance for LLVM CFI and cross-language LLVM CFI support using Itanium C++ ABI mangling.

Skip to main content

## transform_instance

# Function transform_instance

Source

    pub(crate) fn transform_instance<'tcx>(
        tcx: TyCtxt<'tcx>,
        instance: Instance<'tcx>,
        options: TypeIdOptions,
    ) -> Instance<'tcx>

Expand description

Transforms an instance for LLVM CFI and cross-language LLVM CFI support using Itanium C++ ABI mangling.

typeid_for_instance is called at two locations, initially when declaring/defining functions and methods, and later during code generation at call sites, after type erasure might have occurred.

In the first call (i.e., when declaring/defining functions and methods), it encodes type ids for an FnAbi or Instance, and these type ids are attached to functions and methods. (These type ids are used later by the LowerTypeTests LLVM pass to aggregate functions in groups derived from these type ids.)

In the second call (i.e., during code generation at call sites), it encodes a type id for an FnAbi or Instance, after type erasure might have occurred, and this type id is used for testing if a function is member of the group derived from this type id. Therefore, in the first call to typeid_for_fnabi (when type ids are attached to functions and methods), it can only include at most as much information that would be available in the second call (i.e., during code generation at call sites); otherwise, the type ids would not match.

For this, it:

- Adjust the type ids of DropGlues (see below).
- Adjusts the type ids of VTableShims to the type id expected in the call sites for the entry in the vtable (i.e., by using the signature of the closure passed as an argument to the shim, or by just removing self).
- Performs type erasure for calls on trait objects by transforming self into a trait object of the trait that defines the method.
- Performs type erasure for closures call methods by transforming self into a trait object of the Fn trait that defines the method (for being attached as a secondary type id).