@@ -30,19 +30,27 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
3030 }
3131
3232 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
33+ let def_id = body. source . def_id ( ) ;
3334 let ctx = InstSimplifyContext {
3435 tcx,
3536 local_decls : & body. local_decls ,
3637 typing_env : body. typing_env ( tcx) ,
3738 } ;
3839 let preserve_ub_checks =
3940 attr:: contains_name ( tcx. hir ( ) . krate_attrs ( ) , sym:: rustc_preserve_ub_checks) ;
41+ let remove_ub_checks = if tcx. is_coroutine ( def_id) {
42+ false
43+ } else {
44+ tcx. has_attr ( def_id, sym:: rustc_no_ubchecks)
45+ } ;
4046 for block in body. basic_blocks . as_mut ( ) {
4147 for statement in block. statements . iter_mut ( ) {
4248 match statement. kind {
4349 StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
44- if !preserve_ub_checks {
45- ctx. simplify_ub_check ( rvalue) ;
50+ if remove_ub_checks {
51+ ctx. simplify_ub_check ( rvalue, false ) ;
52+ } else if !preserve_ub_checks {
53+ ctx. simplify_ub_check ( rvalue, tcx. sess . ub_checks ( ) ) ;
4654 }
4755 ctx. simplify_bool_cmp ( rvalue) ;
4856 ctx. simplify_ref_deref ( rvalue) ;
@@ -181,9 +189,9 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
181189 }
182190 }
183191
184- fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > ) {
192+ fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > , ub_checks : bool ) {
185193 if let Rvalue :: NullaryOp ( NullOp :: UbChecks , _) = * rvalue {
186- let const_ = Const :: from_bool ( self . tcx , self . tcx . sess . ub_checks ( ) ) ;
194+ let const_ = Const :: from_bool ( self . tcx , ub_checks) ;
187195 let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
188196 * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
189197 }
0 commit comments