Skip to content

Commit 1f6062d

Browse files
hkratzAmanieu
authored andcommitted
Use a lighter dedup guard in the assert_instr test shims.
1 parent b9717b9 commit 1f6062d

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ pub fn assert_instr(
5858
&format!("stdarch_test_shim_{}_{}", name, instr_str),
5959
name.span(),
6060
);
61+
let shim_name_ptr = syn::Ident::new(
62+
&format!("stdarch_test_shim_{}_{}_ptr", name, instr_str).to_ascii_uppercase(),
63+
name.span(),
64+
);
6165
let mut inputs = Vec::new();
6266
let mut input_vals = Vec::new();
6367
let mut const_vals = Vec::new();
@@ -125,6 +129,9 @@ pub fn assert_instr(
125129
};
126130
let shim_name_str = format!("{}{}", shim_name, assert_name);
127131
let to_test = quote! {
132+
133+
const #shim_name_ptr : *const u8 = #shim_name_str.as_ptr();
134+
128135
#attrs
129136
#[no_mangle]
130137
#[inline(never)]
@@ -140,17 +147,7 @@ pub fn assert_instr(
140147
// generate some code that's hopefully very tight in terms of
141148
// codegen but is otherwise unique to prevent code from being
142149
// folded.
143-
//
144-
// This is avoided on Wasm32 right now since these functions aren't
145-
// inlined which breaks our tests since each intrinsic looks like it
146-
// calls functions. Turns out functions aren't similar enough to get
147-
// merged on wasm32 anyway. This bug is tracked at
148-
// rust-lang/rust#74320.
149-
#[cfg(not(target_arch = "wasm32"))]
150-
::stdarch_test::_DONT_DEDUP.store(
151-
std::mem::transmute(#shim_name_str.as_bytes().as_ptr()),
152-
std::sync::atomic::Ordering::Relaxed,
153-
);
150+
::stdarch_test::_DONT_DEDUP = #shim_name_ptr;
154151
#name::<#(#const_vals),*>(#(#input_vals),*)
155152
}
156153
};

crates/stdarch-test/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern crate cfg_if;
1414

1515
pub use assert_instr_macro::*;
1616
pub use simd_test_macro::*;
17-
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::atomic::AtomicPtr};
17+
use std::{cmp, collections::HashSet, env, hash, hint::black_box, str};
1818

1919
cfg_if! {
2020
if #[cfg(target_arch = "wasm32")] {
@@ -103,7 +103,7 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) {
103103
// failed inlining something.
104104
s[0].starts_with("call ") && s[1].starts_with("pop") // FIXME: original logic but does not match comment
105105
})
106-
} else if cfg!(target_arch = "aarch64") {
106+
} else if cfg!(target_arch = "aarch64") || cfg!(target_arch = "arm") {
107107
instrs.iter().any(|s| s.starts_with("bl "))
108108
} else {
109109
// FIXME: Add detection for other archs
@@ -189,4 +189,4 @@ pub fn assert_skip_test_ok(name: &str) {
189189
}
190190

191191
// See comment in `assert-instr-macro` crate for why this exists
192-
pub static _DONT_DEDUP: AtomicPtr<u8> = AtomicPtr::new(b"".as_ptr() as *mut _);
192+
pub static mut _DONT_DEDUP: *const u8 = std::ptr::null();

0 commit comments

Comments
 (0)