@@ -11,7 +11,7 @@ use rustc_mir_dataflow::value_analysis::{
1111 HasTop , Map , State , TrackElem , ValueAnalysis , ValueOrPlace , ValueOrPlaceOrRef ,
1212} ;
1313use rustc_mir_dataflow:: { lattice:: FlatSet , Analysis , ResultsVisitor , SwitchIntEdgeEffects } ;
14- use rustc_span:: { sym , DUMMY_SP } ;
14+ use rustc_span:: DUMMY_SP ;
1515
1616use crate :: MirPass ;
1717
@@ -42,7 +42,6 @@ struct ConstAnalysis<'tcx> {
4242 tcx : TyCtxt < ' tcx > ,
4343 ecx : InterpCx < ' tcx , ' tcx , DummyMachine > ,
4444 param_env : ty:: ParamEnv < ' tcx > ,
45- propagate_overflow : bool ,
4645}
4746
4847impl < ' tcx > ValueAnalysis < ' tcx > for ConstAnalysis < ' tcx > {
@@ -84,13 +83,11 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
8483 let overflow = match overflow {
8584 FlatSet :: Top => FlatSet :: Top ,
8685 FlatSet :: Elem ( overflow) => {
87- if overflow && !self . propagate_overflow {
86+ if overflow {
87+ // Overflow cannot be reliable propagated. See: https://github.com/rust-lang/rust/pull/101168#issuecomment-1288091446
8888 FlatSet :: Top
8989 } else {
90- self . wrap_scalar (
91- Scalar :: from_bool ( overflow) ,
92- self . tcx . types . bool ,
93- )
90+ self . wrap_scalar ( Scalar :: from_bool ( false ) , self . tcx . types . bool )
9491 }
9592 }
9693 FlatSet :: Bottom => FlatSet :: Bottom ,
@@ -220,20 +217,11 @@ impl<'tcx> std::fmt::Debug for ScalarTy<'tcx> {
220217
221218impl < ' tcx > ConstAnalysis < ' tcx > {
222219 pub fn new ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > , map : Map ) -> Self {
223- // It can happen that overflow will be detected even though overflow checks are disabled.
224- // This is caused by inlining functions that have #[rustc_inherit_overflow_checks]. Such
225- // overflows must not be propagated if `-C overflow-checks=off`. Also, if the function we
226- // are optimizing here has #[rustc_inherit_overflow_checks], the overflow checks may
227- // actually not be triggered by the consuming crate, so we have to ignore them too.
228- // Related to https://github.com/rust-lang/rust/issues/35310.
229- let propagate_overflow = tcx. sess . overflow_checks ( )
230- && !tcx. has_attr ( body. source . def_id ( ) , sym:: rustc_inherit_overflow_checks) ;
231220 Self {
232221 map,
233222 tcx,
234223 ecx : InterpCx :: new ( tcx, DUMMY_SP , ty:: ParamEnv :: empty ( ) , DummyMachine ) ,
235224 param_env : tcx. param_env ( body. source . def_id ( ) ) ,
236- propagate_overflow,
237225 }
238226 }
239227
0 commit comments