Skip to content

Commit

Permalink
Use black_box instead of llvm_asm (rust-lang#944)
Browse files Browse the repository at this point in the history
The implementation is the same (where possible), and it unblocks rust-lang#904

Signed-off-by: Joe Richey <joerichey@google.com>
  • Loading branch information
josephlr authored Nov 4, 2020
1 parent bf687fa commit ca5aed8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 0 additions & 4 deletions crates/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ pub fn assert_instr(
fn #assert_name() {
#to_test

// Make sure that the shim is not removed by leaking it to unknown
// code:
unsafe { llvm_asm!("" : : "r"(#shim_name as usize) : "memory" : "volatile") };

::stdarch_test::assert(#shim_name as usize,
stringify!(#shim_name),
#instr);
Expand Down
8 changes: 6 additions & 2 deletions crates/stdarch-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This basically just disassembles the current executable and then parses the
//! output once globally and then provides the `assert` function which makes
//! assertions about the disassembly of a function.
#![feature(test)] // For black_box
#![allow(clippy::missing_docs_in_private_items, clippy::print_stdout)]

extern crate assert_instr_macro;
Expand All @@ -16,7 +17,7 @@ extern crate cfg_if;

pub use assert_instr_macro::*;
pub use simd_test_macro::*;
use std::{cmp, collections::HashSet, env, hash, str, sync::atomic::AtomicPtr};
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::atomic::AtomicPtr};

cfg_if! {
if #[cfg(target_arch = "wasm32")] {
Expand Down Expand Up @@ -63,7 +64,10 @@ impl hash::Hash for Function {
///
/// This asserts that the function at `fnptr` contains the instruction
/// `expected` provided.
pub fn assert(_fnptr: usize, fnname: &str, expected: &str) {
pub fn assert(shim_addr: usize, fnname: &str, expected: &str) {
// Make sure that the shim is not removed
black_box(shim_addr);

//eprintln!("shim name: {}", fnname);
let function = &DISASSEMBLY
.get(&Function::new(fnname))
Expand Down

0 comments on commit ca5aed8

Please sign in to comment.