about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgnzlbg <gonzalobg88@gmail.com>2019-03-04 18:04:08 +0100
committergnzlbg <gonzalobg88@gmail.com>2019-03-19 13:58:48 +0100
commit25c8f61a9f84ecd546dd53b6b891c53d7bcd246a (patch)
tree5c98f89d10699a5d31de488e3b1417c5fcb8742f
parent008ce9902828eb3cad0b2b1019ab1960fbb9300a (diff)
downloadrust-25c8f61a9f84ecd546dd53b6b891c53d7bcd246a.tar.gz
rust-25c8f61a9f84ecd546dd53b6b891c53d7bcd246a.zip
Move black_box back to rust-lang/libtest and use explicit imports
-rw-r--r--src/libtest/lib.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 82e44ba4873..c15ed308ff0 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -12,8 +12,27 @@
 #![unstable(feature = "test", issue = "27812")]
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
        test(attr(deny(warnings))))]
+#![feature(asm)]
 #![feature(staged_api)]
 #![feature(test)]
 
 extern crate libtest;
-pub use libtest::*;
+pub use libtest::{test_main_static, TestDescAndFn, StaticTestFn, StaticBenchFn, Options};
+
+/// A function that is opaque to the optimizer, to allow benchmarks to
+/// pretend to use outputs to assist in avoiding dead-code
+/// elimination.
+///
+/// This function is a no-op, and does not even read from `dummy`.
+#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
+pub fn black_box<T>(dummy: T) -> T {
+    // we need to "use" the argument in some way LLVM can't
+    // introspect.
+    unsafe { asm!("" : : "r"(&dummy)) }
+    dummy
+}
+#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))]
+#[inline(never)]
+pub fn black_box<T>(dummy: T) -> T {
+    dummy
+}