Skip to content

Commit 8c3f5da

Browse files
committed
Expanding __CPROVER_{r,w,rw}_ok must not introduce overflow
Distributing signed-to-unsigned type casts over addition can result in an unsigned overflow where previously there was no overflow. That's ok at the logic level for any expressions yield the same models. We just need to make sure that expressions generated are not subject to goto_check_ct generating additional checks: goto_check_ct generates C language checks, not ones for internally generated expressions.
1 parent f38294f commit 8c3f5da

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int main()
2+
{
3+
char buf[10];
4+
__CPROVER_size_t max = 9;
5+
__CPROVER_size_t start = 1;
6+
7+
__CPROVER_assert(
8+
__CPROVER_r_ok(buf + start, max - start), "array is readable");
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
_ --signed-overflow-check --unsigned-overflow-check
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
This test doesn't actually use contracts, but rather demonstrates the workflow
11+
of having goto-instrument expand __CPROVER_r_ok (but really doing nothing else)
12+
before CBMC when may add (overflow) checks. Doing so must not result in failing
13+
assertions that would not have failed on the original input.

src/analyses/goto_check_c.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,10 @@ optionalt<exprt> goto_check_ct::rw_ok_check(exprt expr)
20472047
exprt c = conjunction(conjuncts);
20482048
if(enable_simplify)
20492049
simplify(c, ns);
2050+
2051+
// this is a logic expression, C language checks no longer apply
2052+
add_all_disable_named_check_pragmas(c.add_source_location());
2053+
20502054
return c;
20512055
}
20522056
else if(modified)

0 commit comments

Comments
 (0)