Skip to content

Commit a2fe314

Browse files
authored
Merge pull request #7024 from tautschnig/bugfixes/value_set-shift
Value sets: track pointers through shifts
2 parents aaa4774 + fef6c60 commit a2fe314

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

regression/cbmc/Pointer2/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int main()
2+
{
3+
int x;
4+
unsigned long long x_i;
5+
_Static_assert(sizeof(&x) == sizeof(x_i), "pointer width");
6+
__CPROVER_assert(((unsigned long long)&x & 0x1ULL) == 0, "LSB is zero");
7+
x_i = (unsigned long long)&x >> 1;
8+
x_i <<= 1;
9+
__CPROVER_assert(*(int *)x_i == x, "pointer to x is tracked through shifts");
10+
}

regression/cbmc/Pointer2/test.desc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
9+
--
10+
Value sets must also track pointers the integer conversion of which is subject
11+
to shifts (just like we already tracked them through other bit operations).

src/pointer-analysis/value_set.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,24 @@ void value_sett::get_value_set_rec(
760760
insert(dest, it->first, offset);
761761
}
762762
}
763+
else if(expr.id() == ID_lshr || expr.id() == ID_ashr || expr.id() == ID_shl)
764+
{
765+
const binary_exprt &binary_expr = to_binary_expr(expr);
766+
767+
object_mapt pointer_expr_set;
768+
get_value_set_rec(
769+
binary_expr.op0(), pointer_expr_set, "", binary_expr.op0().type(), ns);
770+
771+
for(const auto &object_map_entry : pointer_expr_set.read())
772+
{
773+
offsett offset = object_map_entry.second;
774+
775+
// kill any offset
776+
offset.reset();
777+
778+
insert(dest, object_map_entry.first, offset);
779+
}
780+
}
763781
else if(expr.id()==ID_side_effect)
764782
{
765783
const irep_idt &statement = to_side_effect_expr(expr).get_statement();

0 commit comments

Comments
 (0)