Skip to content

Commit ca5aed8

Browse files
authored
Use black_box instead of llvm_asm (rust-lang#944)
The implementation is the same (where possible), and it unblocks rust-lang#904 Signed-off-by: Joe Richey <[email protected]>
1 parent bf687fa commit ca5aed8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

crates/assert-instr-macro/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ pub fn assert_instr(
143143
fn #assert_name() {
144144
#to_test
145145

146-
// Make sure that the shim is not removed by leaking it to unknown
147-
// code:
148-
unsafe { llvm_asm!("" : : "r"(#shim_name as usize) : "memory" : "volatile") };
149-
150146
::stdarch_test::assert(#shim_name as usize,
151147
stringify!(#shim_name),
152148
#instr);

crates/stdarch-test/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This basically just disassembles the current executable and then parses the
44
//! output once globally and then provides the `assert` function which makes
55
//! assertions about the disassembly of a function.
6+
#![feature(test)] // For black_box
67
#![allow(clippy::missing_docs_in_private_items, clippy::print_stdout)]
78

89
extern crate assert_instr_macro;
@@ -16,7 +17,7 @@ extern crate cfg_if;
1617

1718
pub use assert_instr_macro::*;
1819
pub use simd_test_macro::*;
19-
use std::{cmp, collections::HashSet, env, hash, str, sync::atomic::AtomicPtr};
20+
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::atomic::AtomicPtr};
2021

2122
cfg_if! {
2223
if #[cfg(target_arch = "wasm32")] {
@@ -63,7 +64,10 @@ impl hash::Hash for Function {
6364
///
6465
/// This asserts that the function at `fnptr` contains the instruction
6566
/// `expected` provided.
66-
pub fn assert(_fnptr: usize, fnname: &str, expected: &str) {
67+
pub fn assert(shim_addr: usize, fnname: &str, expected: &str) {
68+
// Make sure that the shim is not removed
69+
black_box(shim_addr);
70+
6771
//eprintln!("shim name: {}", fnname);
6872
let function = &DISASSEMBLY
6973
.get(&Function::new(fnname))

0 commit comments

Comments
 (0)