Skip to content

enum padding incorrectly has Scalar::Initialized layout #96158

Description

@RalfJung

#94527 extended our Scalar layout with the notion of whether a scalar has to be initialized or not. Miri enforces this, and also uses it to know whether it can use a more efficient representation for scalars that have to be initialized.

However, in some situations we currently compute a Scalar::Initialized layout when it should be Scalar::Union (aka "may be uninitialized" -- maybe we should rename it to Scalar::MaybeUninit). Specifically, Option<u32> has:

           abi: ScalarPair(
               Initialized {
                   value: Int(
                       I32,
                       false,
                   ),
                   valid_range: 0..=1,
               },
               Initialized {
                   value: Int(
                       I32,
                       false,
                   ),
                   valid_range: 0..=4294967295,
               },
           ),

Note that this claims that the second field must be always initialized. This is not true though, since for a None that second field is padding and hence does not have to be initialized.

This causes rust-lang/miri#2068.
@oli-obk any idea how hard this is to fix?

(To be clear, this bug only causes problems in Miri, not during regular codegen -- at least for now, since we don't [yet] tell LLVM about this "must be initialized" thing.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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