Skip to content

Commit 159af34

Browse files
authored
Merge pull request #8578 from tautschnig/bugfixes/8570-pointer-and-array
Value-set based dereferencing: fix simplified handling of *(p + i)
2 parents be99f47 + 164407f commit 159af34

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
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
{

src/util/pointer_offset_size.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,7 @@ std::optional<exprt> get_subexpression_at_offset(
564564
const namespacet &ns)
565565
{
566566
if(offset_bytes == 0 && expr.type() == target_type_raw)
567-
{
568-
exprt result = expr;
569-
570-
if(expr.type() != target_type_raw)
571-
result.type() = target_type_raw;
572-
573-
return result;
574-
}
567+
return expr;
575568

576569
if(
577570
offset_bytes == 0 && expr.type().id() == ID_pointer &&

0 commit comments

Comments
 (0)