Skip to content
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
95 changes: 0 additions & 95 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,6 @@ dependencies = [
"which 7.0.3",
]

[[package]]
name = "chrono"
version = "0.4.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
dependencies = [
"iana-time-zone",
"num-traits",
"windows-link",
]

[[package]]
name = "clap"
version = "4.6.7"
Expand Down Expand Up @@ -464,12 +453,6 @@ dependencies = [
"unicode-segmentation",
]

[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"

[[package]]
name = "core_detect"
version = "1.0.0"
Expand Down Expand Up @@ -1009,30 +992,6 @@ dependencies = [
"windows-sys",
]

[[package]]
name = "iana-time-zone"
version = "0.1.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]

[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]

[[package]]
name = "ident_case"
version = "1.0.1"
Expand Down Expand Up @@ -1220,7 +1179,6 @@ version = "0.68.0"
dependencies = [
"anyhow",
"cargo_metadata",
"chrono",
"clap",
"comfy-table",
"console",
Expand Down Expand Up @@ -2836,65 +2794,12 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

[[package]]
name = "windows-core"
version = "0.62.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]

[[package]]
name = "windows-implement"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]

[[package]]
name = "windows-interface"
version = "0.59.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]

[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"

[[package]]
name = "windows-result"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
dependencies = [
"windows-link",
]

[[package]]
name = "windows-strings"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
dependencies = [
"windows-link",
]

[[package]]
name = "windows-sys"
version = "0.61.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl GotocCtx<'_, '_> {
/// Checks whether C-FFI has been enabled or not.
/// When enabled, we blindly encode the function type as is.
fn is_cffi_enabled(&self) -> bool {
self.queries.args().unstable_features.contains(&"c-ffi".to_string())
self.queries.args().unstable_features.iter().any(|arg| arg == "c-ffi")
}

/// Generate code for a foreign function shim.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl GotocCtx<'_, '_> {

// Get the order from internal body for now.
let blocks: Vec<_> = reverse_postorder(&body).collect();
if self.queries.args().unstable_features.contains(&"loop-contracts".to_string())
if self.queries.args().unstable_features.iter().any(|arg| arg == "loop-contracts")
&& body.var_debug_info.iter().any(|info| info.name == "kani_loop_decreases")
{
// Used to attach decreases clauses to their loops. The head of a loop with a loop
Expand Down
10 changes: 8 additions & 2 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ impl GotocCtx<'_, '_> {
.queries
.args()
.unstable_features
.contains(&"loop-contracts".to_string())
.iter()
.any(|arg| arg == "loop-contracts")
{
self.report_loop_decreases_without_loop_contracts(stmt.source_info.span);
return Stmt::skip(location);
Expand Down Expand Up @@ -520,7 +521,12 @@ impl GotocCtx<'_, '_> {
TerminatorKind::Call { func, args, destination, target, .. } => {
if self.is_loop_decreases_binding(destination.local) {
let span = term.source_info.span;
if self.queries.args().unstable_features.contains(&"loop-contracts".to_string())
if self
.queries
.args()
.unstable_features
.iter()
.any(|arg| arg == "loop-contracts")
{
// The measure of a decreases clause is the result of a call, which is
// only computed before the loop. Use the value of the binding as the
Expand Down
4 changes: 4 additions & 0 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ impl<'tcx, 'r> GotocCtx<'tcx, 'r> {
ty::UnsafeBinder(_) => todo!(
"Implement support for UnsafeBinder https://github.com/rust-lang/rust/issues/130516"
),
// View types (a view over a subset of an ADT's fields) are an incomplete rustc
// feature that rustc's own codegen backends do not support yet.
ty::View(..) => unimplemented!("view types are not supported by Kani"),
}
}

Expand Down Expand Up @@ -1115,6 +1118,7 @@ impl<'tcx, 'r> GotocCtx<'tcx, 'r> {
ty::UnsafeBinder(_) => todo!(
"Implement support for UnsafeBinder https://github.com/rust-lang/rust/issues/130516"
),
ty::View(..) => unimplemented!("view types are not supported by Kani"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use crate::codegen_cprover_gotoc::GotocCtx;
use crate::kani_middle::attributes::attrs_by_path;
use crate::kani_middle::attributes::{attr_value_str, attrs_by_path};
use cbmc::InternedString;
use cbmc::goto_program::{Expr, Stmt};
use rustc_ast::attr::AttributeExt;
use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::Instance as InstanceInternal;
use rustc_middle::ty::{TyCtxt, UpvarCapture};
Expand Down Expand Up @@ -451,8 +450,7 @@ fn is_generated_contract_closure(tcx: TyCtxt, closure_def_id: rustc_span::def_id
let Some((callee, _)) = func.const_fn_def() else {
continue;
};
let marker =
attrs_by_path(tcx, callee, &fn_marker_path).next().and_then(|attr| attr.value_str());
let marker = attrs_by_path(tcx, callee, &fn_marker_path).next().and_then(attr_value_str);
if !matches!(
marker.as_ref().map(|marker| marker.as_str()),
Some("kani_force_fn_once" | "kani_force_fn_once_with_args" | "kani_register_contract")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ impl GotocHook for LoopInvariantRegister {

gcx.has_loop_contracts = true;

if gcx.queries.args().unstable_features.contains(&"loop-contracts".to_string()) {
if gcx.queries.args().unstable_features.iter().any(|arg| arg == "loop-contracts") {
// When loop-contracts is enabled, codegen
// free(0)
// goto target --- with loop contracts annotated.
Expand Down
37 changes: 35 additions & 2 deletions kani-compiler/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,20 @@ fn try_match_simd(intrinsic_instance: &Instance) -> Option<Intrinsic> {
/// Each now has a fallback body that calls a per-width libm function. Some of those have no CBMC
/// model (e.g. `__powisf2` for `powi`), so Kani keeps its own model for the widths it has one for;
/// see [`uses_kani_model`].
pub const GENERIC_FLOAT_INTRINSICS: &[&str] =
&["ceil", "floor", "fma", "powf", "powi", "round", "round_ties_even", "sqrt", "trunc"];
pub const GENERIC_FLOAT_INTRINSICS: &[&str] = &[
"ceil",
"copysign",
"floor",
"fma",
"maximum_number_nsz",
"minimum_number_nsz",
"powf",
"powi",
"round",
"round_ties_even",
"sqrt",
"trunc",
];

/// The Kani model of the generic float intrinsic `name` for the float type of its first argument,
/// if Kani has one for that width (f32 and f64).
Expand All @@ -768,6 +780,27 @@ fn generic_float_intrinsic(name: &str, sig: &FnSig) -> Option<Intrinsic> {
CeilF64
}
}
"copysign" => {
if f32 {
CopySignF32
} else {
CopySignF64
}
}
"maximum_number_nsz" => {
if f32 {
MaxNumF32
} else {
MaxNumF64
}
}
"minimum_number_nsz" => {
if f32 {
MinNumF32
} else {
MinNumF64
}
}
"floor" => {
if f32 {
FloorF32
Expand Down
18 changes: 16 additions & 2 deletions kani-compiler/src/kani_middle/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::collections::{BTreeMap, HashSet};

use kani_metadata::{CbmcSolver, HarnessAttributes, HarnessKind, Stub};
use quote::ToTokens;
use rustc_ast::attr::AttributeExt;
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind};
use rustc_attr_ir::{AttrArgs, AttrItem, Attribute};
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -44,7 +43,22 @@ pub fn attrs_by_path<'tcx>(
) -> impl Iterator<Item = &'tcx Attribute> {
#[allow(deprecated)]
let attrs = tcx.get_all_attrs(def_id);
attrs.iter().filter(move |attr| attr.path_matches(path))
attrs.iter().filter(move |attr| attr_path_matches(attr, path))
}

/// Whether `attr` is a tool (or derive helper) attribute whose path is `path`. rustc removed
/// `Attribute::path_matches` (nightly-2026-11-17); this is the same test it used to perform.
fn attr_path_matches(attr: &Attribute, path: &[Symbol]) -> bool {
match attr {
Attribute::Tool(item) | Attribute::DeriveHelper(item) => item.path.segments.iter().eq(path),
_ => false,
}
}

/// The string value of a `path = "value"` attribute, e.g. `#[kanitool::fn_marker = "..."]`.
/// rustc removed `Attribute::value_str` (nightly-2026-11-17); `value_lit` gives the literal.
pub fn attr_value_str(attr: &Attribute) -> Option<Symbol> {
attr.value_lit().and_then(|lit| lit.kind.str())
}

/// The item of a `kanitool::*` attribute. rustc does not parse tool attributes, so they are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ impl MirVisitor for CheckUninitVisitor {
value: true,
position: InsertPosition::After,
}),
// An intrinsic that Kani does not know, but whose fallback body it uses
// (e.g. `integer_max`, new in nightly-2026-11-17), runs ordinary MIR,
// which is instrumented like any other function: an ordinary call.
Intrinsic::Unimplemented { .. }
if !crate::intrinsics::uses_kani_model(&instance) => {}
intrinsic => {
self.push_target(MemoryInitOp::Unsupported {
reason: format!("Kani does not support reasoning about memory initialization of intrinsic `{intrinsic:?}`."),
Expand Down
2 changes: 1 addition & 1 deletion kani-compiler/src/kani_middle/transform/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl TransformPass for AnyModifiesPass {
Self: Sized,
{
// TODO: Check if the harness has proof_for_contract
query_db.args().unstable_features.contains(&"function-contracts".to_string())
query_db.args().unstable_features.iter().any(|arg| arg == "function-contracts")
&& self.kani_any.is_some()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl TransformPass for LoopContractPass {
where
Self: Sized,
{
query_db.args().unstable_features.contains(&"loop-contracts".to_string())
query_db.args().unstable_features.iter().any(|arg| arg == "loop-contracts")
}

/// Run a transformation pass on the whole codegen unit.
Expand Down
2 changes: 1 addition & 1 deletion kani-compiler/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static JSON_PANIC_HOOK: LazyLock<Box<dyn Fn(&panic::PanicHookInfo<'_>) + Sync +
#[allow(clippy::arc_with_non_send_sync)]
Some(Arc::new(SourceMap::new(FilePathMapping::empty()))),
false,
HumanReadableErrorType { short: false, unicode: false },
HumanReadableErrorType { no_graphics: false, short: false, unicode: false },
ColorConfig::Never,
);
let diagnostic = DiagInner::new(rustc_errors::Level::Bug, msg);
Expand Down
1 change: 0 additions & 1 deletion kani-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ tracing-subscriber = {version = "0.3.20", features = ["env-filter", "json", "fmt
which = "8"
time = {version = "0.3.47", features = ["formatting"]}
tokio = { version = "1.40.0", features = ["io-util", "process", "rt", "time"] }
chrono = { version = "0.4.41", default-features = false, features = [ "clock" ]}
indicatif = "0.18"


Expand Down
2 changes: 1 addition & 1 deletion kani-driver/src/concrete_playback/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn run_test(exe: &Path, args: &KaniPlaybackArgs) -> Result<()> {
let mut cmd = Command::new(exe);

if args.playback.common_opts.verbose()
&& !args.playback.test_args.contains(&"--nocapture".to_string())
&& !args.playback.test_args.iter().any(|arg| arg == "--nocapture")
{
// Repeated arguments cause an execution error.
cmd.arg("--nocapture");
Expand Down
Loading
Loading