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.
This commit is contained in:
Travis Watkins 2015-01-03 02:49:42 -06:00
parent 3d5fbae338
commit 2cc81ac531

View File

@ -1332,10 +1332,11 @@ pub fn ratchet(&self, p: &Path, pct: Option<f64>) -> (MetricDiff, bool) {
/// elimination.
///
/// This function is a no-op, and does not even read from `dummy`.
pub fn black_box<T>(dummy: T) {
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
}