Skip to content

Commit bfa2a98

Browse files
authored
Upgrade toolchain to 2025-04-01 (#3973)
Culprit PRs: - rust-lang/rust#138384 - rust-lang/rust#127173 - rust-lang/rust#138659, Resolves #3961, #3976 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 4e81792 commit bfa2a98

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

kani-compiler/src/codegen_cprover_gotoc/codegen/foreign_function.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,35 @@ impl GotocCtx<'_> {
4949
/// handled later.
5050
pub fn codegen_foreign_fn(&mut self, instance: Instance) -> &Symbol {
5151
debug!(?instance, "codegen_foreign_function");
52-
let fn_name = instance.mangled_name().intern();
52+
let trimmed_fn_name = instance.trimmed_name().intern();
53+
let mangled_fn_name = instance.mangled_name().intern();
5354
let loc = self.codegen_span_stable(instance.def.span());
54-
if self.symbol_table.contains(fn_name) {
55-
// Symbol has been added (either a built-in CBMC function or a Rust allocation function).
56-
self.symbol_table.lookup(fn_name).unwrap()
57-
} else if RUST_ALLOC_FNS.contains(&fn_name)
58-
|| (self.is_cffi_enabled() && instance.fn_abi().unwrap().conv == CallConvention::C)
59-
{
55+
if self.symbol_table.contains(mangled_fn_name) {
56+
// Symbol has been added (a built-in CBMC function)
57+
self.symbol_table.lookup(mangled_fn_name).unwrap()
58+
} else if self.symbol_table.contains(trimmed_fn_name) {
59+
// Symbol has been added (a Rust allocation function)
60+
self.symbol_table.lookup(trimmed_fn_name).unwrap()
61+
} else if RUST_ALLOC_FNS.contains(&trimmed_fn_name) {
6062
// Add a Rust alloc lib function as is declared by core.
63+
// We use the trimmed name to ensure that it matches the function names in kani_lib.c
64+
self.ensure(trimmed_fn_name, |gcx, _| {
65+
let typ = gcx.codegen_ffi_type(instance);
66+
Symbol::function(trimmed_fn_name, typ, None, instance.name(), loc)
67+
.with_is_extern(true)
68+
})
69+
} else if self.is_cffi_enabled() && instance.fn_abi().unwrap().conv == CallConvention::C {
6170
// When C-FFI feature is enabled, we just trust the rust declaration.
6271
// TODO: Add proper casting and clashing definitions check.
6372
// https://github.com/model-checking/kani/issues/1350
6473
// https://github.com/model-checking/kani/issues/2426
65-
self.ensure(fn_name, |gcx, _| {
74+
self.ensure(mangled_fn_name, |gcx, _| {
6675
let typ = gcx.codegen_ffi_type(instance);
67-
Symbol::function(fn_name, typ, None, instance.name(), loc).with_is_extern(true)
76+
Symbol::function(mangled_fn_name, typ, None, instance.name(), loc)
77+
.with_is_extern(true)
6878
})
6979
} else {
70-
let shim_name = format!("{fn_name}_ffi_shim");
80+
let shim_name = format!("{mangled_fn_name}_ffi_shim");
7181
trace!(?shim_name, "codegen_foreign_function");
7282
self.ensure(&shim_name, |gcx, _| {
7383
// Generate a shim with an unsupported C-FFI error message.

kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ pub mod rustc_smir {
266266
for mapping in &cov_info.mappings {
267267
let Code { bcb } = mapping.kind else { unreachable!() };
268268
let source_map = tcx.sess.source_map();
269-
let file = source_map.lookup_source_file(cov_info.body_span.lo());
269+
let file = source_map.lookup_source_file(mapping.span.lo());
270270
if bcb == coverage {
271271
return Some((
272-
make_source_region(source_map, cov_info, &file, mapping.span).unwrap(),
273-
rustc_internal::stable(cov_info.body_span).get_filename(),
272+
make_source_region(source_map, &file, mapping.span).unwrap(),
273+
rustc_internal::stable(mapping.span).get_filename(),
274274
));
275275
}
276276
}

kani-compiler/src/codegen_cprover_gotoc/codegen/source_region.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
//! the `Span` to `CoverageRegion` conversion defined in
66
//! https://github.com/rust-lang/rust/tree/master/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs
77
8-
use rustc_middle::mir::coverage::FunctionCoverageInfo;
98
use rustc_span::Span;
109
use rustc_span::source_map::SourceMap;
1110
use rustc_span::{BytePos, SourceFile};
@@ -27,33 +26,22 @@ impl Debug for SourceRegion {
2726
}
2827
}
2928

30-
fn ensure_non_empty_span(
31-
source_map: &SourceMap,
32-
fn_cov_info: &FunctionCoverageInfo,
33-
span: Span,
34-
) -> Option<Span> {
29+
fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> {
3530
if !span.is_empty() {
3631
return Some(span);
3732
}
38-
let lo = span.lo();
39-
let hi = span.hi();
40-
// The span is empty, so try to expand it to cover an adjacent '{' or '}',
41-
// but only within the bounds of the body span.
42-
let try_next = hi < fn_cov_info.body_span.hi();
43-
let try_prev = fn_cov_info.body_span.lo() < lo;
44-
if !(try_next || try_prev) {
45-
return None;
46-
}
33+
34+
// The span is empty, so try to enlarge it to cover an adjacent '{' or '}'.
4735
source_map
4836
.span_to_source(span, |src, start, end| try {
4937
// Adjusting span endpoints by `BytePos(1)` is normally a bug,
5038
// but in this case we have specifically checked that the character
5139
// we're skipping over is one of two specific ASCII characters, so
5240
// adjusting by exactly 1 byte is correct.
53-
if try_next && src.as_bytes()[end] == b'{' {
54-
Some(span.with_hi(hi + BytePos(1)))
55-
} else if try_prev && src.as_bytes()[start - 1] == b'}' {
56-
Some(span.with_lo(lo - BytePos(1)))
41+
if src.as_bytes().get(end).copied() == Some(b'{') {
42+
Some(span.with_hi(span.hi() + BytePos(1)))
43+
} else if start > 0 && src.as_bytes()[start - 1] == b'}' {
44+
Some(span.with_lo(span.lo() - BytePos(1)))
5745
} else {
5846
None
5947
}
@@ -104,11 +92,10 @@ fn check_source_region(source_region: SourceRegion) -> Option<SourceRegion> {
10492
/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
10593
pub(crate) fn make_source_region(
10694
source_map: &SourceMap,
107-
fn_cov_info: &FunctionCoverageInfo,
10895
file: &SourceFile,
10996
span: Span,
11097
) -> Option<SourceRegion> {
111-
let span = ensure_non_empty_span(source_map, fn_cov_info, span)?;
98+
let span = ensure_non_empty_span(source_map, span)?;
11299
let lo = span.lo();
113100
let hi = span.hi();
114101
// Column numbers need to be in bytes, so we can't use the more convenient

kani-compiler/src/kani_middle/resolve.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,10 @@ fn resolve_relative(tcx: TyCtxt, current_module: LocalModDefId, name: &str) -> R
432432
let mut glob_imports = vec![];
433433
let result = tcx.hir_module_free_items(current_module).find_map(|item_id| {
434434
let item = tcx.hir_item(item_id);
435-
if item.ident.as_str() == name {
435+
if item.kind.ident().is_some_and(|ident| ident.as_str() == name) {
436436
match item.kind {
437-
ItemKind::Use(use_path, UseKind::Single) => use_path.res[0].opt_def_id(),
438-
ItemKind::ExternCrate(orig_name) => resolve_external(
437+
ItemKind::Use(use_path, UseKind::Single(_)) => use_path.res[0].opt_def_id(),
438+
ItemKind::ExternCrate(orig_name, _) => resolve_external(
439439
tcx,
440440
orig_name.as_ref().map(|sym| sym.as_str()).unwrap_or(name),
441441
),

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
[toolchain]
5-
channel = "nightly-2025-03-18"
5+
channel = "nightly-2025-04-01"
66
components = ["llvm-tools", "rustc-dev", "rust-src", "rustfmt"]

0 commit comments

Comments
 (0)