Enable eager checks for memory sanitizer
This commit is contained in:
parent
2fbc08e2ce
commit
66dcf5dfee
@ -131,7 +131,12 @@ extern "C" LLVMPassRef LLVMRustCreateMemorySanitizerPass(int TrackOrigins, bool
|
||||
const bool CompileKernel = false;
|
||||
|
||||
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
|
||||
report_fatal_error("Legacy PM not supported with LLVM 15");
|
||||
#endif
|
||||
@ -931,10 +936,18 @@ LLVMRustOptimizeWithNewPassManager(
|
||||
|
||||
if (SanitizerOptions) {
|
||||
if (SanitizerOptions->SanitizeMemory) {
|
||||
#if LLVM_VERSION_GE(14, 0)
|
||||
MemorySanitizerOptions Options(
|
||||
SanitizerOptions->SanitizeMemoryTrackOrigins,
|
||||
SanitizerOptions->SanitizeMemoryRecover,
|
||||
/*CompileKernel=*/false,
|
||||
/*EagerChecks=*/true);
|
||||
#else
|
||||
MemorySanitizerOptions Options(
|
||||
SanitizerOptions->SanitizeMemoryTrackOrigins,
|
||||
SanitizerOptions->SanitizeMemoryRecover,
|
||||
/*CompileKernel=*/false);
|
||||
#endif
|
||||
OptimizerLastEPCallbacks.push_back(
|
||||
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||
#if LLVM_VERSION_GE(14, 0)
|
||||
|
35
src/test/ui/sanitize/memory-eager.rs
Normal file
35
src/test/ui/sanitize/memory-eager.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// needs-sanitizer-support
|
||||
// needs-sanitizer-memory
|
||||
// min-llvm-version: 14.0.0
|
||||
//
|
||||
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
|
||||
//
|
||||
// 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
|
||||
}
|
@ -21,9 +21,9 @@ use std::mem::MaybeUninit;
|
||||
#[inline(never)]
|
||||
#[no_mangle]
|
||||
fn random() -> [isize; 32] {
|
||||
let r = unsafe { MaybeUninit::uninit().assume_init() };
|
||||
let r = MaybeUninit::uninit();
|
||||
// Avoid optimizing everything out.
|
||||
black_box(r)
|
||||
unsafe { std::intrinsics::volatile_load(r.as_ptr()) }
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
@ -38,6 +38,6 @@ fn xor(a: &[isize]) -> isize {
|
||||
|
||||
#[start]
|
||||
fn main(_: isize, _: *const *const u8) -> isize {
|
||||
let r = random();
|
||||
let r = black_box(random as fn() -> [isize; 32])();
|
||||
xor(&r)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user