Skip to content

miri_to_const bug on big-endian targets #11488

Closed
@RalfJung

Description

@RalfJung

Description

I just noticed the miri_to_const function. This seems to duplicate a bunch of the logic in try_destructure_mir_constant_for_diagnostics, maybe it would make sense to fully migrate to that query instead?

In particular the current logic is partially wrong: it has support for ConstValue::Indirect arrays of floats. However, using from_le_bytes to convert interpreter floats to an f32 is going to go wrong on big-endian targets. You need to take into account the endianess of the current compiler session. Or ideally you just use all the functions that already exist in rustc to work with interpreter data, e.g. Allocation::read_scalar.

(Also, we are using "Miri" as the name for the tool these days, so the function is somewhat misnamed. This is really just converting a MIR constant into a Clippy constant.)

Version

No response

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions