Rollup merge of #99207 - 5225225:msan-eager-checks, r=jackh726
Enable eager checks for memory sanitizer Fixes #99179
This commit is contained in:
commit
6d2033512b
4 changed files with 67 additions and 5 deletions
|
@ -19,6 +19,7 @@ use rustc_target::abi::call::ArgAbi;
|
||||||
pub use rustc_target::abi::call::*;
|
pub use rustc_target::abi::call::*;
|
||||||
use rustc_target::abi::{self, HasDataLayout, Int};
|
use rustc_target::abi::{self, HasDataLayout, Int};
|
||||||
pub use rustc_target::spec::abi::Abi;
|
pub use rustc_target::spec::abi::Abi;
|
||||||
|
use rustc_target::spec::SanitizerSet;
|
||||||
|
|
||||||
use libc::c_uint;
|
use libc::c_uint;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -90,6 +91,13 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'
|
||||||
if regular.contains(ArgAttribute::NoAliasMutRef) && should_use_mutable_noalias(cx) {
|
if regular.contains(ArgAttribute::NoAliasMutRef) && should_use_mutable_noalias(cx) {
|
||||||
attrs.push(llvm::AttributeKind::NoAlias.create_attr(cx.llcx));
|
attrs.push(llvm::AttributeKind::NoAlias.create_attr(cx.llcx));
|
||||||
}
|
}
|
||||||
|
} else if cx.tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) {
|
||||||
|
// If we're not optimising, *but* memory sanitizer is on, emit noundef, since it affects
|
||||||
|
// memory sanitizer's behavior.
|
||||||
|
|
||||||
|
if regular.contains(ArgAttribute::NoUndef) {
|
||||||
|
attrs.push(llvm::AttributeKind::NoUndef.create_attr(cx.llcx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs
|
attrs
|
||||||
|
|
|
@ -134,7 +134,12 @@ extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool
|
||||||
const bool CompileKernel = false;
|
const bool CompileKernel = false;
|
||||||
|
|
||||||
return wrap(createMemorySanitizerLegacyPassPass(
|
return wrap(createMemorySanitizerLegacyPassPass(
|
||||||
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
|
#if LLVM_VERSION_GE(14, 0)
|
||||||
|
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel, /*EagerChecks=*/true}
|
||||||
|
#else
|
||||||
|
MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}
|
||||||
|
#endif
|
||||||
|
));
|
||||||
#else
|
#else
|
||||||
report_fatal_error("Legacy PM not supported with LLVM 15");
|
report_fatal_error("Legacy PM not supported with LLVM 15");
|
||||||
#endif
|
#endif
|
||||||
|
@ -930,10 +935,18 @@ LLVMRustOptimizeWithNewPassManager(
|
||||||
|
|
||||||
if (SanitizerOptions) {
|
if (SanitizerOptions) {
|
||||||
if (SanitizerOptions->SanitizeMemory) {
|
if (SanitizerOptions->SanitizeMemory) {
|
||||||
|
#if LLVM_VERSION_GE(14, 0)
|
||||||
|
MemorySanitizerOptions Options(
|
||||||
|
SanitizerOptions->SanitizeMemoryTrackOrigins,
|
||||||
|
SanitizerOptions->SanitizeMemoryRecover,
|
||||||
|
/*CompileKernel=*/false,
|
||||||
|
/*EagerChecks=*/true);
|
||||||
|
#else
|
||||||
MemorySanitizerOptions Options(
|
MemorySanitizerOptions Options(
|
||||||
SanitizerOptions->SanitizeMemoryTrackOrigins,
|
SanitizerOptions->SanitizeMemoryTrackOrigins,
|
||||||
SanitizerOptions->SanitizeMemoryRecover,
|
SanitizerOptions->SanitizeMemoryRecover,
|
||||||
/*CompileKernel=*/false);
|
/*CompileKernel=*/false);
|
||||||
|
#endif
|
||||||
OptimizerLastEPCallbacks.push_back(
|
OptimizerLastEPCallbacks.push_back(
|
||||||
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
|
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||||
#if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0)
|
#if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0)
|
||||||
|
|
38
src/test/ui/sanitize/memory-eager.rs
Normal file
38
src/test/ui/sanitize/memory-eager.rs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
// needs-sanitizer-support
|
||||||
|
// needs-sanitizer-memory
|
||||||
|
// min-llvm-version: 14.0.0
|
||||||
|
//
|
||||||
|
// revisions: unoptimized optimized
|
||||||
|
//
|
||||||
|
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
|
||||||
|
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
|
||||||
|
//
|
||||||
|
// run-fail
|
||||||
|
// error-pattern: MemorySanitizer: use-of-uninitialized-value
|
||||||
|
// error-pattern: Uninitialized value was created by an allocation
|
||||||
|
// error-pattern: in the stack frame of function 'random'
|
||||||
|
//
|
||||||
|
// This test case intentionally limits the usage of the std,
|
||||||
|
// since it will be linked with an uninstrumented version of it.
|
||||||
|
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
|
#![feature(start)]
|
||||||
|
#![feature(bench_black_box)]
|
||||||
|
|
||||||
|
use std::hint::black_box;
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
#[no_mangle]
|
||||||
|
#[allow(invalid_value)]
|
||||||
|
fn random() -> char {
|
||||||
|
let r = unsafe { MaybeUninit::uninit().assume_init() };
|
||||||
|
// Avoid optimizing everything out.
|
||||||
|
black_box(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[start]
|
||||||
|
fn main(_: isize, _: *const *const u8) -> isize {
|
||||||
|
random();
|
||||||
|
0
|
||||||
|
}
|
|
@ -1,7 +1,10 @@
|
||||||
// needs-sanitizer-support
|
// needs-sanitizer-support
|
||||||
// needs-sanitizer-memory
|
// needs-sanitizer-memory
|
||||||
//
|
//
|
||||||
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
|
// revisions: unoptimized optimized
|
||||||
|
//
|
||||||
|
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
|
||||||
|
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
|
||||||
//
|
//
|
||||||
// run-fail
|
// run-fail
|
||||||
// error-pattern: MemorySanitizer: use-of-uninitialized-value
|
// error-pattern: MemorySanitizer: use-of-uninitialized-value
|
||||||
|
@ -22,9 +25,9 @@ use std::mem::MaybeUninit;
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn random() -> [isize; 32] {
|
fn random() -> [isize; 32] {
|
||||||
let r = unsafe { MaybeUninit::uninit().assume_init() };
|
let r = MaybeUninit::uninit();
|
||||||
// Avoid optimizing everything out.
|
// Avoid optimizing everything out.
|
||||||
black_box(r)
|
unsafe { std::intrinsics::volatile_load(r.as_ptr()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
@ -39,6 +42,6 @@ fn xor(a: &[isize]) -> isize {
|
||||||
|
|
||||||
#[start]
|
#[start]
|
||||||
fn main(_: isize, _: *const *const u8) -> isize {
|
fn main(_: isize, _: *const *const u8) -> isize {
|
||||||
let r = random();
|
let r = black_box(random as fn() -> [isize; 32])();
|
||||||
xor(&r)
|
xor(&r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue