Enhance Verifier error reporting;

This commit is contained in:
Benjamin Bouvier
2018-07-27 17:55:26 +02:00
committed by Dan Gohman
parent 1b42105faa
commit 3a550d185f
4 changed files with 34 additions and 27 deletions

View File

@@ -44,7 +44,7 @@ function %type_mismatch_controlling_variable() {
function %fn_call_too_few_args() {
fn2 = %great_fn(i32, f32)
ebb0:
call fn2() ; error: mismatched argument count, got 0, expected 2
call fn2() ; error: mismatched argument count for `call fn2()`: got 0, expected 2
return
}
@@ -53,7 +53,7 @@ function %fn_call_too_many_args() {
ebb0:
v0 = iconst.i64 56
v1 = f32const 0.0
call fn5(v0, v1) ; error: mismatched argument count, got 2, expected 0
call fn5(v0, v1) ; error: mismatched argument count for `call fn5(v0, v1)`: got 2, expected 0
return
}

View File

@@ -18,6 +18,16 @@ pub fn pretty_verifier_error(
err: &VerifierError,
) -> String {
let mut w = String::new();
match err.location {
ir::entities::AnyEntity::Inst(_) => {}
_ => {
// Print the error, because the pretty_function_error below won't do it since it isn't
// tied to an instruction.
writeln!(w, "verifier error summary: {}\n", err.to_string()).unwrap();
}
}
decorate_function(
&mut |w, func, isa, inst, indent| pretty_function_error(w, func, isa, inst, indent, err),
&mut w,
@@ -37,8 +47,7 @@ fn pretty_function_error(
err: &VerifierError,
) -> fmt::Result {
match err.location {
ir::entities::AnyEntity::Inst(inst) => {
if inst == cur_inst {
ir::entities::AnyEntity::Inst(inst) if inst == cur_inst => {
writeln!(
w,
"{1:0$}{2}",
@@ -50,18 +59,15 @@ fn pretty_function_error(
for _c in cur_inst.to_string().chars() {
write!(w, "~")?;
}
writeln!(w, "\n\nverifier {}\n", err.to_string())
} else {
write!(
writeln!(w, " verifier {}\n", err.to_string())
}
_ => writeln!(
w,
"{1:0$}{2}",
indent,
"",
func.dfg.display_inst(cur_inst, isa)
)
}
}
_ => writeln!(w),
),
}
}

View File

@@ -820,7 +820,8 @@ impl<'a> Verifier<'a> {
if i != variable_args.len() {
return err!(
inst,
"mismatched argument count, got {}, expected {}",
"mismatched argument count for `{}`: got {}, expected {}",
self.func.dfg.display_inst(inst, None),
variable_args.len(),
i
);

View File

@@ -135,5 +135,5 @@ fn run_one_test<'a>(
}
test.run(func, context)
.map_err(|e| format!("{}: {}", name, e))
.map_err(|e| format!("{}:\n{}", name, e))
}