@@ -30,21 +30,29 @@ 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
let StatementKind :: Assign ( box ( .., rvalue) ) = & mut statement. kind else {
43
49
continue ;
44
50
} ;
45
51
46
- if !preserve_ub_checks {
47
- ctx. simplify_ub_check ( rvalue) ;
52
+ if remove_ub_checks {
53
+ ctx. simplify_ub_check ( rvalue, false ) ;
54
+ } else if !preserve_ub_checks {
55
+ ctx. simplify_ub_check ( rvalue, tcx. sess . ub_checks ( ) ) ;
48
56
}
49
57
ctx. simplify_bool_cmp ( rvalue) ;
50
58
ctx. simplify_ref_deref ( rvalue) ;
@@ -168,10 +176,10 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
168
176
}
169
177
}
170
178
171
- fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > ) {
179
+ fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > , ub_checks : bool ) {
172
180
let Rvalue :: NullaryOp ( NullOp :: UbChecks , _) = * rvalue else { return } ;
173
181
174
- let const_ = Const :: from_bool ( self . tcx , self . tcx . sess . ub_checks ( ) ) ;
182
+ let const_ = Const :: from_bool ( self . tcx , ub_checks) ;
175
183
let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
176
184
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
177
185
}
0 commit comments