about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-01-16 20:53:27 +0530
committerGitHub <noreply@github.com>2020-01-16 20:53:27 +0530
commit678f662e5492fb5a99db84340f8ebc02796fa773 (patch)
treef25da593184d2612bc1df1bb023b6f418abd8f76
parentc8125fb36a7d0f06e21ca891d993c85b9fd884b6 (diff)
parent5d00b5c4aae885a247d783f5c274df9ef0539d0e (diff)
downloadrust-678f662e5492fb5a99db84340f8ebc02796fa773.tar.gz
rust-678f662e5492fb5a99db84340f8ebc02796fa773.zip
Rollup merge of #68244 - tmiasko:leak, r=Centril
Enable leak sanitizer test case

* Use `black_box` to avoid memory leak removal during optimization.
* Leak multiple objects to make test case more robust.
-rw-r--r--src/test/run-make-fulldeps/sanitizer-leak/Makefile6
-rw-r--r--src/test/run-make-fulldeps/sanitizer-leak/leak.rs11
2 files changed, 10 insertions, 7 deletions
diff --git a/src/test/run-make-fulldeps/sanitizer-leak/Makefile b/src/test/run-make-fulldeps/sanitizer-leak/Makefile
index d8598b8ac93..da370335ca9 100644
--- a/src/test/run-make-fulldeps/sanitizer-leak/Makefile
+++ b/src/test/run-make-fulldeps/sanitizer-leak/Makefile
@@ -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'
diff --git a/src/test/run-make-fulldeps/sanitizer-leak/leak.rs b/src/test/run-make-fulldeps/sanitizer-leak/leak.rs
index ab8df5c7bfd..fb0a917dd98 100644
--- a/src/test/run-make-fulldeps/sanitizer-leak/leak.rs
+++ b/src/test/run-make-fulldeps/sanitizer-leak/leak.rs
@@ -1,6 +1,13 @@
+#![feature(test)]
+
+use std::hint::black_box;
 use std::mem;
 
 fn main() {
-    let xs = vec![1, 2, 3, 4];
-    mem::forget(xs);
+    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);
+    }
 }