Skip to content

Commit 411e125

Browse files
authored
Merge pull request rust-lang#41 from alexcrichton/assert-small
Assert that diassembly is "small"
2 parents 1afaf49 + c74d9ea commit 411e125

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

assert-instr/src/lib.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,25 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
256256

257257
// Look for `expected` as the first part of any instruction in this
258258
// function, returning if we do indeed find it.
259+
let mut found = false;
259260
for instr in function.instrs.iter() {
260261
// Gets the first instruction, e.g. tzcntl in tzcntl %rax,%rax
261262
if let Some(part) = instr.parts.get(0) {
262263
// Truncates the instruction with the length of the expected
263264
// instruction: tzcntl => tzcnt and compares that.
264265
if part.starts_with(expected) {
265-
return
266+
found = true;
267+
break
266268
}
267269
}
268270
}
269271

272+
let probably_only_one_instruction = function.instrs.len() < 20;
273+
274+
if found && probably_only_one_instruction {
275+
return
276+
}
277+
270278
// Help debug by printing out the found disassembly, and then panic as we
271279
// didn't find the instruction.
272280
println!("disassembly for {}: ", sym.as_ref().unwrap());
@@ -277,5 +285,10 @@ pub fn assert(fnptr: usize, fnname: &str, expected: &str) {
277285
}
278286
println!("");
279287
}
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+
}
281294
}

0 commit comments

Comments
 (0)