Skip to content

Commit cec8743

Browse files
committed
replace_expr: check type consistency
Make sure that replace_expr cannot introduce type-inconsistent expressions. This wouldn't be a fault of replace_expr, but rather requires fixing the caller. Add preconditions to check this.
1 parent f335668 commit cec8743

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/util/replace_expr.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Author: Daniel Kroening, [email protected]
1111

1212
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
1313
{
14+
PRECONDITION_WITH_DIAGNOSTICS(
15+
what.type() == by.type(),
16+
"types to be replaced should match. old type:\n" + what.type().pretty() +
17+
"\nnew type:\n" + by.type().pretty());
18+
1419
bool no_change = true;
1520

1621
for(auto it = dest.depth_begin(), itend = dest.depth_end();
@@ -39,6 +44,11 @@ bool replace_expr(const replace_mapt &what, exprt &dest)
3944
replace_mapt::const_iterator findit = what.find(*it);
4045
if(findit != what.end())
4146
{
47+
PRECONDITION_WITH_DIAGNOSTICS(
48+
it->type() == findit->second.type(),
49+
"types to be replaced should match. old type:\n" + it->type().pretty() +
50+
"\nnew type:\n" + findit->second.type().pretty());
51+
4252
it.mutate() = findit->second;
4353
no_change = false;
4454
it.next_sibling_or_parent();

0 commit comments

Comments
 (0)