@@ -4,7 +4,7 @@ use rustc_attr as attr;
4
4
use rustc_hir:: def_id:: DefId ;
5
5
use rustc_index:: bit_set:: BitSet ;
6
6
use rustc_index:: vec:: { Idx , IndexVec } ;
7
- use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
7
+ use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
8
8
use rustc_middle:: mir:: visit:: * ;
9
9
use rustc_middle:: mir:: * ;
10
10
use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
@@ -45,7 +45,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
45
45
// based function.
46
46
debug ! ( "function inlining is disabled when compiling with `instrument_coverage`" ) ;
47
47
} else {
48
- Inliner { tcx, source } . run_pass ( body) ;
48
+ Inliner { tcx, source, codegen_fn_attrs : tcx. codegen_fn_attrs ( source. def_id ( ) ) }
49
+ . run_pass ( body) ;
49
50
}
50
51
}
51
52
}
@@ -54,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
54
55
struct Inliner < ' tcx > {
55
56
tcx : TyCtxt < ' tcx > ,
56
57
source : MirSource < ' tcx > ,
58
+ codegen_fn_attrs : & ' tcx CodegenFnAttrs ,
57
59
}
58
60
59
61
impl Inliner < ' tcx > {
@@ -242,9 +244,19 @@ impl Inliner<'tcx> {
242
244
return false ;
243
245
}
244
246
245
- // Avoid inlining functions marked as no_sanitize if sanitizer is enabled,
246
- // since instrumentation might be enabled and performed on the caller.
247
- if self . tcx . sess . opts . debugging_opts . sanitizer . intersects ( codegen_fn_attrs. no_sanitize ) {
247
+ let self_features = & self . codegen_fn_attrs . target_features ;
248
+ let callee_features = & codegen_fn_attrs. target_features ;
249
+ if callee_features. iter ( ) . any ( |feature| !self_features. contains ( feature) ) {
250
+ debug ! ( "`callee has extra target features - not inlining" ) ;
251
+ return false ;
252
+ }
253
+
254
+ let self_no_sanitize =
255
+ self . codegen_fn_attrs . no_sanitize & self . tcx . sess . opts . debugging_opts . sanitizer ;
256
+ let callee_no_sanitize =
257
+ codegen_fn_attrs. no_sanitize & self . tcx . sess . opts . debugging_opts . sanitizer ;
258
+ if self_no_sanitize != callee_no_sanitize {
259
+ debug ! ( "`callee has incompatible no_sanitize attribute - not inlining" ) ;
248
260
return false ;
249
261
}
250
262
0 commit comments