@@ -256,17 +256,25 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
256
256
257
257
// Look for `expected` as the first part of any instruction in this
258
258
// function, returning if we do indeed find it.
259
+ let mut found = false ;
259
260
for instr in function. instrs . iter ( ) {
260
261
// Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax
261
262
if let Some ( part) = instr. parts . get ( 0 ) {
262
263
// Truncates the instruction with the length of the expected
263
264
// instruction: tzcntl => tzcnt and compares that.
264
265
if part. starts_with ( expected) {
265
- return
266
+ found = true ;
267
+ break
266
268
}
267
269
}
268
270
}
269
271
272
+ let probably_only_one_instruction = function. instrs . len ( ) < 20 ;
273
+
274
+ if found && probably_only_one_instruction {
275
+ return
276
+ }
277
+
270
278
// Help debug by printing out the found disassembly, and then panic as we
271
279
// didn't find the instruction.
272
280
println ! ( "disassembly for {}: " , sym. as_ref( ) . unwrap( ) ) ;
@@ -277,5 +285,10 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
277
285
}
278
286
println ! ( "" ) ;
279
287
}
280
- panic ! ( "failed to find instruction `{}` in the disassembly" , expected) ;
288
+
289
+ if !found {
290
+ panic ! ( "failed to find instruction `{}` in the disassembly" , expected) ;
291
+ } else if !probably_only_one_instruction {
292
+ panic ! ( "too many instructions in the disassembly" ) ;
293
+ }
281
294
}
0 commit comments