Repository navigation
Audit all assertions that Kani emits and ensure we do not continue execution past a panic - #1428
Conversation
adpaco
left a comment
There was a problem hiding this comment.
Wanted to give some feedback before you do the remaining work here.
My impression is that SafetyCheck was an early attempt to identify all the checks the Kani compiler introduces during code generation. In the case of intrinsics, you could replace most "special" cases with that. But we also check for arithmetic overflows, so when to use ArithmeticOverflow over SafetyCheck?
| Assertion, | ||
| /// Another instrinsic check. | ||
| /// | ||
| /// SPECIAL BEHAVIORL None TODO: Why should this exist? |
There was a problem hiding this comment.
Saw this one is being used for all checks in exact_div. In principle, if we decided to keep it, I think it should be used only for the cases where an exact division cannot be done. Other cases (division by zero, division does not overflow) are better represented by ArithmeticOverflow. At the same time, these are all being introduced by Kani, so we could get replace all of them with SafetyCheck.
| ExpectFail, | ||
| /// Another instrinsic check. | ||
| /// | ||
| /// SPECIAL BEHAVIOR: None TODO: Why should this exist? |
There was a problem hiding this comment.
This is another instance of a check that we include to detect undefined behavior coming from intrinsics. I think that's the purpose of SafetyCheck (i.e., checks added by Kani to detect the violation of safety conditions), so we could use that instead.
celinval
left a comment
There was a problem hiding this comment.
Just a few notes on the variants.
| /// E.g.: User assertions, compiler invariant checks | ||
| /// Ordinary (Rust) assertions and panics. | ||
| /// | ||
| /// SPECIAL BEHAVIOR: None, this is the default type of assertion. |
There was a problem hiding this comment.
I would like to note that these are checks that would fail in a concrete execution (i.e.: that is either introduced by the compiler or the user). The executable trace feature that @sanjit-bhat just merged relies on that to know which failures can be reproduced.
| UnsupportedConstruct, | ||
| /// When Rust determines code is unreachable, this is the `assert(false)` we emit. | ||
| /// | ||
| /// SPECIAL BEHAVIOR: None TODO: Why should this exist? |
There was a problem hiding this comment.
I think this one could be part of SanityCheck.
|
Here are my notes on the assertions audit.
I chased assertion/assumption/etc related code up from the base types in BuiltinFn
StmtBody
assert.rs
I think there's a followup task for some renaming that could be done here. |
| } | ||
|
|
||
| /// Generates a CBMC assumption. | ||
| pub fn codegen_assume(&self, cond: Expr, loc: Location) -> Stmt { |
There was a problem hiding this comment.
We don't use self? What's the value of this over just Stmt:assume? Is it that this keeps things regular?
There was a problem hiding this comment.
Yes: Several of these don't actually use self but some could in the future. I thought about this and decided that it might be best to keep them all regular. (In fact, the weirdest one was introducing codegen_assume, but I felt that having NO references to the cprover_bindings assert/assume/etc stuff outside of this file was a consistency worth having...)
There was a problem hiding this comment.
You could also just use pure functions without the self. I do agree that for consistency sake, we might as well not use Stmt directly.
|
|
||
| // Since `cond` might have side effects, assign it to a temporary | ||
| // variable so that it's evaluated once, then assert and assume it | ||
| // TODO: I don't think `cond` can have side effects, this is MIR, it's going to be temps |
There was a problem hiding this comment.
Can we just assert that?
There was a problem hiding this comment.
This code bothered me, but it's a distraction from the point of this PR, but I couldn't help but shove a comment in there for later...
| .as_stmt(Location::none()); | ||
| let unimplemented = ctx.codegen_unimplemented_stmt( | ||
| format!("drop_in_place for {}", drop_sym_name).as_str(), | ||
| Location::none(), |
There was a problem hiding this comment.
I'm fixing missing locations in some of the statement stuff, but apparently here is vtable generation we don't really have a location?
| let body = self.codegen_mimic_unimplemented( | ||
| &readable_name, | ||
| loc, | ||
| // There actually are links to specific issues in `should_skip_current_fn`... |
There was a problem hiding this comment.
Should we keep a map from fn-name to url?
There was a problem hiding this comment.
Make should_skip_current_fn
fn should_skip_current_fn(&self) -> Option<&str> {
let current_fn_name =
with_no_trimmed_paths!(self.tcx.def_path_str(self.current_fn().instance().def_id()));
// We cannot use self.current_fn().readable_name() because it gives the monomorphized type, which is more difficult to match on.
// Ideally we should not rely on the pretty-printed name here. Tracked here: https://github.com/model-checking/kani/issues/1374
match current_fn_name.as_str() {
// https://github.com/model-checking/kani/issues/202
"fmt::ArgumentV1::<'a>::as_usize" => Some("https://github.com/model-checking/kani/issues/202"),
// ...
_ => None,
}
}There was a problem hiding this comment.
I thought about sneaking this change in here but there are some other un-linked skips in there, and it seemed like too much to figure out now.
|
I opened a tracking issue for PropertyClass stuff: #1551 Propagated locations a bit more, fixed some comments. |
danielsn
left a comment
There was a problem hiding this comment.
A couple places where we could still use tracking issues, and some work for future PRs.
Otherwise LGTM.
Description of changes:
Audit all assertions that Kani generates, and ensure we consistently use cbmc's assert-assume pattern.
assert.rsPropertyClasses that I'm not sure if we want necessarily. Out of scope for this PR however.Resolved issues:
Call-outs:
Testing:
How is this change tested? existing tests, some of which required changes due to new behavior
Is this a refactor change? yes but also no since wrong-behaviors were identified
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.