Skip to content

Commit b8c6b40

Browse files
committed
Value-set based dereferencing: fix simplified handling of *(p + i)
Value-set based dereferencing must not take an access path through an object that precludes a subsequent index expression from accessing a different part of the object. Such a situation can arise when the value set has a known (constant) offset for the pointer that would identify one particular element in an array (within that object). The code using value-set based dereferencing, however, may be trying to resolve a subexpression of an index expression, where said index expression would lead to a different element that may itself be part of a different array within the same overall object. Fixes: #8570
1 parent 66004dc commit b8c6b40

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

regression/cbmc/Pointer_array8/main.c

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma pack(push)
2+
#pragma pack(1)
3+
typedef struct
4+
{
5+
int data[2];
6+
} arr;
7+
8+
typedef struct
9+
{
10+
arr vec[2];
11+
} arrvec;
12+
#pragma pack(pop)
13+
14+
int main()
15+
{
16+
arrvec A;
17+
arrvec *x = &A;
18+
__CPROVER_assume(x->vec[1].data[0] < 42);
19+
unsigned k;
20+
__CPROVER_assert(k != 2 || ((int *)x)[k] < 42, "");
21+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE no-new-smt
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

regression/cbmc/array-cell-sensitivity15/test.desc

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ access.c
33
--program-only
44
^EXIT=0$
55
^SIGNAL=0$
6-
s!0@1#2\.\.n == \{ s!0@1#1\.\.n\[\[0\]\], s!0@1#1\.\.n\[\[1\]\], s!0@1#1\.\.n\[\[2\]\], s!0@1#1\.\.n\[\[3\]\] } WITH \[\(.*\)i!0@1#2:=k!0@1#1\]
6+
s!0@1#2\.\.n ==.*\{ s!0@1#1\.\.n\[\[0\]\], s!0@1#1\.\.n\[\[1\]\], s!0@1#1\.\.n\[\[2\]\], s!0@1#1\.\.n\[\[3\]\] \}
77
--
8-
byte_update
98
--
109
This tests applying field-sensitivity to a pointer to an array that is part of a struct. See cbmc issue #5397 and PR #5418 for more detail.
1110
Disabled for paths-lifo mode, which does not support --program-only.

src/pointer-analysis/value_set_dereference.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ exprt value_set_dereferencet::dereference(
196196

197197
if(
198198
can_cast_type<pointer_typet>(pointer_expr.type()) &&
199+
pointer_expr.id() != ID_typecast &&
199200
!can_cast_type<pointer_typet>(offset_expr.type()) &&
200201
!can_cast_expr<constant_exprt>(offset_expr))
201202
{

0 commit comments

Comments
 (0)