Skip to content

Commit

Permalink
Merge branch 'main' into toolchain-2023-09-07-manual
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig authored Sep 8, 2023
2 parents ff5d36c + 1e3409d commit f5edcd3
Show file tree
Hide file tree
Showing 54 changed files with 1,478 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
name: Kani Performance Benchmarks
on:
push:
tags:
- kani-*
branches:
- 'main'
pull_request:
Expand Down
44 changes: 44 additions & 0 deletions kani-compiler/src/codegen_cprover_gotoc/overrides/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,49 @@ impl<'tcx> GotocHook<'tcx> for MemCmp {
}
}

/// A builtin that is essentially a C-style dereference operation, creating an
/// unsafe shallow copy. Importantly either this copy or the original needs to
/// be `mem::forget`en or a double-free will occur.
///
/// Takes in a `&T` reference and returns a `T` (like clone would but without
/// cloning). Breaks ownership rules and is only used in the context of function
/// contracts where we can structurally guarantee the use is safe.
struct UntrackedDeref;

impl<'tcx> GotocHook<'tcx> for UntrackedDeref {
fn hook_applies(&self, tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
matches_function(tcx, instance, "KaniUntrackedDeref")
}

fn handle(
&self,
tcx: &mut GotocCtx<'tcx>,
_instance: Instance<'tcx>,
mut fargs: Vec<Expr>,
assign_to: Place<'tcx>,
_target: Option<BasicBlock>,
span: Option<Span>,
) -> Stmt {
assert_eq!(
fargs.len(),
1,
"Invariant broken. `untracked_deref` should only be given one argument. \
This function should only be called from code generated by kani macros, \
as such this is likely a code-generation error."
);
let loc = tcx.codegen_span_option(span);
Stmt::block(
vec![Stmt::assign(
unwrap_or_return_codegen_unimplemented_stmt!(tcx, tcx.codegen_place(&assign_to))
.goto_expr,
fargs.pop().unwrap().dereference(),
loc,
)],
loc,
)
}
}

pub fn fn_hooks<'tcx>() -> GotocHooks<'tcx> {
GotocHooks {
hooks: vec![
Expand All @@ -335,6 +378,7 @@ pub fn fn_hooks<'tcx>() -> GotocHooks<'tcx> {
Rc::new(Nondet),
Rc::new(RustAlloc),
Rc::new(MemCmp),
Rc::new(UntrackedDeref),
],
}
}
Expand Down
Loading

0 comments on commit f5edcd3

Please sign in to comment.