diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2025-07-18 20:27:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-18 20:27:56 +0000 |
| commit | 8fe55684d8ccee7fe9c0fdadd94ee98709af9193 (patch) | |
| tree | 78a9dc3ef7f8d27fadfef950cbda1d6196b4d85c /library/stdarch/crates/stdarch-test | |
| parent | d198c4fbf57fc0c7d91531b0b29d97ebbe8e675b (diff) | |
| parent | 5438a7c110127ec66002d6a15d168858a20a802c (diff) | |
| download | rust-8fe55684d8ccee7fe9c0fdadd94ee98709af9193.tar.gz rust-8fe55684d8ccee7fe9c0fdadd94ee98709af9193.zip | |
Merge pull request #1860 from folkertdev/stdarch-test-cleanup
`stdarch-test`: various cleanups
Diffstat (limited to 'library/stdarch/crates/stdarch-test')
| -rw-r--r-- | library/stdarch/crates/stdarch-test/Cargo.toml | 1 | ||||
| -rw-r--r-- | library/stdarch/crates/stdarch-test/src/lib.rs | 39 |
2 files changed, 25 insertions, 15 deletions
diff --git a/library/stdarch/crates/stdarch-test/Cargo.toml b/library/stdarch/crates/stdarch-test/Cargo.toml index 299bc8c63bf..e88258bfd30 100644 --- a/library/stdarch/crates/stdarch-test/Cargo.toml +++ b/library/stdarch/crates/stdarch-test/Cargo.toml @@ -7,7 +7,6 @@ edition = "2024" [dependencies] assert-instr-macro = { path = "../assert-instr-macro" } simd-test-macro = { path = "../simd-test-macro" } -lazy_static = "1.0" rustc-demangle = "0.1.8" cfg-if = "1.0" diff --git a/library/stdarch/crates/stdarch-test/src/lib.rs b/library/stdarch/crates/stdarch-test/src/lib.rs index f6614f6d51c..ecaf95f6176 100644 --- a/library/stdarch/crates/stdarch-test/src/lib.rs +++ b/library/stdarch/crates/stdarch-test/src/lib.rs @@ -7,13 +7,11 @@ #![allow(clippy::missing_docs_in_private_items, clippy::print_stdout)] #[macro_use] -extern crate lazy_static; -#[macro_use] extern crate cfg_if; pub use assert_instr_macro::*; pub use simd_test_macro::*; -use std::{cmp, collections::HashSet, env, hash, hint::black_box, str}; +use std::{cmp, collections::HashSet, env, hash, hint::black_box, str, sync::LazyLock}; cfg_if! { if #[cfg(target_arch = "wasm32")] { @@ -25,9 +23,7 @@ cfg_if! { } } -lazy_static! { - static ref DISASSEMBLY: HashSet<Function> = disassemble_myself(); -} +static DISASSEMBLY: LazyLock<HashSet<Function>> = LazyLock::new(disassemble_myself); #[derive(Debug)] struct Function { @@ -65,11 +61,12 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) { black_box(shim_addr); //eprintln!("shim name: {fnname}"); - let function = &DISASSEMBLY - .get(&Function::new(fnname)) - .unwrap_or_else(|| panic!("function \"{fnname}\" not found in the disassembly")); + let Some(function) = &DISASSEMBLY.get(&Function::new(fnname)) else { + panic!("function `{fnname}` not found in the disassembly") + }; //eprintln!(" function: {:?}", function); + // Trim any filler instructions. let mut instrs = &function.instrs[..]; while instrs.last().is_some_and(|s| s == "nop" || s == "int3") { instrs = &instrs[..instrs.len() - 1]; @@ -84,12 +81,26 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) { // 2. It is a mark, indicating that the instruction will be // compiled into other instructions - mainly because of llvm // optimization. - let expected = if expected == "unknown" { - "<unknown>" // Workaround for rust-lang/stdarch#1674, todo: remove when the issue is fixed - } else { - expected + let expected = match expected { + // `<unknown>` is what LLVM will generate for unknown instructions. We use this to fail + // loudly when LLVM does start supporting these instructions. + // + // This was introduced in https://github.com/rust-lang/stdarch/pull/1674 to work around the + // RISC-V P extension not yet being supported. + "unknown" => "<unknown>", + _ => expected, }; - let found = expected == "nop" || instrs.iter().any(|s| s.starts_with(expected)); + + // Check whether the given instruction is part of the disassemblied body. + let found = expected == "nop" + || instrs.iter().any(|instruction| { + instruction.starts_with(expected) + // Check that the next character is non-alphanumeric. This prevents false negatives + // when e.g. `fminnm` was used but `fmin` was expected. + // + // TODO: resolve the conflicts (x86_64 and aarch64 have a bunch, probably others) + // && !instruction[expected.len()..].starts_with(|c: char| c.is_ascii_alphanumeric()) + }); // Look for subroutine call instructions in the disassembly to detect whether // inlining failed: all intrinsics are `#[inline(always)]`, so calling one |
