@@ -37,19 +37,27 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
37
37
}
38
38
39
39
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
40
+ let def_id = body. source . def_id ( ) ;
40
41
let ctx = InstSimplifyContext {
41
42
tcx,
42
43
local_decls : & body. local_decls ,
43
- param_env : tcx. param_env_reveal_all_normalized ( body . source . def_id ( ) ) ,
44
+ param_env : tcx. param_env_reveal_all_normalized ( def_id) ,
44
45
} ;
45
46
let preserve_ub_checks =
46
47
attr:: contains_name ( tcx. hir ( ) . krate_attrs ( ) , sym:: rustc_preserve_ub_checks) ;
48
+ let remove_ub_checks = tcx. has_attr ( def_id, sym:: rustc_no_ubchecks) ;
47
49
for block in body. basic_blocks . as_mut ( ) {
48
50
for statement in block. statements . iter_mut ( ) {
49
51
match statement. kind {
50
52
StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
51
- if !preserve_ub_checks {
52
- ctx. simplify_ub_check ( & statement. source_info , rvalue) ;
53
+ if remove_ub_checks {
54
+ ctx. simplify_ub_check ( & statement. source_info , rvalue, false ) ;
55
+ } else if !preserve_ub_checks {
56
+ ctx. simplify_ub_check (
57
+ & statement. source_info ,
58
+ rvalue,
59
+ tcx. sess . ub_checks ( ) ,
60
+ ) ;
53
61
}
54
62
ctx. simplify_bool_cmp ( & statement. source_info , rvalue) ;
55
63
ctx. simplify_ref_deref ( & statement. source_info , rvalue) ;
@@ -199,9 +207,14 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
199
207
}
200
208
}
201
209
202
- fn simplify_ub_check ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
210
+ fn simplify_ub_check (
211
+ & self ,
212
+ source_info : & SourceInfo ,
213
+ rvalue : & mut Rvalue < ' tcx > ,
214
+ ub_checks : bool ,
215
+ ) {
203
216
if let Rvalue :: NullaryOp ( NullOp :: UbChecks , _) = * rvalue {
204
- let const_ = Const :: from_bool ( self . tcx , self . tcx . sess . ub_checks ( ) ) ;
217
+ let const_ = Const :: from_bool ( self . tcx , ub_checks) ;
205
218
let constant = ConstOperand { span : source_info. span , const_, user_ty : None } ;
206
219
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
207
220
}
0 commit comments