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() { function %fn_call_too_few_args() {
fn2 = %great_fn(i32, f32) fn2 = %great_fn(i32, f32)
ebb0: 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 return
} }
@@ -53,7 +53,7 @@ function %fn_call_too_many_args() {
ebb0: ebb0:
v0 = iconst.i64 56 v0 = iconst.i64 56
v1 = f32const 0.0 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 return
} }

View File

@@ -18,6 +18,16 @@ pub fn pretty_verifier_error(
err: &VerifierError, err: &VerifierError,
) -> String { ) -> String {
let mut w = String::new(); 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( decorate_function(
&mut |w, func, isa, inst, indent| pretty_function_error(w, func, isa, inst, indent, err), &mut |w, func, isa, inst, indent| pretty_function_error(w, func, isa, inst, indent, err),
&mut w, &mut w,
@@ -37,8 +47,7 @@ fn pretty_function_error(
err: &VerifierError, err: &VerifierError,
) -> fmt::Result { ) -> fmt::Result {
match err.location { match err.location {
ir::entities::AnyEntity::Inst(inst) => { ir::entities::AnyEntity::Inst(inst) if inst == cur_inst => {
if inst == cur_inst {
writeln!( writeln!(
w, w,
"{1:0$}{2}", "{1:0$}{2}",
@@ -50,18 +59,15 @@ fn pretty_function_error(
for _c in cur_inst.to_string().chars() { for _c in cur_inst.to_string().chars() {
write!(w, "~")?; write!(w, "~")?;
} }
writeln!(w, "\n\nverifier {}\n", err.to_string()) writeln!(w, " verifier {}\n", err.to_string())
} else { }
write!( _ => writeln!(
w, w,
"{1:0$}{2}", "{1:0$}{2}",
indent, indent,
"", "",
func.dfg.display_inst(cur_inst, isa) func.dfg.display_inst(cur_inst, isa)
) ),
}
}
_ => writeln!(w),
} }
} }

View File

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

View File

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