Skip to content

Commit cbc396f

Browse files
committed
inliner: Check for target features compatibility
1 parent 80cacd7 commit cbc396f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

compiler/rustc_mir/src/transform/inline.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_attr as attr;
44
use rustc_hir::def_id::DefId;
55
use rustc_index::bit_set::BitSet;
66
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};
88
use rustc_middle::mir::visit::*;
99
use rustc_middle::mir::*;
1010
use rustc_middle::ty::subst::{Subst, SubstsRef};
@@ -45,7 +45,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
4545
// based function.
4646
debug!("function inlining is disabled when compiling with `instrument_coverage`");
4747
} 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);
4950
}
5051
}
5152
}
@@ -54,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
5455
struct Inliner<'tcx> {
5556
tcx: TyCtxt<'tcx>,
5657
source: MirSource<'tcx>,
58+
codegen_fn_attrs: &'tcx CodegenFnAttrs,
5759
}
5860

5961
impl Inliner<'tcx> {
@@ -242,6 +244,13 @@ impl Inliner<'tcx> {
242244
return false;
243245
}
244246

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+
245254
// Avoid inlining functions marked as no_sanitize if sanitizer is enabled,
246255
// since instrumentation might be enabled and performed on the caller.
247256
if self.tcx.sess.opts.debugging_opts.sanitizer.intersects(codegen_fn_attrs.no_sanitize) {

0 commit comments

Comments
 (0)