Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to run CBMC sanity checks + set is_param for function parameters #1387

Merged
merged 5 commits into from
Jul 19, 2022

Conversation

celinval
Copy link
Contributor

@celinval celinval commented Jul 18, 2022

Description of changes:

  1. Add an unstable hidden option to kani-driver to run sanity checks that are available in CBMC to perform consistency checks on the GOTO model.
  2. Fix consistency checks related to missing is_parameter flag. We were not setting this parameter at all. CBMC expects all symbols that are function parameters to have this flag set to true.

Resolved issues:

This is related to #957

Call-outs:

We would like to enable these checks (as requested in #957), however the regression is still failing as described in #957 (comment).

Testing:

  • How is this change tested?

  • Is this a refactor change?

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

celinval added 3 commits July 18, 2022 14:40
This will ensure the gotoc model we generate is valid. Surprisingly, we
fail at that in many places today.
I am not aware of any verification issue from missing this flag, but
but it is expected in a well formed iRep according to the sanity checks
in CBMC. This is blocking us from enable those sanity checks so I'm
fixing them now.
We are still seeing issues with `memcmp` in the regression. Disable the
sanity checks in the regression for now but allow them to be run
manually.
@celinval celinval requested a review from a team as a code owner July 18, 2022 21:44
@celinval celinval requested a review from tautschnig July 18, 2022 21:45
@@ -130,6 +134,16 @@ impl KaniSession {
self.call_goto_instrument(args)
}

fn goto_sanity_check(&self, file: &Path) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be running it twice, when we're already doing it with the cbmc args?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I figured it's a cheap analysis, so we might as well run before any goto-instrument optimization and right before verification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that said, I totally misplaced it. Let me move it up.

@@ -153,7 +159,8 @@ impl<'tcx> GotocCtx<'tcx> {
loc: Location,
) -> (Expr, Stmt) {
let c = self.current_fn_mut().get_and_incr_counter();
let var = self.gen_stack_variable(c, &self.current_fn().name(), "temp", t, loc).to_expr();
let var =
self.gen_stack_variable(c, &self.current_fn().name(), "temp", t, loc, false).to_expr();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could/should this use gen_function_local_variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. We would just need to add is_hidden parameter to that function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, a proliferation of boolean arguments isn't good either. Maybe ignore my comment here, or consider a "gen_hidden_local_variable" function or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I thought you were talking about the explicit Symbol::variable call in function.rs.

This does name variables "temp" instead of "var". I would rather not change that in this PR if that's OK for you.

@@ -58,7 +67,8 @@ impl<'tcx> GotocCtx<'tcx> {
let loc = self.codegen_span(&ldata.source_info.span);
let sym =
Symbol::variable(name, base_name, t, self.codegen_span(&ldata.source_info.span))
.with_is_hidden(!ldata.is_user_variable());
.with_is_hidden(!ldata.is_user_variable())
.with_is_parameter(idx > 0 && idx <= num_args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this condition is here? Definitely calls for a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... that's a good point. I'll add some comments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's 0? And the rest are locals I assume?

Copy link
Contributor Author

@celinval celinval Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is the return variable. There is a comment right below that talks about that. I added a comment to the function explaining that. I hope it helps.

@@ -58,7 +67,8 @@ impl<'tcx> GotocCtx<'tcx> {
let loc = self.codegen_span(&ldata.source_info.span);
let sym =
Symbol::variable(name, base_name, t, self.codegen_span(&ldata.source_info.span))
.with_is_hidden(!ldata.is_user_variable());
.with_is_hidden(!ldata.is_user_variable())
.with_is_parameter(idx > 0 && idx <= num_args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's 0? And the rest are locals I assume?

@celinval celinval merged commit f57eb28 into model-checking:main Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants