Skip to content

Commit 2a32be7

Browse files
committed
Require explicit contract for --replace-call-with-contract
Change --replace-call-with-contract to produce a hard error instead of a warning when used with functions lacking explicit contracts. This change addresses a soundness issue where CBMC would previously assume a trivial contract automatically. Users that really need a trivial contract with no constraints should use ````c int my_function(int x) __CPROVER_requires(1) __CPROVER_ensures(1) { return x + 1; } ```` Fixes: #8728
1 parent 0985044 commit 2a32be7

File tree

29 files changed

+85
-66
lines changed

29 files changed

+85
-66
lines changed

regression/contracts-dfcc/assigns-local-composite/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct taggedt {
4040
};
4141
// clang-format on
4242

43-
int foo(int i) __CPROVER_assigns()
43+
int foo(int i) __CPROVER_ensures(1) __CPROVER_assigns()
4444
{
4545
// all accesses to locals should pass
4646
int arr[10];

regression/contracts-dfcc/assigns_enforce_15/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int baz() __CPROVER_ensures(__CPROVER_return_value == global)
2020
return global;
2121
}
2222

23-
void qux(void) __CPROVER_assigns()
23+
void qux(void) __CPROVER_ensures(1) __CPROVER_assigns()
2424
{
2525
global = global + 1;
2626
}

regression/contracts-dfcc/assigns_enforce_17/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int x;
44

5-
void pure() __CPROVER_assigns()
5+
void pure() __CPROVER_ensures(1) __CPROVER_assigns()
66
{
77
int x;
88
x++;

regression/contracts-dfcc/assigns_enforce_20/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
int x = 0;
55

6-
void foo(int *y) __CPROVER_assigns()
6+
void foo(int *y) __CPROVER_ensures(1) __CPROVER_assigns()
77
{
88
__CPROVER_havoc_object(y);
99
x = 2;

regression/contracts-dfcc/assigns_enforce_arrays_01/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void f1(int a[], int len) __CPROVER_assigns()
1+
void f1(int a[], int len) __CPROVER_ensures(1) __CPROVER_assigns()
22
{
33
int b[10];
44
a = b;

regression/contracts-dfcc/assigns_enforce_arrays_03/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void assign_out_under(int a[], int len) __CPROVER_assigns()
1+
void assign_out_under(int a[], int len) __CPROVER_ensures(1) __CPROVER_assigns()
22
{
33
a[1] = 5;
44
}

regression/contracts-dfcc/assigns_enforce_malloc_01/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
22

3-
int f(int *a) __CPROVER_assigns()
3+
int f(int *a) __CPROVER_ensures(1) __CPROVER_assigns()
44
{
55
a = (int *)malloc(sizeof(int));
66
*a = 5;

regression/contracts-dfcc/assigns_enforce_malloc_02/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
22

3-
int f(int n, int *ptr) __CPROVER_assigns()
3+
int f(int n, int *ptr) __CPROVER_ensures(1) __CPROVER_assigns()
44
{
55
while(n > 0)
66
{

regression/contracts-dfcc/assigns_enforce_malloc_03/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdlib.h>
22

3-
void foo() __CPROVER_assigns()
3+
void foo() __CPROVER_ensures(1) __CPROVER_assigns()
44
{
55
char *loc1 = malloc(1);
66
char *loc2 = malloc(1);

regression/contracts-dfcc/assigns_enforce_statics/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
static int x = 0;
22

3-
void foo() __CPROVER_assigns()
3+
void foo() __CPROVER_ensures(1) __CPROVER_assigns()
44
{
55
int *y = &x;
66

0 commit comments

Comments
 (0)