Skip to content

Commit

Permalink
Record the fact that rustc_peek has no side effects
Browse files Browse the repository at this point in the history
This means that calls to `rustc_peek` are no longer indirect definitions
of any locals in the body. Other pure intrinsics (e.g. `transmute`)
could also be added to the list of exceptions.
  • Loading branch information
ecstatic-morse committed Aug 8, 2019
1 parent 047e7ca commit 976ba13
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/librustc_mir/dataflow/impls/reaching_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ fn has_side_effects(
terminator: &mir::Terminator<'tcx>,
) -> bool {
match &terminator.kind {
mir::TerminatorKind::Call { .. } => true,
mir::TerminatorKind::Call { func, .. } => {
// Special-case some intrinsics that do not have side effects.
if let mir::Operand::Constant(func) = func {
if let ty::FnDef(def_id, _) = func.ty.sty {
if let Abi::RustIntrinsic = tcx.fn_sig(def_id).abi() {
match tcx.item_name(def_id) {
sym::rustc_peek => return false,
_ => (),
}
}
}
}

true
}

// Types with special drop glue may mutate their environment.
| mir::TerminatorKind::Drop { location: place, .. }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mir-dataflow/reaching-defs-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn foo(test: bool) -> (i32, i32) {
}

unsafe { rustc_peek(&x); }
//~^ ERROR rustc_peek: [16: "x=2", 17: "rustc_peek(&x)", 20: "x=3"]
//~^ ERROR rustc_peek: [16: "x=2", 20: "x=3"]

unsafe { rustc_peek(&y); }
//~^ ERROR rustc_peek: [13: "y=1", 21: "y=4"]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mir-dataflow/reaching-defs-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: rustc_peek: [16: "x=2"]
LL | unsafe { rustc_peek(&x); }
| ^^^^^^^^^^^^^^

error: rustc_peek: [16: "x=2", 17: "rustc_peek(&x)", 20: "x=3"]
error: rustc_peek: [16: "x=2", 20: "x=3"]
--> $DIR/reaching-defs-1.rs:24:14
|
LL | unsafe { rustc_peek(&x); }
Expand Down

0 comments on commit 976ba13

Please sign in to comment.