Repository navigation
Add a loop's dead temporaries and loop-body variables to an explicit loop_modifies #5071
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -881,13 +881,25 @@ impl GotocHook for LoopInvariantRegister { | |
| let mut stmt = Stmt::goto(bb_label(target.unwrap()), loc) | ||
| .with_loop_contracts(func_exp.call(fargs).cast_to(Type::CInteger(CIntType::Bool))); | ||
| let current_fn = gcx.current_fn().instance_stable(); | ||
| let mut storage_live = Vec::new(); | ||
| if let Some(mut assigns) = gcx.loop_modifies.remove(&(current_fn, instance)) { | ||
| // The user wrote a loop modifies clause, possibly without any target. Add the | ||
| // locals that the loop contract transformation makes live across iterations of | ||
| // this loop, which the user cannot name (without a user clause, CBMC infers the | ||
| // clause instead). | ||
| let generated = | ||
| gcx.transformer.generated_loop_modifies(current_fn, instance).to_vec(); | ||
| // The storage of such a local can end in the loop body, which can make it the | ||
| // dead object (see `codegen_storage_live`) when the latch jumps back to the | ||
| // loop head, where the loop havocs it. It is dead there: mark its storage live, | ||
| // as its `StorageLive` in the body would. That is one step early: between here | ||
| // and the back edge CBMC only checks the invariant and the assigns clause, so an | ||
| // invariant that reads the local through a dangling pointer loses its dead-object | ||
| // check on this path. A pointer to the local that the loop writes must be in the | ||
| // write set, though, so it is havocked at the head, and the step case still flags | ||
| // the read (test `loop_modifies_returned_local_dangling`). | ||
| storage_live = | ||
| generated.iter().map(|local| gcx.codegen_storage_live(*local, loc)).collect(); | ||
|
Comment on lines
+901
to
+902
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A pointer to such a local that the loop writes must itself be in the write set, so it is havocked at the head, and the step case still flags the read. 9510ceb adds
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dangling-pointer test covers a pointer the loop names (
Either one with the invariant reading through the pointer should fail with |
||
| assigns.extend(generated.into_iter().map(|local| gcx.codegen_local(local, loc))); | ||
| if assigns.is_empty() { | ||
| // The clause has no target (e.g. `#[kani::loop_modifies()]`, or only targets | ||
|
|
@@ -913,15 +925,14 @@ impl GotocHook for LoopInvariantRegister { | |
|
|
||
| // Add `free(0)` to make sure the body of `free` won't be dropped to | ||
| // satisfy the requirement of DFCC. | ||
| Stmt::block( | ||
| vec![ | ||
| BuiltinFn::Free | ||
| .call(vec![Expr::pointer_constant(0, Type::void_pointer())], loc) | ||
| .as_stmt(loc), | ||
| stmt, | ||
| ], | ||
| loc, | ||
| ) | ||
| let mut stmts = vec![ | ||
| BuiltinFn::Free | ||
| .call(vec![Expr::pointer_constant(0, Type::void_pointer())], loc) | ||
| .as_stmt(loc), | ||
| ]; | ||
| stmts.extend(storage_live); | ||
|
feliperodri marked this conversation as resolved.
Resolved
|
||
| stmts.push(stmt); | ||
| Stmt::block(stmts, loc) | ||
| } else { | ||
| // When loop-contracts is not enabled, codegen | ||
| // assign_to = true | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.