From 16dedba1c80e96e7b0481191d4ae16e2d8cb0016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannis=20Christopher=20K=C3=B6hl?= Date: Fri, 2 Sep 2022 00:37:38 +0200 Subject: [PATCH] Ignore terminators explicitly --- .../rustc_mir_dataflow/src/value_analysis.rs | 20 ++++++++++++++----- .../src/dataflow_const_prop.rs | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 64e45083fc07..5fe768f83106 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -146,10 +146,7 @@ pub trait ValueAnalysis<'tcx> { Rvalue::CopyForDeref(place) => { self.handle_operand(&Operand::Copy(*place), state).into() } - _ => { - // FIXME: Check that other Rvalues really have no side-effect. - ValueOrPlaceOrRef::Unknown - } + _ => ValueOrPlaceOrRef::Unknown, } } @@ -200,7 +197,20 @@ pub trait ValueAnalysis<'tcx> { self.super_terminator(terminator, state) } - fn super_terminator(&self, _terminator: &Terminator<'tcx>, _state: &mut State) {} + fn super_terminator(&self, terminator: &Terminator<'tcx>, _state: &mut State) { + match &terminator.kind { + TerminatorKind::Call { .. } | TerminatorKind::InlineAsm { .. } => { + // Effect is applied by `handle_call_return`. + } + TerminatorKind::DropAndReplace { .. } | TerminatorKind::Yield { .. } => { + // They would have an effect, but are not allowed in this phase. + bug!("encountered disallowed terminator"); + } + _ => { + // The other terminators can be ignored. + } + } + } fn handle_call_return( &self, diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index f461514716e6..c80ff3dd3ec7 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -35,7 +35,6 @@ impl<'tcx> MirPass<'tcx> for DataflowConstProp { } } -// FIXME: Consider support for discriminants, mutable references, arrays and slices. struct ConstAnalysis<'tcx> { map: Map, tcx: TyCtxt<'tcx>,