Skip to content

Commit e7a78aa

Browse files
authored
Merge pull request #4848 from diffblue/pointer_check_beautification
Pointer check beautification
2 parents b7bad44 + ab1c30b commit e7a78aa

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/analyses/goto_check.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ class goto_checkt
170170
void undefined_shift_check(const shift_exprt &, const guardt &);
171171
void pointer_rel_check(const binary_relation_exprt &, const guardt &);
172172
void pointer_overflow_check(const exprt &, const guardt &);
173-
void pointer_validity_check(const dereference_exprt &, const guardt &);
173+
174+
/// Generates VCCs for the validity of the given dereferencing operation.
175+
/// \param expr the expression to be checked
176+
/// \param src_expr The expression as found in the program,
177+
/// prior to any rewriting
178+
/// \param guard the condition under which the operation happens
179+
void pointer_validity_check(
180+
const dereference_exprt &expr,
181+
const exprt &src_expr,
182+
const guardt &guard);
183+
174184
conditionst address_check(const exprt &address, const exprt &size);
175185
void integer_overflow_check(const exprt &, const guardt &);
176186
void conversion_check(const exprt &, const guardt &);
@@ -1094,6 +1104,7 @@ void goto_checkt::pointer_overflow_check(
10941104

10951105
void goto_checkt::pointer_validity_check(
10961106
const dereference_exprt &expr,
1107+
const exprt &src_expr,
10971108
const guardt &guard)
10981109
{
10991110
if(!enable_pointer_check)
@@ -1112,8 +1123,8 @@ void goto_checkt::pointer_validity_check(
11121123
c.assertion,
11131124
"dereference failure: " + c.description,
11141125
"pointer dereference",
1115-
expr.find_source_location(),
1116-
expr,
1126+
src_expr.find_source_location(),
1127+
src_expr,
11171128
guard);
11181129
}
11191130
}
@@ -1581,16 +1592,14 @@ bool goto_checkt::check_rec_member(const member_exprt &member, guardt &guard)
15811592
deref.pointer(), pointer_type(char_type()));
15821593

15831594
const exprt new_address_casted = typecast_exprt::conditional_cast(
1584-
typecast_exprt{
1585-
plus_exprt{char_pointer,
1586-
typecast_exprt::conditional_cast(
1587-
member_offset_opt.value(), pointer_diff_type())},
1588-
char_pointer.type()},
1595+
plus_exprt{char_pointer,
1596+
typecast_exprt::conditional_cast(
1597+
member_offset_opt.value(), pointer_diff_type())},
15891598
new_pointer_type);
15901599

15911600
dereference_exprt new_deref{new_address_casted};
15921601
new_deref.add_source_location() = deref.source_location();
1593-
pointer_validity_check(new_deref, guard);
1602+
pointer_validity_check(new_deref, member, guard);
15941603

15951604
return true;
15961605
}
@@ -1692,7 +1701,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard)
16921701
pointer_rel_check(to_binary_relation_expr(expr), guard);
16931702
else if(expr.id()==ID_dereference)
16941703
{
1695-
pointer_validity_check(to_dereference_expr(expr), guard);
1704+
pointer_validity_check(to_dereference_expr(expr), expr, guard);
16961705
}
16971706
}
16981707

0 commit comments

Comments
 (0)