@@ -30,19 +30,27 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
30
30
}
31
31
32
32
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
33
+ let def_id = body. source . def_id ( ) ;
33
34
let ctx = InstSimplifyContext {
34
35
tcx,
35
36
local_decls : & body. local_decls ,
36
37
typing_env : body. typing_env ( tcx) ,
37
38
} ;
38
39
let preserve_ub_checks =
39
40
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
+ } ;
40
46
for block in body. basic_blocks . as_mut ( ) {
41
47
for statement in block. statements . iter_mut ( ) {
42
48
match statement. kind {
43
49
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 ( ) ) ;
46
54
}
47
55
ctx. simplify_bool_cmp ( rvalue) ;
48
56
ctx. simplify_ref_deref ( rvalue) ;
@@ -181,9 +189,9 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
181
189
}
182
190
}
183
191
184
- fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > ) {
192
+ fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > , ub_checks : bool ) {
185
193
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) ;
187
195
let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
188
196
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
189
197
}
0 commit comments