Skip to content

Commit

Permalink
Never inline when no_sanitize attributes differ
Browse files Browse the repository at this point in the history
The inliner looks if a sanitizer is enabled before considering
`no_sanitize` attribute as possible source of incompatibility.

The MIR inlining could happen in a crate with sanitizer disabled, but
code generation in a crate with sanitizer enabled, thus the attribute
would be incorrectly ignored.

To avoid the issue never inline functions with different `no_sanitize`
attributes.
  • Loading branch information
tmiasko committed Nov 12, 2020
1 parent 9722952 commit 0b4af16
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_mir/src/transform/inline.rs
Expand Up @@ -218,11 +218,7 @@ impl Inliner<'tcx> {
return false;
}

let self_no_sanitize =
self.codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
let callee_no_sanitize =
codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
if self_no_sanitize != callee_no_sanitize {
if self.codegen_fn_attrs.no_sanitize != codegen_fn_attrs.no_sanitize {
debug!("`callee has incompatible no_sanitize attribute - not inlining");
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions src/test/mir-opt/inline/inline-compatibility.rs
@@ -1,8 +1,6 @@
// Checks that only functions with compatible attributes are inlined.
//
// only-x86_64
// needs-sanitizer-address
// compile-flags: -Zsanitizer=address

#![crate_type = "lib"]
#![feature(no_sanitize)]
Expand Down Expand Up @@ -35,5 +33,5 @@ pub unsafe fn not_inlined_no_sanitize() {
pub unsafe fn target_feature() {}

#[inline]
#[no_sanitize(address, memory)]
#[no_sanitize(address)]
pub unsafe fn no_sanitize() {}

0 comments on commit 0b4af16

Please sign in to comment.