1
Fork 0

Enable leak sanitizer test case

* Use `black_box` to avoid memory leak removal during optimization.
* Leak multiple objects to make test case more robust.
This commit is contained in:
Tomasz Miąsko 2020-01-15 00:00:00 +00:00
parent 6d0bb91bcb
commit 5d00b5c4aa
2 changed files with 10 additions and 7 deletions

View file

@ -1,11 +1,7 @@
-include ../tools.mk
# needs-sanitizer-support
# only-linux
# only-x86_64
# ignore-test
# FIXME(#46126) ThinLTO for libstd broke this test
all:
$(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan
$(RUSTC) -O -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan
$(TMPDIR)/leak 2>&1 | $(CGREP) 'detected memory leaks'

View file

@ -1,6 +1,13 @@
#![feature(test)]
use std::hint::black_box;
use std::mem;
fn main() {
let xs = vec![1, 2, 3, 4];
for _ in 0..10 {
let xs = vec![1, 2, 3];
// Prevent compiler from removing the memory allocation.
let xs = black_box(xs);
mem::forget(xs);
}
}