@@ -31,19 +31,27 @@ impl<'tcx> crate::MirPass<'tcx> for InstSimplify {
31
31
}
32
32
33
33
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
34
+ let def_id = body. source . def_id ( ) ;
34
35
let ctx = InstSimplifyContext {
35
36
tcx,
36
37
local_decls : & body. local_decls ,
37
38
typing_env : body. typing_env ( tcx) ,
38
39
} ;
39
40
let preserve_ub_checks =
40
41
attr:: contains_name ( tcx. hir ( ) . krate_attrs ( ) , sym:: rustc_preserve_ub_checks) ;
42
+ let remove_ub_checks = if tcx. is_coroutine ( def_id) {
43
+ false
44
+ } else {
45
+ tcx. has_attr ( def_id, sym:: rustc_no_ubchecks)
46
+ } ;
41
47
for block in body. basic_blocks . as_mut ( ) {
42
48
for statement in block. statements . iter_mut ( ) {
43
49
match statement. kind {
44
50
StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
45
- if !preserve_ub_checks {
46
- ctx. simplify_ub_check ( rvalue) ;
51
+ if remove_ub_checks {
52
+ ctx. simplify_ub_check ( rvalue, false ) ;
53
+ } else if !preserve_ub_checks {
54
+ ctx. simplify_ub_check ( rvalue, tcx. sess . ub_checks ( ) ) ;
47
55
}
48
56
ctx. simplify_bool_cmp ( rvalue) ;
49
57
ctx. simplify_ref_deref ( rvalue) ;
@@ -160,9 +168,9 @@ impl<'tcx> InstSimplifyContext<'_, 'tcx> {
160
168
}
161
169
}
162
170
163
- fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > ) {
171
+ fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > , ub_checks : bool ) {
164
172
if let Rvalue :: NullaryOp ( NullOp :: UbChecks , _) = * rvalue {
165
- let const_ = Const :: from_bool ( self . tcx , self . tcx . sess . ub_checks ( ) ) ;
173
+ let const_ = Const :: from_bool ( self . tcx , ub_checks) ;
166
174
let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
167
175
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
168
176
}
0 commit comments