Skip to content

Commit 0b4af16

Browse files
committed
Never inline when no_sanitize attributes differ
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.
1 parent 9722952 commit 0b4af16

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

compiler/rustc_mir/src/transform/inline.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,7 @@ impl Inliner<'tcx> {
218218
return false;
219219
}
220220

221-
let self_no_sanitize =
222-
self.codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
223-
let callee_no_sanitize =
224-
codegen_fn_attrs.no_sanitize & self.tcx.sess.opts.debugging_opts.sanitizer;
225-
if self_no_sanitize != callee_no_sanitize {
221+
if self.codegen_fn_attrs.no_sanitize != codegen_fn_attrs.no_sanitize {
226222
debug!("`callee has incompatible no_sanitize attribute - not inlining");
227223
return false;
228224
}

src/test/mir-opt/inline/inline-compatibility.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Checks that only functions with compatible attributes are inlined.
22
//
33
// only-x86_64
4-
// needs-sanitizer-address
5-
// compile-flags: -Zsanitizer=address
64

75
#![crate_type = "lib"]
86
#![feature(no_sanitize)]
@@ -35,5 +33,5 @@ pub unsafe fn not_inlined_no_sanitize() {
3533
pub unsafe fn target_feature() {}
3634

3735
#[inline]
38-
#[no_sanitize(address, memory)]
36+
#[no_sanitize(address)]
3937
pub unsafe fn no_sanitize() {}

0 commit comments

Comments
 (0)