Skip to content

Commit c9d0774

Browse files
committed
Make __CPROVER_allocated_memory work with non-POD type objects
The precision of local_bitvector_analysist is not sufficient to rule out several cases introduced in 732ce2a.
1 parent a745405 commit c9d0774

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

regression/cbmc/union12/main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
typedef struct
2+
{
3+
union {
4+
int access[256];
5+
};
6+
} S1;
7+
8+
typedef struct
9+
{
10+
int c;
11+
} S2;
12+
13+
static S1(*const l[1]) = {((S1 *)((0x50000000UL) + 0x00000))};
14+
15+
void main()
16+
{
17+
__CPROVER_allocated_memory(0x50000000UL, sizeof(S1));
18+
l[0]->access[0] = 0;
19+
__CPROVER_assert(l[0]->access[0] == 0, "holds");
20+
__CPROVER_assert(l[0]->access[1] == 0, "should fail");
21+
__CPROVER_allocated_memory(0x40000000UL + 0x40000, sizeof(S2));
22+
((S2 *)((0x40000000UL) + 0x40000))->c = 0x0707;
23+
}

regression/cbmc/union12/test.desc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
main.c
3+
--pointer-check
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[main\.assertion\.2\] line 20 should fail: FAILURE$
7+
^\*\* 1 of 17 failed
8+
^VERIFICATION FAILED$
9+
--
10+
^warning: ignoring
11+
--
12+
Despite the large array inside the union, the test should complete within 10
13+
seconds. Simplify extractbits(concatenation(...)) is essential to make this
14+
possible. With 77236cc34 (Avoid nesting of ID_with/byte_update by rewriting
15+
byte_extract to use the root object) the test already is trivial, however.

src/analyses/goto_check.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,14 +1017,14 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10171017
if(flags.is_unknown() || flags.is_dynamic_heap())
10181018
{
10191019
conditions.push_back(conditiont(
1020-
not_exprt(deallocated(address, ns)),
1020+
or_exprt(allocs, not_exprt(deallocated(address, ns))),
10211021
"deallocated dynamic object"));
10221022
}
10231023

10241024
if(flags.is_unknown() || flags.is_dynamic_local())
10251025
{
10261026
conditions.push_back(conditiont(
1027-
not_exprt(dead_object(address, ns)), "dead object"));
1027+
or_exprt(allocs, not_exprt(dead_object(address, ns))), "dead object"));
10281028
}
10291029

10301030
if(flags.is_unknown() || flags.is_dynamic_heap())
@@ -1034,7 +1034,10 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10341034
dynamic_object_upper_bound(address, ns, size));
10351035

10361036
conditions.push_back(conditiont(
1037-
implies_exprt(malloc_object(address, ns), not_exprt(dynamic_bounds_violation)),
1037+
or_exprt(
1038+
allocs,
1039+
implies_exprt(
1040+
malloc_object(address, ns), not_exprt(dynamic_bounds_violation))),
10381041
"pointer outside dynamic object bounds"));
10391042
}
10401043

@@ -1047,7 +1050,11 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10471050
object_upper_bound(address, ns, size));
10481051

10491052
conditions.push_back(conditiont(
1050-
implies_exprt(not_exprt(dynamic_object(address)), not_exprt(object_bounds_violation)),
1053+
or_exprt(
1054+
allocs,
1055+
implies_exprt(
1056+
not_exprt(dynamic_object(address)),
1057+
not_exprt(object_bounds_violation))),
10511058
"pointer outside object bounds"));
10521059
}
10531060

0 commit comments

Comments
 (0)