Skip to content

Commit

Permalink
black_box should use inline assembly on wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzlbg committed Mar 25, 2019
1 parent cfa76c4 commit 24db517
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libcore/hint.rs
Expand Up @@ -99,17 +99,17 @@ pub fn spin_loop() {
/// This function is a no-op, and does not even read from `dummy`.
#[unstable(feature = "test", issue = "27812")]
pub fn black_box<T>(dummy: T) -> T {
#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))] {
#[cfg(not(target_arch = "asmjs"))] {
// 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"))] {
#[cfg(target_arch = "asmjs")] {
unsafe {
let ret = crate::ptr::read_volatile(&dummy);
crate::mem::forget(dummy);
ret
}
}
}
}

0 comments on commit 24db517

Please sign in to comment.