diff --git a/src/librustc_mir/dataflow/impls/reaching_defs.rs b/src/librustc_mir/dataflow/impls/reaching_defs.rs index f52895ef1c1ee..017121784e704 100644 --- a/src/librustc_mir/dataflow/impls/reaching_defs.rs +++ b/src/librustc_mir/dataflow/impls/reaching_defs.rs @@ -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, .. } diff --git a/src/test/ui/mir-dataflow/reaching-defs-1.rs b/src/test/ui/mir-dataflow/reaching-defs-1.rs index 25dd7ae32f22e..054fe232230e3 100644 --- a/src/test/ui/mir-dataflow/reaching-defs-1.rs +++ b/src/test/ui/mir-dataflow/reaching-defs-1.rs @@ -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"] diff --git a/src/test/ui/mir-dataflow/reaching-defs-1.stderr b/src/test/ui/mir-dataflow/reaching-defs-1.stderr index a5e8fe5464125..4c99a47571dd0 100644 --- a/src/test/ui/mir-dataflow/reaching-defs-1.stderr +++ b/src/test/ui/mir-dataflow/reaching-defs-1.stderr @@ -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); }