black_box should inhibit optimizations on platforms without inline assembly

This commit is contained in:
gnzlbg 2019-03-25 11:49:08 +01:00
parent f2443831e9
commit cfa76c438a

View File

@ -106,7 +106,10 @@ pub fn black_box<T>(dummy: T) -> T {
dummy
}
#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))] {
#[inline(never)] fn black_box_(x: T) -> T { x }
black_box_(dummy)
}
unsafe {
let ret = crate::ptr::read_volatile(&dummy);
crate::mem::forget(dummy);
ret
}
}
}