@@ -26,8 +26,8 @@ use rustc_hir::def_id::LocalDefId;
26
26
use rustc_index:: IndexVec ;
27
27
use rustc_middle:: mir:: {
28
28
AnalysisPhase , Body , CallSource , ClearCrossCrate , ConstOperand , ConstQualifs , LocalDecl ,
29
- MirPhase , Operand , Place , ProjectionElem , Promoted , RuntimePhase , Rvalue , START_BLOCK ,
30
- SourceInfo , Statement , StatementKind , TerminatorKind ,
29
+ MirFlags , MirPhase , Operand , Place , ProjectionElem , Promoted , RuntimePhase , Rvalue ,
30
+ START_BLOCK , SourceInfo , Statement , StatementKind , TerminatorKind ,
31
31
} ;
32
32
use rustc_middle:: ty:: { self , TyCtxt , TypeVisitableExt } ;
33
33
use rustc_middle:: util:: Providers ;
@@ -134,7 +134,7 @@ pub fn provide(providers: &mut Providers) {
134
134
promoted_mir,
135
135
deduced_param_attrs : deduce_param_attrs:: deduced_param_attrs,
136
136
coroutine_by_move_body_def_id : coroutine:: coroutine_by_move_body_def_id,
137
- is_nounwind ,
137
+ mir_flags ,
138
138
..providers. queries
139
139
} ;
140
140
}
@@ -331,15 +331,14 @@ fn mir_promoted(
331
331
_ => ConstQualifs :: default ( ) ,
332
332
} ;
333
333
334
- // the `has_ffi_unwind_calls` query uses the raw mir, so make sure it is run.
335
- tcx. ensure_with_value ( ) . has_ffi_unwind_calls ( def) ;
334
+ tcx. ensure_with_value ( ) . mir_flags ( def) ;
336
335
337
336
// the `by_move_body` query uses the raw mir, so make sure it is run.
338
337
if tcx. needs_coroutine_by_move_body_def_id ( def. to_def_id ( ) ) {
339
338
tcx. ensure_with_value ( ) . coroutine_by_move_body_def_id ( def) ;
340
339
}
341
340
342
- tcx. ensure_with_value ( ) . is_nounwind ( def) ;
341
+ tcx. ensure_with_value ( ) . mir_flags ( def) ;
343
342
344
343
let mut body = tcx. mir_built ( def) . steal ( ) ;
345
344
if let Some ( error_reported) = const_qualifs. tainted_by_errors {
@@ -363,22 +362,31 @@ fn mir_promoted(
363
362
( tcx. alloc_steal_mir ( body) , tcx. alloc_steal_promoted ( promoted) )
364
363
}
365
364
366
- fn is_nounwind < ' tcx > ( tcx : TyCtxt < ' tcx > , local_def_id : LocalDefId ) -> bool {
365
+ fn mir_flags < ' tcx > ( tcx : TyCtxt < ' tcx > , local_def_id : LocalDefId ) -> MirFlags {
366
+ let mut flags = MirFlags :: default ( ) ;
367
367
if !tcx. is_mir_available ( local_def_id) {
368
- return false ;
368
+ return flags ;
369
369
}
370
370
371
- let def_id = local_def_id . to_def_id ( ) ;
372
- let kind = tcx. def_kind ( def_id ) ;
371
+ // Only perform check on functions because constants cannot call FFI functions.
372
+ let kind = tcx. def_kind ( local_def_id ) ;
373
373
if !kind. is_fn_like ( ) {
374
- return false ;
374
+ return flags ;
375
375
}
376
376
377
377
let body = & * tcx. mir_built ( local_def_id) . borrow ( ) ;
378
- if body. basic_blocks . iter ( ) . all ( |block| block. terminator ( ) . unwind ( ) . is_none ( ) ) {
379
- return true ;
378
+
379
+ if is_nounwind ( body) {
380
+ flags. insert ( MirFlags :: IS_NOUNWIND ) ;
381
+ }
382
+ if ffi_unwind_calls:: has_ffi_unwind_calls ( tcx, body) {
383
+ flags. insert ( MirFlags :: HAS_FFI_UNWIND_CALLS ) ;
380
384
}
381
- false
385
+ flags
386
+ }
387
+
388
+ fn is_nounwind < ' tcx > ( body : & Body < ' tcx > ) -> bool {
389
+ body. basic_blocks . iter ( ) . all ( |block| block. terminator ( ) . unwind ( ) . is_none ( ) )
382
390
}
383
391
384
392
/// Compute the MIR that is used during CTFE (and thus has no optimizations run on it)
0 commit comments