Skip to content

Commit d84b123

Browse files
authored
Update toolchain to 2022-07-05 (#1340)
* Update toolchain to 2022-07-05 The updates required were related to the following changes: - Simplify memory ordering intrinsics - rust-lang/rust#97423 - once cell renamings - rust-lang/rust#98165 - Rename the ConstS::val field as kind - rust-lang/rust#97935 - Remove the source archive functionality of ArchiveWriter - rust-lang/rust#98098 - Use valtrees as the type-system representation for constant values - rust-lang/rust#96591 * Codegen unimplemented for unsupported constant slices See #1339 for more details. * Fix copyright check * Use codegen_option_span instead
1 parent 6205a56 commit d84b123

File tree

27 files changed

+215
-219
lines changed

27 files changed

+215
-219
lines changed

kani-compiler/src/codegen_cprover_gotoc/archive.rs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,47 +44,16 @@ pub(crate) struct ArArchiveBuilder<'a> {
4444
}
4545

4646
impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
47-
fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self {
48-
let (src_archives, entries) = if let Some(input) = input {
49-
let read_cache = ReadCache::new(File::open(input).unwrap());
50-
let archive = ArchiveFile::parse(&read_cache).unwrap();
51-
let mut entries = Vec::new();
52-
53-
for entry in archive.members() {
54-
let entry = entry.unwrap();
55-
entries.push((
56-
entry.name().to_vec(),
57-
ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() },
58-
));
59-
}
60-
61-
(vec![read_cache.into_inner()], entries)
62-
} else {
63-
(vec![], Vec::new())
64-
};
65-
47+
fn new(sess: &'a Session, output: &Path) -> Self {
6648
ArArchiveBuilder {
6749
sess,
6850
dst: output.to_path_buf(),
6951
use_gnu_style_archive: sess.target.archive_format == "gnu",
70-
src_archives,
71-
entries,
52+
src_archives: vec![],
53+
entries: vec![],
7254
}
7355
}
7456

75-
fn src_files(&mut self) -> Vec<String> {
76-
self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect()
77-
}
78-
79-
fn remove_file(&mut self, name: &str) {
80-
let index = self
81-
.entries
82-
.iter()
83-
.position(|(entry_name, _)| entry_name == name.as_bytes())
84-
.expect("Tried to remove file not existing in src archive");
85-
self.entries.remove(index);
86-
}
87-
8857
fn add_file(&mut self, file: &Path) {
8958
self.entries.push((
9059
file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(),
@@ -116,7 +85,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
11685
Ok(())
11786
}
11887

119-
fn build(mut self) {
88+
fn build(mut self) -> bool {
12089
enum BuilderKind {
12190
Bsd(ar::Builder<File>),
12291
Gnu(ar::GnuBuilder<File>),
@@ -168,6 +137,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
168137
};
169138

170139
// Add all files
140+
let any_members = !entries.is_empty();
171141
for (entry_name, data) in entries.into_iter() {
172142
let header = ar::Header::new(entry_name, data.len() as u64);
173143
match builder {
@@ -178,6 +148,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
178148

179149
// Finalize archive
180150
std::mem::drop(builder);
151+
any_members
181152
}
182153

183154
fn inject_dll_import_lib(

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

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -396,79 +396,79 @@ impl<'tcx> GotocCtx<'tcx> {
396396
"assumption failed",
397397
loc,
398398
),
399-
"atomic_and" => codegen_atomic_binop!(bitand),
400-
"atomic_and_acq" => codegen_atomic_binop!(bitand),
399+
"atomic_and_seqcst" => codegen_atomic_binop!(bitand),
400+
"atomic_and_acquire" => codegen_atomic_binop!(bitand),
401401
"atomic_and_acqrel" => codegen_atomic_binop!(bitand),
402-
"atomic_and_rel" => codegen_atomic_binop!(bitand),
402+
"atomic_and_release" => codegen_atomic_binop!(bitand),
403403
"atomic_and_relaxed" => codegen_atomic_binop!(bitand),
404404
name if name.starts_with("atomic_cxchg") => {
405405
self.codegen_atomic_cxchg(intrinsic, fargs, p, loc)
406406
}
407-
"atomic_fence" => self.codegen_atomic_noop(intrinsic, loc),
408-
"atomic_fence_acq" => self.codegen_atomic_noop(intrinsic, loc),
407+
"atomic_fence_seqcst" => self.codegen_atomic_noop(intrinsic, loc),
408+
"atomic_fence_acquire" => self.codegen_atomic_noop(intrinsic, loc),
409409
"atomic_fence_acqrel" => self.codegen_atomic_noop(intrinsic, loc),
410-
"atomic_fence_rel" => self.codegen_atomic_noop(intrinsic, loc),
411-
"atomic_load" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
412-
"atomic_load_acq" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
410+
"atomic_fence_release" => self.codegen_atomic_noop(intrinsic, loc),
411+
"atomic_load_seqcst" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
412+
"atomic_load_acquire" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
413413
"atomic_load_relaxed" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
414414
"atomic_load_unordered" => self.codegen_atomic_load(intrinsic, fargs, p, loc),
415-
"atomic_max" => codegen_atomic_binop!(max),
416-
"atomic_max_acq" => codegen_atomic_binop!(max),
415+
"atomic_max_seqcst" => codegen_atomic_binop!(max),
416+
"atomic_max_acquire" => codegen_atomic_binop!(max),
417417
"atomic_max_acqrel" => codegen_atomic_binop!(max),
418-
"atomic_max_rel" => codegen_atomic_binop!(max),
418+
"atomic_max_release" => codegen_atomic_binop!(max),
419419
"atomic_max_relaxed" => codegen_atomic_binop!(max),
420-
"atomic_min" => codegen_atomic_binop!(min),
421-
"atomic_min_acq" => codegen_atomic_binop!(min),
420+
"atomic_min_seqcst" => codegen_atomic_binop!(min),
421+
"atomic_min_acquire" => codegen_atomic_binop!(min),
422422
"atomic_min_acqrel" => codegen_atomic_binop!(min),
423-
"atomic_min_rel" => codegen_atomic_binop!(min),
423+
"atomic_min_release" => codegen_atomic_binop!(min),
424424
"atomic_min_relaxed" => codegen_atomic_binop!(min),
425-
"atomic_nand" => codegen_atomic_binop!(bitnand),
426-
"atomic_nand_acq" => codegen_atomic_binop!(bitnand),
425+
"atomic_nand_seqcst" => codegen_atomic_binop!(bitnand),
426+
"atomic_nand_acquire" => codegen_atomic_binop!(bitnand),
427427
"atomic_nand_acqrel" => codegen_atomic_binop!(bitnand),
428-
"atomic_nand_rel" => codegen_atomic_binop!(bitnand),
428+
"atomic_nand_release" => codegen_atomic_binop!(bitnand),
429429
"atomic_nand_relaxed" => codegen_atomic_binop!(bitnand),
430-
"atomic_or" => codegen_atomic_binop!(bitor),
431-
"atomic_or_acq" => codegen_atomic_binop!(bitor),
430+
"atomic_or_seqcst" => codegen_atomic_binop!(bitor),
431+
"atomic_or_acquire" => codegen_atomic_binop!(bitor),
432432
"atomic_or_acqrel" => codegen_atomic_binop!(bitor),
433-
"atomic_or_rel" => codegen_atomic_binop!(bitor),
433+
"atomic_or_release" => codegen_atomic_binop!(bitor),
434434
"atomic_or_relaxed" => codegen_atomic_binop!(bitor),
435-
"atomic_singlethreadfence" => self.codegen_atomic_noop(intrinsic, loc),
436-
"atomic_singlethreadfence_acq" => self.codegen_atomic_noop(intrinsic, loc),
435+
"atomic_singlethreadfence_seqcst" => self.codegen_atomic_noop(intrinsic, loc),
436+
"atomic_singlethreadfence_acquire" => self.codegen_atomic_noop(intrinsic, loc),
437437
"atomic_singlethreadfence_acqrel" => self.codegen_atomic_noop(intrinsic, loc),
438-
"atomic_singlethreadfence_rel" => self.codegen_atomic_noop(intrinsic, loc),
439-
"atomic_store" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
440-
"atomic_store_rel" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
438+
"atomic_singlethreadfence_release" => self.codegen_atomic_noop(intrinsic, loc),
439+
"atomic_store_seqcst" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
440+
"atomic_store_release" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
441441
"atomic_store_relaxed" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
442442
"atomic_store_unordered" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
443-
"atomic_umax" => codegen_atomic_binop!(max),
444-
"atomic_umax_acq" => codegen_atomic_binop!(max),
443+
"atomic_umax_seqcst" => codegen_atomic_binop!(max),
444+
"atomic_umax_acquire" => codegen_atomic_binop!(max),
445445
"atomic_umax_acqrel" => codegen_atomic_binop!(max),
446-
"atomic_umax_rel" => codegen_atomic_binop!(max),
446+
"atomic_umax_release" => codegen_atomic_binop!(max),
447447
"atomic_umax_relaxed" => codegen_atomic_binop!(max),
448-
"atomic_umin" => codegen_atomic_binop!(min),
449-
"atomic_umin_acq" => codegen_atomic_binop!(min),
448+
"atomic_umin_seqcst" => codegen_atomic_binop!(min),
449+
"atomic_umin_acquire" => codegen_atomic_binop!(min),
450450
"atomic_umin_acqrel" => codegen_atomic_binop!(min),
451-
"atomic_umin_rel" => codegen_atomic_binop!(min),
451+
"atomic_umin_release" => codegen_atomic_binop!(min),
452452
"atomic_umin_relaxed" => codegen_atomic_binop!(min),
453-
"atomic_xadd" => codegen_atomic_binop!(plus),
454-
"atomic_xadd_acq" => codegen_atomic_binop!(plus),
453+
"atomic_xadd_seqcst" => codegen_atomic_binop!(plus),
454+
"atomic_xadd_acquire" => codegen_atomic_binop!(plus),
455455
"atomic_xadd_acqrel" => codegen_atomic_binop!(plus),
456-
"atomic_xadd_rel" => codegen_atomic_binop!(plus),
456+
"atomic_xadd_release" => codegen_atomic_binop!(plus),
457457
"atomic_xadd_relaxed" => codegen_atomic_binop!(plus),
458-
"atomic_xchg" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
459-
"atomic_xchg_acq" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
458+
"atomic_xchg_seqcst" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
459+
"atomic_xchg_acquire" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
460460
"atomic_xchg_acqrel" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
461-
"atomic_xchg_rel" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
461+
"atomic_xchg_release" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
462462
"atomic_xchg_relaxed" => self.codegen_atomic_store(intrinsic, fargs, p, loc),
463-
"atomic_xor" => codegen_atomic_binop!(bitxor),
464-
"atomic_xor_acq" => codegen_atomic_binop!(bitxor),
463+
"atomic_xor_seqcst" => codegen_atomic_binop!(bitxor),
464+
"atomic_xor_acquire" => codegen_atomic_binop!(bitxor),
465465
"atomic_xor_acqrel" => codegen_atomic_binop!(bitxor),
466-
"atomic_xor_rel" => codegen_atomic_binop!(bitxor),
466+
"atomic_xor_release" => codegen_atomic_binop!(bitxor),
467467
"atomic_xor_relaxed" => codegen_atomic_binop!(bitxor),
468-
"atomic_xsub" => codegen_atomic_binop!(sub),
469-
"atomic_xsub_acq" => codegen_atomic_binop!(sub),
468+
"atomic_xsub_seqcst" => codegen_atomic_binop!(sub),
469+
"atomic_xsub_acquire" => codegen_atomic_binop!(sub),
470470
"atomic_xsub_acqrel" => codegen_atomic_binop!(sub),
471-
"atomic_xsub_rel" => codegen_atomic_binop!(sub),
471+
"atomic_xsub_release" => codegen_atomic_binop!(sub),
472472
"atomic_xsub_relaxed" => codegen_atomic_binop!(sub),
473473
"bitreverse" => self.codegen_expr_to_place(p, fargs.remove(0).bitreverse()),
474474
// black_box is an identity function that hints to the compiler

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> GotocCtx<'tcx> {
5757
debug!("found literal: {:?}", lit);
5858
let lit = self.monomorphize(lit);
5959

60-
match lit.val() {
60+
match lit.kind() {
6161
// evaluate constant if it has no been evaluated yet
6262
ConstKind::Unevaluated(unevaluated) => {
6363
debug!("The literal was a Unevaluated");
@@ -68,14 +68,15 @@ impl<'tcx> GotocCtx<'tcx> {
6868
self.codegen_const_value(const_val, lit.ty(), span)
6969
}
7070

71-
ConstKind::Value(v) => {
72-
debug!("The literal was a ConstValue {:?}", v);
73-
self.codegen_const_value(v, lit.ty(), span)
71+
ConstKind::Value(valtree) => {
72+
let value = self.tcx.valtree_to_const_val((lit.ty(), valtree));
73+
debug!("The literal was a ConstValue {:?}", value);
74+
self.codegen_const_value(value, lit.ty(), span)
7475
}
7576
_ => {
7677
unreachable!(
7778
"monomorphized item shouldn't have this constant value: {:?}",
78-
lit.val()
79+
lit.kind()
7980
)
8081
}
8182
}
@@ -104,8 +105,6 @@ impl<'tcx> GotocCtx<'tcx> {
104105
ty::Slice(slice_ty) => {
105106
if let Uint(UintTy::U8) = slice_ty.kind() {
106107
// The case where we have a slice of u8 is easy enough: make an array of u8
107-
// TODO: Handle cases with larger int types by making an array of bytes,
108-
// then using byte-extract on it.
109108
let slice =
110109
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
111110
let vec_of_bytes: Vec<Expr> = slice
@@ -123,12 +122,22 @@ impl<'tcx> GotocCtx<'tcx> {
123122
len_expr,
124123
&self.symbol_table,
125124
);
125+
} else {
126+
// TODO: Handle cases with other types such as tuples and larger integers.
127+
let loc = self.codegen_span_option(span.cloned());
128+
let typ = self.codegen_ty(lit_ty);
129+
return self.codegen_unimplemented(
130+
"Constant slice value with 2+ bytes",
131+
typ,
132+
loc,
133+
"https://github.com/model-checking/kani/issues/1339",
134+
);
126135
}
127136
}
128137
_ => {}
129138
}
130139
}
131-
unimplemented!("\nv {:?}\nlit_ty {:?}\nspan {:?}", v, lit_ty, span);
140+
unimplemented!("\nv {:?}\nlit_ty {:?}\nspan {:?}", v, lit_ty.kind(), span);
132141
}
133142

134143
pub fn codegen_const_value(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<'tcx> GotocCtx<'tcx> {
446446
// https://rust-lang.github.io/rfcs/2359-subslice-pattern-syntax.html
447447
match before.mir_typ().kind() {
448448
ty::Array(ty, len) => {
449-
let len = len.val().try_to_machine_usize(self.tcx).unwrap();
449+
let len = len.kind().try_to_machine_usize(self.tcx).unwrap();
450450
let subarray_len = if from_end {
451451
// `to` counts from the end of the array
452452
len - to - from
@@ -578,7 +578,7 @@ impl<'tcx> GotocCtx<'tcx> {
578578
match before.mir_typ().kind() {
579579
//TODO, ask on zulip if we can ever have from_end here?
580580
ty::Array(elemt, length) => {
581-
let length = length.val().try_to_machine_usize(self.tcx).unwrap();
581+
let length = length.kind().try_to_machine_usize(self.tcx).unwrap();
582582
assert!(length >= min_length);
583583
let idx = if from_end { length - offset } else { offset };
584584
let idxe = Expr::int_constant(idx, Type::ssize_t());

kani-compiler/src/codegen_cprover_gotoc/utils/debug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1010
use rustc_middle::ty::Instance;
1111
use rustc_span::def_id::DefId;
1212
use std::cell::RefCell;
13-
use std::lazy::SyncLazy;
1413
use std::panic;
14+
use std::sync::LazyLock;
1515
use tracing::debug;
1616

1717
// Use a thread-local global variable to track the current codegen item for debugging.
@@ -21,12 +21,12 @@ thread_local!(static CURRENT_CODEGEN_ITEM: RefCell<(Option<String>, Option<Locat
2121

2222
pub fn init() {
2323
// Install panic hook
24-
SyncLazy::force(&DEFAULT_HOOK); // Install ice hook
24+
LazyLock::force(&DEFAULT_HOOK); // Install ice hook
2525
}
2626

2727
// Custom panic hook to add more information when panic occurs during goto-c codegen.
28-
static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
29-
SyncLazy::new(|| {
28+
static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
29+
LazyLock::new(|| {
3030
let hook = panic::take_hook();
3131
panic::set_hook(Box::new(|info| {
3232
// Invoke the default handler, which prints the actual panic message and

kani-compiler/src/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
use crate::parser;
77
use clap::ArgMatches;
8-
use std::lazy::SyncLazy;
98
use std::panic;
109
use std::str::FromStr;
10+
use std::sync::LazyLock;
1111
use tracing_subscriber::{filter::Directive, layer::SubscriberExt, EnvFilter, Registry};
1212
use tracing_tree::HierarchicalLayer;
1313

@@ -19,8 +19,8 @@ const BUG_REPORT_URL: &str =
1919
"https://github.com/model-checking/kani/issues/new?labels=bug&template=bug_report.md";
2020

2121
// Custom panic hook.
22-
static PANIC_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
23-
SyncLazy::new(|| {
22+
static PANIC_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
23+
LazyLock::new(|| {
2424
let hook = panic::take_hook();
2525
panic::set_hook(Box::new(|info| {
2626
// Print stack trace.
@@ -92,5 +92,5 @@ fn hier_logs(args: &ArgMatches, filter: EnvFilter) {
9292

9393
fn init_panic_hook() {
9494
// Install panic hook
95-
SyncLazy::force(&PANIC_HOOK); // Install ice hook
95+
LazyLock::force(&PANIC_HOOK); // Install ice hook
9696
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
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-2022-06-09"
5+
channel = "nightly-2022-07-05"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

tests/kani/Intrinsics/Atomic/Unstable/AtomicAdd/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
#![feature(core_intrinsics)]
88
use std::intrinsics::{
9-
atomic_xadd, atomic_xadd_acq, atomic_xadd_acqrel, atomic_xadd_rel, atomic_xadd_relaxed,
9+
atomic_xadd_acqrel, atomic_xadd_acquire, atomic_xadd_relaxed, atomic_xadd_release,
10+
atomic_xadd_seqcst,
1011
};
1112

1213
#[kani::proof]
@@ -27,10 +28,10 @@ fn main() {
2728
let c = 1 as u8;
2829

2930
unsafe {
30-
let x1 = atomic_xadd(ptr_a1, b);
31-
let x2 = atomic_xadd_acq(ptr_a2, b);
31+
let x1 = atomic_xadd_seqcst(ptr_a1, b);
32+
let x2 = atomic_xadd_acquire(ptr_a2, b);
3233
let x3 = atomic_xadd_acqrel(ptr_a3, b);
33-
let x4 = atomic_xadd_rel(ptr_a4, b);
34+
let x4 = atomic_xadd_release(ptr_a4, b);
3435
let x5 = atomic_xadd_relaxed(ptr_a5, b);
3536

3637
assert!(x1 == 0);

tests/kani/Intrinsics/Atomic/Unstable/AtomicAnd/main.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
// Check that `atomic_and` and other variants (unstable version) return the
4+
// Check that `atomic_and_seqcst` and other variants (unstable version) return the
55
// expected result.
66

77
#![feature(core_intrinsics)]
88
use std::intrinsics::{
9-
atomic_and, atomic_and_acq, atomic_and_acqrel, atomic_and_rel, atomic_and_relaxed,
9+
atomic_and_acqrel, atomic_and_acquire, atomic_and_relaxed, atomic_and_release,
10+
atomic_and_seqcst,
1011
};
1112

1213
#[kani::proof]
@@ -26,10 +27,10 @@ fn main() {
2627
let b = 0 as u8;
2728

2829
unsafe {
29-
let x1 = atomic_and(ptr_a1, b);
30-
let x2 = atomic_and_acq(ptr_a2, b);
30+
let x1 = atomic_and_seqcst(ptr_a1, b);
31+
let x2 = atomic_and_acquire(ptr_a2, b);
3132
let x3 = atomic_and_acqrel(ptr_a3, b);
32-
let x4 = atomic_and_rel(ptr_a4, b);
33+
let x4 = atomic_and_release(ptr_a4, b);
3334
let x5 = atomic_and_relaxed(ptr_a5, b);
3435

3536
assert!(x1 == 1);

0 commit comments

Comments
 (0)