From 2cc81ac531c10a678ee25128a36fdc56ba00aaa3 Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sat, 3 Jan 2015 02:49:42 -0600 Subject: [PATCH] Return passed value from black_box By returning the passed value black_box can be used on data being passed to a function being benchmarked. This ensures the compiler does not optimize the function for the input which could result in the entire function being optimized away. --- src/libtest/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index c4cb53d6cb7..c00246598c3 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1332,10 +1332,11 @@ pub fn ratchet(&self, p: &Path, pct: Option) -> (MetricDiff, bool) { /// elimination. /// /// This function is a no-op, and does not even read from `dummy`. -pub fn black_box(dummy: T) { +pub fn black_box(dummy: T) -> T { // we need to "use" the argument in some way LLVM can't // introspect. unsafe {asm!("" : : "r"(&dummy))} + dummy }