Skip to content

Commit e41f3b0

Browse files
authored
Revert "Upgrade to CBMC 5.68.0 (with fixes) (#1811)"
This reverts commit 3007e84.
1 parent 3007e84 commit e41f3b0

File tree

23 files changed

+81
-87
lines changed

23 files changed

+81
-87
lines changed

cprover_bindings/src/env.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ use super::goto_program::{Expr, Location, Symbol, Type};
1212
use super::MachineModel;
1313
use num::bigint::BigInt;
1414
fn int_constant<T>(name: &str, value: T) -> Symbol
15-
where
16-
T: Into<BigInt>,
17-
{
18-
Symbol::constant(name, name, name, Expr::int_constant(value, Type::integer()), Location::none())
19-
}
20-
21-
fn int_constant_c_int<T>(name: &str, value: T) -> Symbol
2215
where
2316
T: Into<BigInt>,
2417
{
@@ -30,7 +23,7 @@ fn int_constant_from_bool(name: &str, value: bool) -> Symbol {
3023
name,
3124
name,
3225
name,
33-
Expr::int_constant(if value { 1 } else { 0 }, Type::integer()),
26+
Expr::int_constant(if value { 1 } else { 0 }, Type::c_int()),
3427
Location::none(),
3528
)
3629
}
@@ -65,9 +58,7 @@ pub fn machine_model_symbols(mm: &MachineModel) -> Vec<Symbol> {
6558
),
6659
int_constant("__CPROVER_architecture_wchar_t_width", mm.wchar_t_width),
6760
int_constant("__CPROVER_architecture_word_size", mm.word_size),
68-
// `__CPROVER_rounding_mode` doesn't use `integer` type.
69-
// More details in <https://github.com/diffblue/cbmc/issues/7282>
70-
int_constant_c_int("__CPROVER_rounding_mode", mm.rounding_mode),
61+
int_constant("__CPROVER_rounding_mode", mm.rounding_mode),
7162
]
7263
}
7364

cprover_bindings/src/goto_program/symtab_transformer/transformer.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub trait Transformer: Sized {
5555
Type::IncompleteStruct { tag } => self.transform_type_incomplete_struct(*tag),
5656
Type::IncompleteUnion { tag } => self.transform_type_incomplete_union(*tag),
5757
Type::InfiniteArray { typ } => self.transform_type_infinite_array(typ),
58-
Type::Integer => self.transform_type_integer(),
5958
Type::Pointer { typ } => self.transform_type_pointer(typ),
6059
Type::Signedbv { width } => self.transform_type_signedbv(width),
6160
Type::Struct { tag, components } => self.transform_type_struct(*tag, components),
@@ -155,11 +154,6 @@ pub trait Transformer: Sized {
155154
transformed_typ.infinite_array_of()
156155
}
157156

158-
/// Transforms a CPROVER integer type
159-
fn transform_type_integer(&mut self) -> Type {
160-
Type::integer()
161-
}
162-
163157
/// Transforms a pointer type (`typ*`)
164158
fn transform_type_pointer(&mut self, typ: &Type) -> Type {
165159
let transformed_typ = self.transform_type(typ);

cprover_bindings/src/goto_program/typ.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ pub enum Type {
4646
IncompleteStruct { tag: InternedString },
4747
/// `union x {}`
4848
IncompleteUnion { tag: InternedString },
49-
/// `integer`: A machine independent integer
50-
Integer,
5149
/// CBMC specific. `typ x[__CPROVER_infinity()]`
5250
InfiniteArray { typ: Box<Type> },
5351
/// `typ*`
@@ -165,7 +163,6 @@ impl DatatypeComponent {
165163
| Double
166164
| FlexibleArray { .. }
167165
| Float
168-
| Integer
169166
| Pointer { .. }
170167
| Signedbv { .. }
171168
| Struct { .. }
@@ -346,7 +343,6 @@ impl Type {
346343
IncompleteStruct { .. } => unreachable!("IncompleteStruct doesn't have a sizeof"),
347344
IncompleteUnion { .. } => unreachable!("IncompleteUnion doesn't have a sizeof"),
348345
InfiniteArray { .. } => unreachable!("InfiniteArray doesn't have a sizeof"),
349-
Integer => unreachable!("Integer doesn't have a sizeof"),
350346
Pointer { .. } => st.machine_model().pointer_width,
351347
Signedbv { width } => *width,
352348
Struct { components, .. } => {
@@ -531,7 +527,7 @@ impl Type {
531527
pub fn is_integer(&self) -> bool {
532528
let concrete = self.unwrap_typedef();
533529
match concrete {
534-
CInteger(_) | Integer | Signedbv { .. } | Unsignedbv { .. } => true,
530+
CInteger(_) | Signedbv { .. } | Unsignedbv { .. } => true,
535531
_ => false,
536532
}
537533
}
@@ -544,7 +540,6 @@ impl Type {
544540
| CInteger(_)
545541
| Double
546542
| Float
547-
| Integer
548543
| Pointer { .. }
549544
| Signedbv { .. }
550545
| Struct { .. }
@@ -600,7 +595,6 @@ impl Type {
600595
| Double
601596
| Empty
602597
| Float
603-
| Integer
604598
| Pointer { .. }
605599
| Signedbv { .. }
606600
| Unsignedbv { .. } => true,
@@ -883,7 +877,6 @@ impl Type {
883877
| CInteger(_)
884878
| Double
885879
| Float
886-
| Integer
887880
| Pointer { .. }
888881
| Signedbv { .. }
889882
| Struct { .. }
@@ -1032,10 +1025,6 @@ impl Type {
10321025
InfiniteArray { typ: Box::new(self) }
10331026
}
10341027

1035-
pub fn integer() -> Self {
1036-
Integer
1037-
}
1038-
10391028
/// self *
10401029
pub fn to_pointer(self) -> Self {
10411030
Pointer { typ: Box::new(self) }
@@ -1267,7 +1256,6 @@ impl Type {
12671256
| CInteger(_)
12681257
| Double
12691258
| Float
1270-
| Integer
12711259
| Pointer { .. }
12721260
| Signedbv { .. }
12731261
| Unsignedbv { .. } => self.zero(),
@@ -1376,7 +1364,6 @@ impl Type {
13761364
Type::InfiniteArray { typ } => {
13771365
format!("infinite_array_of_{}", typ.to_identifier())
13781366
}
1379-
Type::Integer => "integer".to_string(),
13801367
Type::Pointer { typ } => format!("pointer_to_{}", typ.to_identifier()),
13811368
Type::Signedbv { width } => format!("signed_bv_{width}"),
13821369
Type::Struct { tag, .. } => format!("struct_{tag}"),

cprover_bindings/src/irep/to_irep.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,14 @@ impl ToIrep for DatatypeComponent {
140140
impl ToIrep for Expr {
141141
fn to_irep(&self, mm: &MachineModel) -> Irep {
142142
if let ExprValue::IntConstant(i) = self.value() {
143-
let typ_width = self.typ().native_width(mm);
144-
let irep_value = if let Some(width) = typ_width {
145-
Irep::just_bitpattern_id(i.clone(), width, self.typ().is_signed(mm))
146-
} else {
147-
Irep::just_int_id(i.clone())
148-
};
143+
let width = self.typ().native_width(mm).unwrap();
149144
Irep {
150145
id: IrepId::Constant,
151146
sub: vec![],
152-
named_sub: linear_map![(IrepId::Value, irep_value,)],
147+
named_sub: linear_map![(
148+
IrepId::Value,
149+
Irep::just_bitpattern_id(i.clone(), width, self.typ().is_signed(mm))
150+
)],
153151
}
154152
.with_location(self.location(), mm)
155153
.with_type(self.typ(), mm)
@@ -654,7 +652,6 @@ impl ToIrep for Type {
654652
named_sub: linear_map![(IrepId::Size, infinity)],
655653
}
656654
}
657-
Type::Integer => Irep::just_id(IrepId::Integer),
658655
Type::Pointer { typ } => Irep {
659656
id: IrepId::Pointer,
660657
sub: vec![typ.to_irep(mm)],

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ impl<'tcx> GotocCtx<'tcx> {
174174
Type::IncompleteStruct { .. } => todo!(),
175175
Type::IncompleteUnion { .. } => todo!(),
176176
Type::InfiniteArray { .. } => todo!(),
177-
Type::Integer => write!(out, "integer")?,
178177
Type::Pointer { typ } => {
179178
write!(out, "*")?;
180179
debug_write_type(ctx, typ, out, indent)?;

kani-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
CBMC_VERSION="5.69.1"
1+
CBMC_VERSION="5.67.0"
22
# If you update this version number, remember to bump it in `src/setup.rs` too
33
CBMC_VIEWER_VERSION="3.6"

kani-driver/src/call_cbmc.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,12 @@ impl KaniSession {
124124
args.push("--validate-ssa-equation".into());
125125
}
126126

127-
// Push `--slice-formula` argument.
128-
// Previously, this would happen if the condition below was satisfied:
129-
// ```rust
130-
// if !self.args.visualize
131-
// && self.args.concrete_playback.is_none()
132-
// && !self.args.no_slice_formula
133-
// ```
134-
// But for some reason, not pushing it causes a CBMC invariant violation
135-
// since version 5.68.0.
136-
// <https://github.com/model-checking/kani/issues/1810>
137-
args.push("--slice-formula".into());
127+
if !self.args.visualize
128+
&& self.args.concrete_playback.is_none()
129+
&& !self.args.no_slice_formula
130+
{
131+
args.push("--slice-formula".into());
132+
}
138133

139134
if self.args.concrete_playback.is_some() {
140135
args.push("--trace".into());

library/kani/kani_lib.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ void *calloc(size_t nmemb, size_t size);
1111

1212
typedef __CPROVER_bool bool;
1313

14-
/// Mapping unit to `void` works for functions with no return type but not for
15-
/// variables with type unit. We treat both uniformly by declaring an empty
16-
/// struct type: `struct Unit {}` and a global variable `struct Unit VoidUnit`
17-
/// returned by all void functions (both declared by the Kani compiler).
18-
struct Unit;
19-
extern struct Unit VoidUnit;
20-
2114
// `assert` then `assume`
2215
#define __KANI_assert(cond, msg) \
2316
do { \
@@ -77,7 +70,7 @@ uint8_t *__rust_alloc_zeroed(size_t size, size_t align)
7770
// definition.
7871
// For safety, refer to the documentation of GlobalAlloc::dealloc:
7972
// https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html#tymethod.dealloc
80-
struct Unit __rust_dealloc(uint8_t *ptr, size_t size, size_t align)
73+
void __rust_dealloc(uint8_t *ptr, size_t size, size_t align)
8174
{
8275
// TODO: Ensure we are doing the right thing with align
8376
// https://github.com/model-checking/kani/issues/1168
@@ -86,7 +79,6 @@ struct Unit __rust_dealloc(uint8_t *ptr, size_t size, size_t align)
8679
__KANI_assert(__CPROVER_OBJECT_SIZE(ptr) == size,
8780
"rust_dealloc must be called on an object whose allocated size matches its layout");
8881
free(ptr);
89-
return VoidUnit;
9082
}
9183

9284
// This is a C implementation of the __rust_realloc function that has the following signature:

scripts/kani-regression.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ fi
8787
# Check codegen of firecracker
8888
time "$SCRIPT_DIR"/codegen-firecracker.sh
8989

90+
# Check that we can use Kani on crates with a diamond dependency graph,
91+
# with two different versions of the same crate.
92+
#
93+
# dependency1
94+
# / \ v0.1.0
95+
# main dependency3
96+
# \ / v0.1.1
97+
# dependency2
98+
time "$KANI_DIR"/tests/kani-dependency-test/diamond-dependency/run-dependency-test.sh
99+
90100
# Check that documentation compiles.
91101
cargo doc --workspace --no-deps --exclude std
92102

tests/cargo-kani/dependency-test/diamond-dependency/harness.expected

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Copyright Kani Contributors
3+
# SPDX-License-Identifier: Apache-2.0 OR MIT
4+
5+
# We're explicitly checking output rather than failing if the test fails
6+
#set -eu
7+
8+
echo
9+
echo "Starting Diamond Dependency Test..."
10+
echo
11+
12+
# Test for platform
13+
PLATFORM=$(uname -sp)
14+
if [[ $PLATFORM == "Linux x86_64" ]]
15+
then
16+
TARGET="x86_64-unknown-linux-gnu"
17+
elif [[ $PLATFORM == "Darwin i386" ]]
18+
then
19+
TARGET="x86_64-apple-darwin"
20+
else
21+
echo
22+
echo "Test only works on Linux or OSX x86 platforms, skipping..."
23+
echo
24+
exit 0
25+
fi
26+
27+
# Compile crates with Kani backend
28+
cd $(dirname $0)
29+
rm -rf build
30+
RUST_BACKTRACE=1 cargo kani --target-dir build --only-codegen --keep-temps --verbose --no-assertion-reach-checks
31+
32+
# Convert from JSON to Gotoc
33+
cd build/${TARGET}/debug/deps/
34+
ls *.symtab.json | xargs symtab2gb
35+
36+
# Add the entry point and remove unused functions
37+
goto-cc --function harness *.out -o a.out
38+
goto-instrument --drop-unused-functions a.out b.out
39+
40+
# Run the solver
41+
RESULT="/tmp/dependency_test_result.txt"
42+
cbmc b.out &> $RESULT
43+
if ! grep -q "VERIFICATION SUCCESSFUL" $RESULT; then
44+
cat $RESULT
45+
echo
46+
echo "Failed dependency test"
47+
echo
48+
exit 1
49+
fi
50+
51+
echo
52+
echo "Finished Diamond Dependency Test successfully..."
53+
echo

tests/kani/ForeignItems/lib.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
#include <stdio.h>
88
#include <string.h>
99

10-
/// Mapping unit to `void` works for functions with no return type but not for
11-
/// variables with type unit. We treat both uniformly by declaring an empty
12-
/// struct type: `struct Unit {}` and a global variable `struct Unit VoidUnit`
13-
/// returned by all void functions (both declared by the Kani compiler).
14-
struct Unit;
15-
extern struct Unit VoidUnit;
16-
1710
size_t my_add(size_t num, ...)
1811
{
1912
va_list argp;
@@ -55,15 +48,7 @@ struct Foo2 {
5548

5649
uint32_t S = 12;
5750

58-
// Note: We changed the return type from `void` to `struct Unit` when upgrading
59-
// to a newer CBMC version with stricter type-checking. This is a temporary
60-
// change until C-FFI support is added.
61-
// <https://github.com/model-checking/kani/issues/1817>
62-
struct Unit update_static()
63-
{
64-
S++;
65-
return VoidUnit;
66-
}
51+
void update_static() { S++; }
6752

6853
uint32_t takes_int(uint32_t i) { return i + 2; }
6954

@@ -78,15 +63,7 @@ uint32_t takes_ptr_option(uint32_t *p)
7863
}
7964
}
8065

81-
// Note: We changed the return type from `void` to `struct Unit` when upgrading
82-
// to a newer CBMC version with stricter type-checking. This is a temporary
83-
// change until C-FFI support is added.
84-
// <https://github.com/model-checking/kani/issues/1817>
85-
struct Unit mutates_ptr(uint32_t *p)
86-
{
87-
*p -= 1;
88-
return VoidUnit;
89-
}
66+
void mutates_ptr(uint32_t *p) { *p -= 1; }
9067

9168
uint32_t name_in_c(uint32_t i) { return i + 2; }
9269

0 commit comments

Comments
 (0)