Skip to content

Commit 5d00b5c

Browse files
committed
Enable leak sanitizer test case
* Use `black_box` to avoid memory leak removal during optimization. * Leak multiple objects to make test case more robust.
1 parent 6d0bb91 commit 5d00b5c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
-include ../tools.mk
22

33
# needs-sanitizer-support
4-
# only-linux
5-
# only-x86_64
6-
# ignore-test
7-
# FIXME(#46126) ThinLTO for libstd broke this test
84

95
all:
10-
$(RUSTC) -C opt-level=1 -g -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan
6+
$(RUSTC) -O -Z sanitizer=leak -Z print-link-args leak.rs | $(CGREP) rustc_rt.lsan
117
$(TMPDIR)/leak 2>&1 | $(CGREP) 'detected memory leaks'
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
#![feature(test)]
2+
3+
use std::hint::black_box;
14
use std::mem;
25

36
fn main() {
4-
let xs = vec![1, 2, 3, 4];
5-
mem::forget(xs);
7+
for _ in 0..10 {
8+
let xs = vec![1, 2, 3];
9+
// Prevent compiler from removing the memory allocation.
10+
let xs = black_box(xs);
11+
mem::forget(xs);
12+
}
613
}

0 commit comments

Comments
 (0)