Skip to content

miri function argument passing should use FnAbi #56166

Closed
@RalfJung

Description

@RalfJung

In the miri engine, when evaluating a function call, it can happen that caller and callee do not agree on the type of an argument. In this case, the argument effectively gets transmuted from the caller type to the callee type. However, this is not legal for all types, and whether it is legal depends on horrible details of the ABI. This logic is implemented for codegen, where it is called FnType. miri should probably use that same infrastructure.

The relevant code in miri that would need changing is here. Currently, we only allow argument type punning for the Rust ABI, and we only allow the valid range of a Scalar/ScalarPair to change -- effectively, we allow one side to have &T while the other side has *const T.

For the FnType side, I do not know much, but @eddyb offered to mentor someone trying to do this cleanup. :) He also left the following hints:

move some code from rustc_codegen_ssa and then compare ArgType pairwise.

The main issue to moving that stuff around is pointee_info_at (it would have to be moved to rustc::ty::layout, as an additional method in TyLayoutMethods):

if let Some(pointee) = layout.pointee_info_at(cx, offset) {

Everything else is mostly relying on rustc_target doing the heavy lifting, already.

Cc @oli-obk

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions