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

[Boogie Backend] Codegen the arguments to Kani intrinsics inside the functions that handle the intrinsics #2924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kani-compiler/src/codegen_boogie/context/boogie_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ impl<'a, 'tcx> FunctionCtx<'a, 'tcx> {
span: Span,
) -> Stmt {
debug!(?func, ?args, ?destination, ?span, "codegen_funcall");
let fargs = self.codegen_funcall_args(args);
let funct = self.operand_ty(func);
// TODO: Only Kani intrinsics are handled currently
match &funct.kind() {
Expand All @@ -355,12 +354,13 @@ impl<'a, 'tcx> FunctionCtx<'a, 'tcx> {
return self.codegen_kani_intrinsic(
intrinsic,
instance,
fargs,
args,
*destination,
*target,
Some(span),
);
}
let _fargs = self.codegen_funcall_args(args);
todo!()
}
_ => todo!(),
Expand All @@ -383,7 +383,7 @@ impl<'a, 'tcx> FunctionCtx<'a, 'tcx> {
.collect()
}

fn codegen_operand(&self, o: &Operand<'tcx>) -> Expr {
pub(crate) fn codegen_operand(&self, o: &Operand<'tcx>) -> Expr {
trace!(operand=?o, "codegen_operand");
// A MIR operand is either a constant (literal or `const` declaration)
// or a place (being moved or copied for this operation).
Expand Down
22 changes: 11 additions & 11 deletions kani-compiler/src/codegen_boogie/context/kani_intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use super::boogie_ctx::FunctionCtx;

use boogie_ast::boogie_program::{Expr, Stmt};
use rustc_middle::mir::{BasicBlock, Place};
use boogie_ast::boogie_program::Stmt;
use rustc_middle::mir::{BasicBlock, Operand, Place};
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_span::Span;
use std::str::FromStr;
Expand Down Expand Up @@ -49,32 +49,32 @@ impl<'a, 'tcx> FunctionCtx<'a, 'tcx> {
&self,
intrinsic: KaniIntrinsic,
instance: Instance<'tcx>,
fargs: Vec<Expr>,
args: &[Operand<'tcx>],
assign_to: Place<'tcx>,
target: Option<BasicBlock>,
span: Option<Span>,
) -> Stmt {
match intrinsic {
KaniIntrinsic::KaniAssert => {
self.codegen_kani_assert(instance, fargs, assign_to, target, span)
self.codegen_kani_assert(instance, args, assign_to, target, span)
}
KaniIntrinsic::KaniAssume => {
self.codegen_kani_assume(instance, fargs, assign_to, target, span)
self.codegen_kani_assume(instance, args, assign_to, target, span)
}
}
}

pub fn codegen_kani_assert(
&self,
_instance: Instance<'tcx>,
mut fargs: Vec<Expr>,
args: &[Operand<'tcx>],
_assign_to: Place<'tcx>,
_target: Option<BasicBlock>,
_span: Option<Span>,
) -> Stmt {
// TODO: ignoring the `'static str` argument for now
assert_eq!(fargs.len(), 1); // 2);
let cond = fargs.remove(0);
assert_eq!(args.len(), 2);
let cond = self.codegen_operand(&args[0]);
// TODO: handle message
// TODO: handle location

Expand All @@ -89,13 +89,13 @@ impl<'a, 'tcx> FunctionCtx<'a, 'tcx> {
pub fn codegen_kani_assume(
&self,
_instance: Instance<'tcx>,
mut fargs: Vec<Expr>,
args: &[Operand<'tcx>],
_assign_to: Place<'tcx>,
_target: Option<BasicBlock>,
_span: Option<Span>,
) -> Stmt {
assert_eq!(fargs.len(), 1);
let cond = fargs.remove(0);
assert_eq!(args.len(), 1);
let cond = self.codegen_operand(&args[0]);
// TODO: handle location

Stmt::Block {
Expand Down
Loading