Skip to content

Commit

Permalink
Rollup merge of rust-lang#65369 - tmiasko:sanitizers-keep-names, r=va…
Browse files Browse the repository at this point in the history
…rkor

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.
  • Loading branch information
Centril authored Oct 13, 2019
2 parents a927c83 + d488500 commit 45a6cc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::fingerprint::Fingerprint;

use crate::lint;
use crate::lint::builtin::BuiltinLintDiagnostics;
use crate::session::config::{OutputType, PrintRequest, SwitchWithOptPath};
use crate::session::config::{OutputType, PrintRequest, Sanitizer, SwitchWithOptPath};
use crate::session::search_paths::{PathKind, SearchPath};
use crate::util::nodemap::{FxHashMap, FxHashSet};
use crate::util::common::{duration_to_secs_str, ErrorReported};
Expand Down Expand Up @@ -626,6 +626,14 @@ impl Session {
.output_types
.contains_key(&OutputType::LlvmAssembly)
|| self.opts.output_types.contains_key(&OutputType::Bitcode);

// Address sanitizer and memory sanitizer use alloca name when reporting an issue.
let more_names = match self.opts.debugging_opts.sanitizer {
Some(Sanitizer::Address) => true,
Some(Sanitizer::Memory) => true,
_ => more_names,
};

self.opts.debugging_opts.fewer_names || !more_names
}

Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make-fulldeps/sanitizer-address/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ endif

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

0 comments on commit 45a6cc0

Please sign in to comment.