Skip to content

Commit eff520b

Browse files
committed
stdarch-test: misc cleanups
1 parent f919daa commit eff520b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

crates/stdarch-test/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) {
6161
black_box(shim_addr);
6262

6363
//eprintln!("shim name: {fnname}");
64-
let function = &DISASSEMBLY
65-
.get(&Function::new(fnname))
66-
.unwrap_or_else(|| panic!("function \"{fnname}\" not found in the disassembly"));
64+
let Some(function) = &DISASSEMBLY.get(&Function::new(fnname)) else {
65+
panic!("function `{fnname}` not found in the disassembly")
66+
};
6767
//eprintln!(" function: {:?}", function);
6868

69+
// Trim any filler instructions.
6970
let mut instrs = &function.instrs[..];
7071
while instrs.last().is_some_and(|s| s == "nop" || s == "int3") {
7172
instrs = &instrs[..instrs.len() - 1];
@@ -80,11 +81,17 @@ pub fn assert(shim_addr: usize, fnname: &str, expected: &str) {
8081
// 2. It is a mark, indicating that the instruction will be
8182
// compiled into other instructions - mainly because of llvm
8283
// optimization.
83-
let expected = if expected == "unknown" {
84-
"<unknown>" // Workaround for rust-lang/stdarch#1674, todo: remove when the issue is fixed
85-
} else {
86-
expected
84+
let expected = match expected {
85+
// `<unknown>` is what LLVM will generate for unknown instructions. We use this to fail
86+
// loudly when LLVM does start supporting these instructions.
87+
//
88+
// This was introduced in https://github.com/rust-lang/stdarch/pull/1674 to work around the
89+
// RISC-V P extension not yet being supported.
90+
"unknown" => "<unknown>",
91+
_ => expected,
8792
};
93+
94+
// Check whether the given instruction is part of the disassemblied body.
8895
let found = expected == "nop" || instrs.iter().any(|s| s.starts_with(expected));
8996

9097
// Look for subroutine call instructions in the disassembly to detect whether

0 commit comments

Comments
 (0)