diff options
| author | gnzlbg <gonzalobg88@gmail.com> | 2019-03-25 11:49:08 +0100 |
|---|---|---|
| committer | gnzlbg <gonzalobg88@gmail.com> | 2019-03-25 11:49:08 +0100 |
| commit | cfa76c438a907bf223e4487ab4da2500277474cc (patch) | |
| tree | f49d736607ac49fbf3bc839d1f845cb56a016629 /src/libcore | |
| parent | f2443831e97279d94902997d2c012d2e92d5d996 (diff) | |
| download | rust-cfa76c438a907bf223e4487ab4da2500277474cc.tar.gz rust-cfa76c438a907bf223e4487ab4da2500277474cc.zip | |
black_box should inhibit optimizations on platforms without inline assembly
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/hint.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/libcore/hint.rs b/src/libcore/hint.rs index 75d64bbe0fb..abaf0b31b46 100644 --- a/src/libcore/hint.rs +++ b/src/libcore/hint.rs @@ -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 + } + } } |
