Skip to content

NRVO miropt is unsound #111005

Open
Open
@JakobDegen

Description

@JakobDegen

I tried this code:

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;

#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn wrong(arg: char) -> char {
    mir!({
        let temp = arg;
        RET = temp;
        temp = 'b';
        Return()
    })
}

fn main() {
    assert_eq!('a', wrong('a'));
}
$ rustc +master -Zmir-opt-level=0 -Zmir-enable-passes=+RenameReturnPlace test3.rs
$ ./test3
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `'a'`,
 right: `'b'`', test3.rs:16:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Meta

Reproduces on master at f5adff6bd8b29ac7dd173b36f0c8c35bb1c593c5, as well as

rustc --version --verbose:

rustc 1.71.0-nightly (7908a1d65 2023-04-17)
binary: rustc
commit-hash: 7908a1d65496b88626e4b7c193c81d777005d6f3
commit-date: 2023-04-17
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions