Skip to content

Commit

Permalink
inliner: Check for target features compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Sep 4, 2020
1 parent 80cacd7 commit cbc396f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_mir/src/transform/inline.rs
Expand Up @@ -4,7 +4,7 @@ use rustc_attr as attr;
use rustc_hir::def_id::DefId;
use rustc_index::bit_set::BitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::subst::{Subst, SubstsRef};
Expand Down Expand Up @@ -45,7 +45,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
// based function.
debug!("function inlining is disabled when compiling with `instrument_coverage`");
} else {
Inliner { tcx, source }.run_pass(body);
Inliner { tcx, source, codegen_fn_attrs: tcx.codegen_fn_attrs(source.def_id()) }
.run_pass(body);
}
}
}
Expand All @@ -54,6 +55,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
struct Inliner<'tcx> {
tcx: TyCtxt<'tcx>,
source: MirSource<'tcx>,
codegen_fn_attrs: &'tcx CodegenFnAttrs,
}

impl Inliner<'tcx> {
Expand Down Expand Up @@ -242,6 +244,13 @@ impl Inliner<'tcx> {
return false;
}

let self_features = &self.codegen_fn_attrs.target_features;
let callee_features = &codegen_fn_attrs.target_features;
if callee_features.iter().any(|feature| !self_features.contains(feature)) {
debug!("`callee has extra target features - not inlining");
return false;
}

// Avoid inlining functions marked as no_sanitize if sanitizer is enabled,
// since instrumentation might be enabled and performed on the caller.
if self.tcx.sess.opts.debugging_opts.sanitizer.intersects(codegen_fn_attrs.no_sanitize) {
Expand Down

0 comments on commit cbc396f

Please sign in to comment.