Skip to content

SROA is incompatible with RFC 3943 semantics #163388

Description

@tmiasko
#![feature(custom_mir, core_intrinsics)]
#![allow(internal_features)]
use std::intrinsics::mir::*;
use std::mem::MaybeUninit;
#[custom_mir(dialect = "runtime")]
pub fn main() {
    mir! {
        let _1: (usize, MaybeUninit<usize>);
        let _2: MaybeUninit<usize>;
        {
            _1.0 = 0;
            _2 = _1.1;
            Return()
        }
    }
}

rustc --crate-type=lib a.rs -Zunpretty=mir -Zmir-opt-level=0 -Zmir-enable-passes=+ScalarReplacementOfAggregates

// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
// HINT: See also -Z dump-mir for MIR at specific points during compilation.
fn main() -> () {
    let mut _0: ();
    let mut _1: (usize, std::mem::MaybeUninit<usize>);
    let mut _2: std::mem::MaybeUninit<usize>;
    let mut _3: usize;
    let mut _4: std::mem::MaybeUninit<usize>;

    bb0: {
        _3 = const 0_usize;
        _2 = copy _4;
        return;
    }
}

cc @Amanieu

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 26, 2026
  2. Amanieu commented on Sep 28, 2026

    @Amanieu
    Member

    I addressed this in #163335. The basic idea is that a write to a place based on _1 has the side-effect of allocating _1. This side effect must be preserved when splitting by emitting StorageAlloc for every field at that point (except the field being written to, since it gets that implicitly from the write anyways).

  3. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 28, 2026
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

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions