Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check type of place base (not projection) for Freeze in IndirectlyMutableLocals #65030

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/test/ui/mir-dataflow/indirect-mutation-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#![feature(core_intrinsics, rustc_attrs, const_raw_ptr_deref)]
oli-obk marked this conversation as resolved.
Show resolved Hide resolved

use std::cell::Cell;
use std::intrinsics::rustc_peek;

#[rustc_mir(rustc_peek_indirectly_mutable, stop_after_dataflow)]
pub fn mut_ref(flag: bool) -> i32 {
let mut i = 0;
let cell = Cell::new(0);

if flag {
let p = &mut i;
unsafe { rustc_peek(i) };
*p = 1;

let p = &cell;
unsafe { rustc_peek(cell) };
p.set(2);
} else {
unsafe { rustc_peek(i) }; //~ ERROR rustc_peek: bit not set
unsafe { rustc_peek(cell) }; //~ ERROR rustc_peek: bit not set

let p = &mut cell;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cell is immutable, how does this line not error?

Copy link
Contributor Author

@ecstatic-morse ecstatic-morse Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stop_after_dataflow prevents later all subsequent compiler passes from running, so we never actually get to the pass that would fail on this broken code. I'll make sure these tests compile outside of rustc_peek mode when possible though.

unsafe { rustc_peek(cell) };
*p = Cell::new(3);
}

unsafe { rustc_peek(i) };
unsafe { rustc_peek(cell) };
i + cell.get()
}

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/mir-dataflow/indirect-mutation-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: rustc_peek: bit not set
--> $DIR/indirect-mutation-1.rs:20:18
|
LL | unsafe { rustc_peek(i) };
| ^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/indirect-mutation-1.rs:21:18
|
LL | unsafe { rustc_peek(cell) };
| ^^^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

error: aborting due to 3 previous errors

30 changes: 30 additions & 0 deletions src/test/ui/mir-dataflow/indirect-mutation-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![feature(core_intrinsics, rustc_attrs, const_raw_ptr_deref)]

use std::cell::Cell;
use std::intrinsics::rustc_peek;

struct Arr {
inner: [Cell<i32>; 0],
_peek: (),
}

// Zero-sized arrays are never mutable.
#[rustc_mir(rustc_peek_indirectly_mutable, stop_after_dataflow)]
pub fn zst(flag: bool) {
{
let arr: [i32; 0] = [];
let s: &mut [i32] = &mut arr;
unsafe { rustc_peek(arr) }; //~ ERROR rustc_peek: bit not set
}

{
let arr: [Cell<i32>; 0] = [];
let s: &[Cell<i32>] = &arr;
unsafe { rustc_peek(arr) }; //~ ERROR rustc_peek: bit not set

let ss = &s;
unsafe { rustc_peek(arr) }; //~ ERROR rustc_peek: bit not set
}
}

fn main() {}
22 changes: 22 additions & 0 deletions src/test/ui/mir-dataflow/indirect-mutation-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error: rustc_peek: bit not set
--> $DIR/indirect-mutation-2.rs:17:18
|
LL | unsafe { rustc_peek(arr) };
| ^^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/indirect-mutation-2.rs:23:18
|
LL | unsafe { rustc_peek(arr) };
| ^^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/indirect-mutation-2.rs:26:18
|
LL | unsafe { rustc_peek(arr) };
| ^^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

error: aborting due to 4 previous errors