Skip to content

Commit bd6c79e

Browse files
authored
Merge pull request diffblue#3595 from tautschnig/allocated
Make __CPROVER_allocated_memory work with non-POD type objects
2 parents e56aa4e + 8eac552 commit bd6c79e

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
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.

scripts/delete_failing_smt2_solver_tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ rm struct7/test.desc
9494
rm struct9/test.desc
9595
rm trace-values/trace-values.desc
9696
rm trace_show_function_calls/test.desc
97+
rm union12/test.desc
9798
rm union6/test.desc
9899
rm union7/test.desc
99100
rm union9/test.desc

src/analyses/goto_check.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,12 +992,16 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
992992
alloc_disjuncts.push_back(and_exprt(lb_check, ub_check));
993993
}
994994

995-
const exprt allocs = disjunction(alloc_disjuncts);
995+
const exprt in_bounds_of_some_explicit_allocation =
996+
disjunction(alloc_disjuncts);
996997

997998
if(flags.is_unknown() || flags.is_null())
998999
{
9991000
conditions.push_back(conditiont(
1000-
or_exprt(allocs, not_exprt(null_pointer(address))), "pointer NULL"));
1001+
or_exprt(
1002+
in_bounds_of_some_explicit_allocation,
1003+
not_exprt(null_pointer(address))),
1004+
"pointer NULL"));
10011005
}
10021006

10031007
if(flags.is_unknown())
@@ -1010,21 +1014,28 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10101014
if(flags.is_uninitialized())
10111015
{
10121016
conditions.push_back(conditiont(
1013-
or_exprt(allocs, not_exprt(invalid_pointer(address))),
1017+
or_exprt(
1018+
in_bounds_of_some_explicit_allocation,
1019+
not_exprt(invalid_pointer(address))),
10141020
"pointer uninitialized"));
10151021
}
10161022

10171023
if(flags.is_unknown() || flags.is_dynamic_heap())
10181024
{
10191025
conditions.push_back(conditiont(
1020-
not_exprt(deallocated(address, ns)),
1026+
or_exprt(
1027+
in_bounds_of_some_explicit_allocation,
1028+
not_exprt(deallocated(address, ns))),
10211029
"deallocated dynamic object"));
10221030
}
10231031

10241032
if(flags.is_unknown() || flags.is_dynamic_local())
10251033
{
10261034
conditions.push_back(conditiont(
1027-
not_exprt(dead_object(address, ns)), "dead object"));
1035+
or_exprt(
1036+
in_bounds_of_some_explicit_allocation,
1037+
not_exprt(dead_object(address, ns))),
1038+
"dead object"));
10281039
}
10291040

10301041
if(flags.is_unknown() || flags.is_dynamic_heap())
@@ -1034,7 +1045,10 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10341045
dynamic_object_upper_bound(address, ns, size));
10351046

10361047
conditions.push_back(conditiont(
1037-
implies_exprt(malloc_object(address, ns), not_exprt(dynamic_bounds_violation)),
1048+
or_exprt(
1049+
in_bounds_of_some_explicit_allocation,
1050+
implies_exprt(
1051+
malloc_object(address, ns), not_exprt(dynamic_bounds_violation))),
10381052
"pointer outside dynamic object bounds"));
10391053
}
10401054

@@ -1047,14 +1061,19 @@ goto_checkt::address_check(const exprt &address, const exprt &size)
10471061
object_upper_bound(address, ns, size));
10481062

10491063
conditions.push_back(conditiont(
1050-
implies_exprt(not_exprt(dynamic_object(address)), not_exprt(object_bounds_violation)),
1064+
or_exprt(
1065+
in_bounds_of_some_explicit_allocation,
1066+
implies_exprt(
1067+
not_exprt(dynamic_object(address)),
1068+
not_exprt(object_bounds_violation))),
10511069
"pointer outside object bounds"));
10521070
}
10531071

10541072
if(flags.is_unknown() || flags.is_integer_address())
10551073
{
10561074
conditions.push_back(conditiont(
1057-
implies_exprt(integer_address(address), allocs),
1075+
implies_exprt(
1076+
integer_address(address), in_bounds_of_some_explicit_allocation),
10581077
"invalid integer address"));
10591078
}
10601079

0 commit comments

Comments
 (0)