Skip to content

Commit 9f92553

Browse files
author
Nathan Wetzler
committed
Populate function name in source locations for function contracts
During parsing of function parameters, the function name should be set in the source location, but only for top-level function declarations and definitions. In addition, function contracts should be only allowed for top-level function declarations and definitions. CBMC Viewer reports a failure when analyzing the incomplete coverage report, causing the CMBC Starter Kit to fail during a standard build. Also removed source location from "end function" command during contract checking and added proper source location to function contract instrumentation. Resolves issues #7032, #7070
1 parent aaa4774 commit 9f92553

File tree

39 files changed

+136
-44
lines changed

39 files changed

+136
-44
lines changed

regression/contracts/assigns_repeated_ignored/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--enforce-contract foo
4-
^Ignored duplicate expression '\*x' in assigns clause spec at file main.c line \d+$
4+
^Ignored duplicate expression '\*x' in assigns clause spec at file main.c line \d+ function .*$
55
^EXIT=0$
66
^SIGNAL=0$
77
^VERIFICATION SUCCESSFUL$

regression/contracts/assigns_validity_pointer_02/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--enforce-contract foo
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS$
6+
^\[foo.postcondition.\d+\] line \d+ Check ensures clause: SUCCESS$
77
^\[bar.assigns.\d+\] line \d+ Check that \*x is assignable: SUCCESS$
88
^\[bar.assigns.\d+\] line \d+ Check that \*y is assignable: SUCCESS$
99
^\[baz.assigns.\d+\] line \d+ Check that \*z is assignable: SUCCESS$

regression/contracts/contracts_with_function_pointers/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--enforce-contract bar
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS$
6+
^\[bar.postcondition.\d+\] line \d+ Check ensures clause: SUCCESS$
77
^\[bar.assigns.\d+\] line \d+ Check that \*return\_value\_baz is assignable: SUCCESS$
88
^\[foo.assigns.\d+\] line \d+ Check that \*y is assignable: SUCCESS$
99
^VERIFICATION SUCCESSFUL$
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
typedef void (*fun_ptr_t)(int x);
2+
3+
void bar(int x) {
4+
return;
5+
}
6+
7+
void foo(void (*fun_ptr)(int x) __CPROVER_requires(x != 0)) {
8+
return;
9+
}
10+
11+
void main() {
12+
fun_ptr_t fun_ptr = bar;
13+
foo(fun_ptr);
14+
return;
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^Assertion failed: \(contract_in_global_scope || contract_in_top_level_function_scope\), function yyansi_cparse, file parser.y, line \d+.$
5+
^EXIT=134$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Checks if function contracts can be attached to function pointers
10+
(with non-empty parameter lists) in function parameters. This should
11+
fail.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
typedef int (*fun_ptr_t)();
2+
3+
int bar() {
4+
return 1 ;
5+
}
6+
7+
void foo(int (*fun_ptr)() __CPROVER_ensures(__CPROVER_return_value == 1)) {
8+
return;
9+
}
10+
11+
void main() {
12+
fun_ptr_t fun_ptr = bar;
13+
foo(fun_ptr);
14+
return;
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^Assertion failed: \(contract_in_global_scope || contract_in_top_level_function_scope\), function yyansi_cparse, file parser.y, line \d+.$
5+
^EXIT=134$
6+
^SIGNAL=0$
7+
--
8+
--
9+
Checks if function contracts can be attached to function pointers
10+
(with empty parameter lists) in function parameters. This should
11+
fail.

regression/contracts/function-calls-05/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--enforce-contract foo
44
^EXIT=0$
55
^SIGNAL=0$
6-
\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS
6+
\[foo.postcondition.\d+\] line \d+ Check ensures clause: SUCCESS
77
\[main.assertion.\d+\] line \d+ assertion foo\(\&x, \&y\) \=\= 10: SUCCESS
88
^VERIFICATION SUCCESSFUL$
99
--

regression/contracts/function-pointer-contracts-replace/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
main.c
33
--replace-call-with-contract foo
4-
^\[precondition.\d+] file main.c line 19 Assert function pointer 'infun' obeys contract 'contract': SUCCESS$
4+
^\[foo.precondition.\d+] line 19 Assert function pointer 'infun' obeys contract 'contract': SUCCESS$
55
^\[main.assertion.\d+].* assertion outfun1 == contract: SUCCESS$
66
^\[main.assertion.\d+].* assertion outfun2 == contract: SUCCESS$
77
^EXIT=0$

regression/contracts/history-pointer-enforce-09/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--enforce-contract foo
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[postcondition.\d+\] file main.c line \d+ Check ensures clause: SUCCESS$
6+
^\[foo.postcondition.\d+\] line \d+ Check ensures clause: SUCCESS$
77
^\[foo.assigns.\d+\] line \d+ Check that p->y is assignable: SUCCESS$
88
^VERIFICATION SUCCESSFUL$
99
--

0 commit comments

Comments
 (0)