Test that Miri can handle MIR with NRVO applied

This commit is contained in:
Dylan MacKenzie 2020-05-16 12:15:25 -07:00
parent e369d7f4e7
commit c38283d7a7
2 changed files with 50 additions and 0 deletions

View file

@ -0,0 +1,23 @@
// compile-flags: -Zunleash-the-miri-inside-of-you
// run-pass
const fn init(buf: &mut [u8; 1024]) {
buf[33] = 3;
buf[444] = 4;
}
const fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
let mut buf = [0; 1024];
init(&mut buf);
buf
}
// When the NRVO is applied, the return place (`_0`) gets treated like a normal local. For example,
// its address may be taken and it may be written to indirectly. Ensure that MIRI can handle this.
const BUF: [u8; 1024] = nrvo(init);
fn main() {
assert_eq!(BUF[33], 3);
assert_eq!(BUF[19], 0);
assert_eq!(BUF[444], 4);
}

View file

@ -0,0 +1,27 @@
warning: skipping const checks
|
help: skipping check for `const_mut_refs` feature
--> $DIR/nrvo.rs:5:5
|
LL | buf[33] = 3;
| ^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/nrvo.rs:6:5
|
LL | buf[444] = 4;
| ^^^^^^^^^^^^
help: skipping check for `const_mut_refs` feature
--> $DIR/nrvo.rs:11:10
|
LL | init(&mut buf);
| ^^^^^^^^
help: skipping check that does not even have a feature gate
--> $DIR/nrvo.rs:11:5
|
LL | init(&mut buf);
| ^^^^^^^^^^^^^^
error: `-Zunleash-the-miri-inside-of-you` may not be used to circumvent feature gates, except when testing error paths in the CTFE engine
error: aborting due to previous error; 1 warning emitted