Closed
Description
This code has UB under Stacked Borrows in Miri, but is fine with -Zmiri-tree-borrows
, and it should print false
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn0() -> bool {
mir! {
type RET = bool;
let pair: (i8, bool);
let ptr: *mut bool;
{
pair = (1, false);
ptr = core::ptr::addr_of_mut!(pair.1);
RET = pair.1 <= (*ptr);
pair = (1, false);
(*ptr) = RET | RET;
RET = !pair.1;
Return()
}
}
}
pub fn main() {
println!("{}", fn0());
}
However, under -Zmir-opt-level=2
and above, it prints true
% rustc -Zmir-opt-level=2 repro.rs && ./repro
true
Meta
rustc --version --verbose
:
rustc 1.71.0-nightly (1c42cb4ef 2023-04-26)
binary: rustc
commit-hash: 1c42cb4ef0544fbfaa500216e53382d6b079c001
commit-date: 2023-04-26
host: aarch64-apple-darwin
release: 1.71.0-nightly
LLVM version: 16.0.2