@@ -11,7 +11,7 @@ use rustc_mir_dataflow::value_analysis::{
11
11
HasTop , Map , State , TrackElem , ValueAnalysis , ValueOrPlace , ValueOrPlaceOrRef ,
12
12
} ;
13
13
use rustc_mir_dataflow:: { lattice:: FlatSet , Analysis , ResultsVisitor , SwitchIntEdgeEffects } ;
14
- use rustc_span:: { sym , DUMMY_SP } ;
14
+ use rustc_span:: DUMMY_SP ;
15
15
16
16
use crate :: MirPass ;
17
17
@@ -42,7 +42,6 @@ struct ConstAnalysis<'tcx> {
42
42
tcx : TyCtxt < ' tcx > ,
43
43
ecx : InterpCx < ' tcx , ' tcx , DummyMachine > ,
44
44
param_env : ty:: ParamEnv < ' tcx > ,
45
- propagate_overflow : bool ,
46
45
}
47
46
48
47
impl < ' tcx > ValueAnalysis < ' tcx > for ConstAnalysis < ' tcx > {
@@ -84,13 +83,11 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'tcx> {
84
83
let overflow = match overflow {
85
84
FlatSet :: Top => FlatSet :: Top ,
86
85
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
88
88
FlatSet :: Top
89
89
} 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 )
94
91
}
95
92
}
96
93
FlatSet :: Bottom => FlatSet :: Bottom ,
@@ -220,20 +217,11 @@ impl<'tcx> std::fmt::Debug for ScalarTy<'tcx> {
220
217
221
218
impl < ' tcx > ConstAnalysis < ' tcx > {
222
219
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) ;
231
220
Self {
232
221
map,
233
222
tcx,
234
223
ecx : InterpCx :: new ( tcx, DUMMY_SP , ty:: ParamEnv :: empty ( ) , DummyMachine ) ,
235
224
param_env : tcx. param_env ( body. source . def_id ( ) ) ,
236
- propagate_overflow,
237
225
}
238
226
}
239
227
0 commit comments