Skip to content

Commit

Permalink
Merge branch 'main' into fix-2909
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig authored Jun 7, 2024
2 parents efc4769 + 0bb1325 commit ef9ecda
Show file tree
Hide file tree
Showing 104 changed files with 932 additions and 263 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ This file contains notable changes (e.g. breaking changes, major changes, etc.)

This file was introduced starting Kani 0.23.0, so it only contains changes from version 0.23.0 onwards.

## [0.51.0]
## [0.52.0]

## What's Changed
* New section about linter configuraton checking in the doc by @remi-delmas-3000 in https://github.com/model-checking/kani/pull/3198
* Fix `{,e}println!()` by @GrigorenkoPV in https://github.com/model-checking/kani/pull/3209
* Contracts for a few core functions by @celinval in https://github.com/model-checking/kani/pull/3107
* Add simple API for shadow memory by @zhassan-aws in https://github.com/model-checking/kani/pull/3200
* Upgrade Rust toolchain to 2024-05-28 by @zhassan-aws @remi-delmas-3000 @qinheping

**Full Changelog**: https://github.com/model-checking/kani/compare/kani-0.51.0...kani-0.52.0

## [0.51.0]

### What's Changed

* Do not assume that ZST-typed symbols refer to unique objects by @tautschnig in https://github.com/model-checking/kani/pull/3134
* Remove `kani::Arbitrary` from the `modifies` contract instrumentation by @feliperodri in https://github.com/model-checking/kani/pull/3169
Expand Down
25 changes: 16 additions & 9 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"

[[package]]
name = "build-kani"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"anyhow",
"cargo_metadata",
Expand Down Expand Up @@ -228,7 +228,7 @@ dependencies = [

[[package]]
name = "cprover_bindings"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"lazy_static",
"linear-map",
Expand Down Expand Up @@ -405,14 +405,14 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"

[[package]]
name = "kani"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"kani_macros",
]

[[package]]
name = "kani-compiler"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"clap",
"cprover_bindings",
Expand All @@ -433,7 +433,7 @@ dependencies = [

[[package]]
name = "kani-driver"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"anyhow",
"cargo_metadata",
Expand Down Expand Up @@ -461,16 +461,23 @@ dependencies = [

[[package]]
name = "kani-verifier"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"anyhow",
"home",
"os_info",
]

[[package]]
name = "kani_macros"
name = "kani_core"
version = "0.51.0"
dependencies = [
"kani_macros",
]

[[package]]
name = "kani_macros"
version = "0.52.0"
dependencies = [
"proc-macro-error",
"proc-macro2",
Expand All @@ -480,7 +487,7 @@ dependencies = [

[[package]]
name = "kani_metadata"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"clap",
"cprover_bindings",
Expand Down Expand Up @@ -985,7 +992,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"

[[package]]
name = "std"
version = "0.51.0"
version = "0.52.0"
dependencies = [
"kani",
]
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "kani-verifier"
version = "0.51.0"
version = "0.52.0"
edition = "2021"
description = "A bit-precise model checker for Rust."
readme = "README.md"
Expand Down Expand Up @@ -43,6 +43,7 @@ members = [
"kani-driver",
"kani-compiler",
"kani_metadata",
"library/kani_core",
]

# This indicates what package to e.g. build with 'cargo build' without --workspace
Expand All @@ -67,4 +68,5 @@ exclude = [
"tests/script-based-pre",
"tests/script-based-pre/build-cache-bin/target/new_dep",
"tests/script-based-pre/build-cache-dirty/target/new_dep",
"tests/script-based-pre/verify_std_cmd/tmp_dir/target/kani_verify_std",
]
2 changes: 1 addition & 1 deletion cprover_bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "cprover_bindings"
version = "0.51.0"
version = "0.52.0"
edition = "2021"
license = "MIT OR Apache-2.0"
publish = false
Expand Down
2 changes: 1 addition & 1 deletion kani-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "kani-compiler"
version = "0.51.0"
version = "0.52.0"
edition = "2021"
license = "MIT OR Apache-2.0"
publish = false
Expand Down
40 changes: 40 additions & 0 deletions kani-compiler/src/codegen_cprover_gotoc/overrides/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,45 @@ impl GotocHook for UntrackedDeref {
}
}

struct InitContracts;

/// CBMC contracts currently has a limitation where `free` has to be in scope.
/// However, if there is no dynamic allocation in the harness, slicing removes `free` from the
/// scope.
///
/// Thus, this function will basically translate into:
/// ```c
/// // This is a no-op.
/// free(NULL);
/// ```
impl GotocHook for InitContracts {
fn hook_applies(&self, tcx: TyCtxt, instance: Instance) -> bool {
matches_function(tcx, instance.def, "KaniInitContracts")
}

fn handle(
&self,
gcx: &mut GotocCtx,
_instance: Instance,
fargs: Vec<Expr>,
_assign_to: &Place,
target: Option<BasicBlockIdx>,
span: Span,
) -> Stmt {
assert_eq!(fargs.len(), 0,);
let loc = gcx.codegen_span_stable(span);
Stmt::block(
vec![
BuiltinFn::Free
.call(vec![Expr::pointer_constant(0, Type::void_pointer())], loc)
.as_stmt(loc),
Stmt::goto(bb_label(target.unwrap()), loc),
],
loc,
)
}
}

pub fn fn_hooks() -> GotocHooks {
GotocHooks {
hooks: vec![
Expand All @@ -472,6 +511,7 @@ pub fn fn_hooks() -> GotocHooks {
Rc::new(RustAlloc),
Rc::new(MemCmp),
Rc::new(UntrackedDeref),
Rc::new(InitContracts),
],
}
}
Expand Down
7 changes: 6 additions & 1 deletion kani-compiler/src/kani_middle/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ impl<'tcx> ModelIntrinsics<'tcx> {
let arg_ty = args[0].node.ty(&self.local_decls, tcx);
if arg_ty.is_simd() {
// Get the stub definition.
let stub_id = tcx.get_diagnostic_item(Symbol::intern("KaniModelSimdBitmask")).unwrap();
let Some(stub_id) = tcx.get_diagnostic_item(Symbol::intern("KaniModelSimdBitmask"))
else {
// This should only happen when verifying the standard library.
// We don't need to warn here, since the backend will print unsupported constructs.
return;
};
debug!(?func, ?stub_id, "replace_simd_bitmask");

// Get SIMD information from the type.
Expand Down
2 changes: 1 addition & 1 deletion kani-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "kani-driver"
version = "0.51.0"
version = "0.52.0"
edition = "2021"
description = "Build a project with Kani and run all proof harnesses"
license = "MIT OR Apache-2.0"
Expand Down
10 changes: 10 additions & 0 deletions kani-driver/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod assess_args;
pub mod cargo;
pub mod common;
pub mod playback_args;
pub mod std_args;

pub use assess_args::*;

Expand Down Expand Up @@ -90,6 +91,8 @@ pub struct StandaloneArgs {
pub enum StandaloneSubcommand {
/// Execute concrete playback testcases of a local crate.
Playback(Box<playback_args::KaniPlaybackArgs>),
/// Verify the rust standard library.
VerifyStd(Box<std_args::VerifyStdArgs>),
}

#[derive(Debug, clap::Parser)]
Expand Down Expand Up @@ -448,6 +451,13 @@ fn check_no_cargo_opt(is_set: bool, name: &str) -> Result<(), Error> {
impl ValidateArgs for StandaloneArgs {
fn validate(&self) -> Result<(), Error> {
self.verify_opts.validate()?;

match &self.command {
Some(StandaloneSubcommand::VerifyStd(args)) => args.validate()?,
// TODO: Invoke PlaybackArgs::validate()
None | Some(StandaloneSubcommand::Playback(..)) => {}
};

// Cargo target arguments.
check_no_cargo_opt(self.verify_opts.target.bins, "--bins")?;
check_no_cargo_opt(self.verify_opts.target.lib, "--lib")?;
Expand Down
77 changes: 77 additions & 0 deletions kani-driver/src/args/std_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Implements the `verify-std` subcommand handling.
use crate::args::{ValidateArgs, VerificationArgs};
use clap::error::ErrorKind;
use clap::{Error, Parser};
use kani_metadata::UnstableFeature;
use std::path::PathBuf;

/// Verify a local version of the Rust standard library.
///
/// This is an **unstable option** and it the standard library version must be compatible with
/// Kani's toolchain version.
#[derive(Debug, Parser)]
pub struct VerifyStdArgs {
/// The path to the folder containing the crates for the Rust standard library.
/// Note that this directory must be named `library` as used in the Rust toolchain and
/// repository.
pub std_path: PathBuf,

#[command(flatten)]
pub verify_opts: VerificationArgs,
}

impl ValidateArgs for VerifyStdArgs {
fn validate(&self) -> Result<(), Error> {
self.verify_opts.validate()?;

if !self
.verify_opts
.common_args
.unstable_features
.contains(UnstableFeature::UnstableOptions)
{
return Err(Error::raw(
ErrorKind::MissingRequiredArgument,
"The `verify-std` subcommand is unstable and requires -Z unstable-options",
));
}

if !self.std_path.exists() {
Err(Error::raw(
ErrorKind::InvalidValue,
format!(
"Invalid argument: `<STD_PATH>` argument `{}` does not exist",
self.std_path.display()
),
))
} else if !self.std_path.is_dir() {
Err(Error::raw(
ErrorKind::InvalidValue,
format!(
"Invalid argument: `<STD_PATH>` argument `{}` is not a directory",
self.std_path.display()
),
))
} else {
let full_path = self.std_path.canonicalize()?;
let dir = full_path.file_stem().unwrap();
if dir != "library" {
Err(Error::raw(
ErrorKind::InvalidValue,
format!(
"Invalid argument: Expected `<STD_PATH>` to point to the `library` folder \
containing the standard library crates.\n\
Found `{}` folder instead",
dir.to_string_lossy()
),
))
} else {
Ok(())
}
}
}
}
Loading

0 comments on commit ef9ecda

Please sign in to comment.