Open
Description
openedon Oct 17, 2024
Considering the following code, it should print 0 with a release build, but I get a segmentation violation.
#![feature(rustc_attrs)]
#![allow(internal_features)]
#![allow(dead_code)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_layout_scalar_valid_range_end(0xfffffffffffffff0)]
pub struct RestrictedAddress(&'static i8);
enum E {
A(RestrictedAddress),
B,
C,
}
#[no_mangle]
#[inline(never)]
fn foo(a: E) -> i8 {
match a {
E::A(v) => *v.0,
_ => 0,
}
}
fn main() {
println!("{}", foo(std::hint::black_box(E::B)));
}
This is because we are adding the dereferenceable
attribute, which allows LLVM to hoist the load instruction. In this case, we need to drop the dereferenceable
attribute.
@rustbot label +requires-nightly +I-miscompile +A-codegen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment