From 800b43ec591eba95d5239f3ecd2b85348d0420a6 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Thu, 21 Sep 2017 09:28:02 +0200 Subject: [PATCH] [assert-instr] compare only the instruction prefix When comparing the assembly instructions against the expected instruction, depending on the platform, we might end up with `tzcntl != tzcnt`. This commit truncates the instructions to the length of the expected instruction, such that `tzcntl => tzcnt` and the comparison succeeds. --- library/stdarch/assert-instr/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library/stdarch/assert-instr/src/lib.rs b/library/stdarch/assert-instr/src/lib.rs index 596668a8f59b..1011d8310615 100644 --- a/library/stdarch/assert-instr/src/lib.rs +++ b/library/stdarch/assert-instr/src/lib.rs @@ -242,9 +242,14 @@ pub fn assert(fnptr: usize, expected: &str) { // Look for `expected` as the first part of any instruction in this // function, returning if we do indeed find it. for instr in function.instrs.iter() { + // Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax if let Some(part) = instr.parts.get(0) { - if part == expected { - return + // Truncates the instruction with the length of the expected + // instruction: tzcntl => tzcnt and compares that. + if let Some(part) = part.get(0..expected.len()) { + if part == expected { + return + } } } }