Skip to content

Commit 16525cc

Browse files
committed
Emit noundef even for unoptimised code if msan is on
1 parent 66dcf5d commit 16525cc

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_target::abi::call::ArgAbi;
1919
pub use rustc_target::abi::call::*;
2020
use rustc_target::abi::{self, HasDataLayout, Int};
2121
pub use rustc_target::spec::abi::Abi;
22+
use rustc_target::spec::SanitizerSet;
2223

2324
use libc::c_uint;
2425
use smallvec::SmallVec;
@@ -90,6 +91,13 @@ fn get_attrs<'ll>(this: &ArgAttributes, cx: &CodegenCx<'ll, '_>) -> SmallVec<[&'
9091
if regular.contains(ArgAttribute::NoAliasMutRef) && should_use_mutable_noalias(cx) {
9192
attrs.push(llvm::AttributeKind::NoAlias.create_attr(cx.llcx));
9293
}
94+
} else if cx.tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::MEMORY) {
95+
// If we're not optimising, *but* memory sanitizer is on, emit noundef, since it affects
96+
// memory sanitizer's behavior.
97+
98+
if regular.contains(ArgAttribute::NoUndef) {
99+
attrs.push(llvm::AttributeKind::NoUndef.create_attr(cx.llcx));
100+
}
93101
}
94102

95103
attrs

src/test/ui/sanitize/memory-eager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// needs-sanitizer-memory
33
// min-llvm-version: 14.0.0
44
//
5-
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
5+
// revisions: unoptimized optimized
6+
//
7+
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
8+
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
69
//
710
// run-fail
811
// error-pattern: MemorySanitizer: use-of-uninitialized-value

src/test/ui/sanitize/memory.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// needs-sanitizer-support
22
// needs-sanitizer-memory
33
//
4-
// compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
4+
// revisions: unoptimized optimized
5+
//
6+
// [optimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins -O
7+
// [unoptimized]compile-flags: -Z sanitizer=memory -Zsanitizer-memory-track-origins
58
//
69
// run-fail
710
// error-pattern: MemorySanitizer: use-of-uninitialized-value

0 commit comments

Comments
 (0)