Skip to content

Commit d488500

Browse files
committed
Don't discard value names when using address or memory sanitizer
The value names are used when reporting issues found by address sanitizer or memory sanitizer. Avoid discarding names when those sanitizers are enabled, unless explicitly requested to do otherwise.
1 parent 3da6836 commit d488500

File tree

2 files changed

+12
-1
lines changed
  • src
    • librustc/session
    • test/run-make-fulldeps/sanitizer-address

2 files changed

+12
-1
lines changed

src/librustc/session/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
77

88
use crate::lint;
99
use crate::lint::builtin::BuiltinLintDiagnostics;
10-
use crate::session::config::{OutputType, PrintRequest, SwitchWithOptPath};
10+
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
1111
use crate::session::search_paths::{PathKind, SearchPath};
1212
use crate::util::nodemap::{FxHashMap, FxHashSet};
1313
use crate::util::common::{duration_to_secs_str, ErrorReported};
@@ -626,6 +626,14 @@ impl Session {
626626
.output_types
627627
.contains_key(&OutputType::LlvmAssembly)
628628
|| self.opts.output_types.contains_key(&OutputType::Bitcode);
629+
630+
// Address sanitizer and memory sanitizer use alloca name when reporting an issue.
631+
let more_names = match self.opts.debugging_opts.sanitizer {
632+
Some(Sanitizer::Address) => true,
633+
Some(Sanitizer::Memory) => true,
634+
_ => more_names,
635+
};
636+
629637
self.opts.debugging_opts.fewer_names || !more_names
630638
}
631639

src/test/run-make-fulldeps/sanitizer-address/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ endif
2424

2525
all:
2626
$(RUSTC) -g -Z sanitizer=address -Z print-link-args $(EXTRA_RUSTFLAG) overflow.rs | $(CGREP) librustc_asan
27+
# Verify that stack buffer overflow is detected:
2728
$(TMPDIR)/overflow 2>&1 | $(CGREP) stack-buffer-overflow
29+
# Verify that variable name is included in address sanitizer report:
30+
$(TMPDIR)/overflow 2>&1 | $(CGREP) "'xs'"

0 commit comments

Comments
 (0)