Skip to content

Use black_box instead of llvm_asm #944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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