Skip to content

Commit 25c8f61

Browse files
committed
Move black_box back to rust-lang/libtest and use explicit imports
1 parent 008ce99 commit 25c8f61

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/libtest/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@
1212
#![unstable(feature = "test", issue = "27812")]
1313
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/",
1414
test(attr(deny(warnings))))]
15+
#![feature(asm)]
1516
#![feature(staged_api)]
1617
#![feature(test)]
1718

1819
extern crate libtest;
19-
pub use libtest::*;
20+
pub use libtest::{test_main_static, TestDescAndFn, StaticTestFn, StaticBenchFn, Options};
21+
22+
/// A function that is opaque to the optimizer, to allow benchmarks to
23+
/// pretend to use outputs to assist in avoiding dead-code
24+
/// elimination.
25+
///
26+
/// This function is a no-op, and does not even read from `dummy`.
27+
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))]
28+
pub fn black_box<T>(dummy: T) -> T {
29+
// we need to "use" the argument in some way LLVM can't
30+
// introspect.
31+
unsafe { asm!("" : : "r"(&dummy)) }
32+
dummy
33+
}
34+
#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))]
35+
#[inline(never)]
36+
pub fn black_box<T>(dummy: T) -> T {
37+
dummy
38+
}

0 commit comments

Comments
 (0)