Skip to content

Commit 2c1fc06

Browse files
authored
Merge pull request #2721 from tautschnig/replace_symbol-cleanup2
Constant propagation: Check type consistency before adding to replacement map
2 parents 8211a78 + 30d557a commit 2c1fc06

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/analyses/constant_propagator.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ Author: Peter Schrammel
1616
#include <util/format_expr.h>
1717
#endif
1818

19-
#include <util/ieee_float.h>
20-
#include <util/find_symbols.h>
2119
#include <util/arith_tools.h>
22-
#include <util/simplify_expr.h>
20+
#include <util/base_type.h>
2321
#include <util/cprover_prefix.h>
22+
#include <util/find_symbols.h>
23+
#include <util/ieee_float.h>
24+
#include <util/simplify_expr.h>
2425

2526
#include <langapi/language_util.h>
2627

@@ -46,7 +47,12 @@ void constant_propagator_domaint::assign_rec(
4647
partial_evaluate(tmp, ns);
4748

4849
if(tmp.is_constant())
50+
{
51+
DATA_INVARIANT(
52+
base_type_eq(ns.lookup(s).type, tmp.type(), ns),
53+
"type of constant to be replaced should match");
4954
values.set_to(s, tmp);
55+
}
5056
else
5157
values.set_to_top(s);
5258
}
@@ -258,7 +264,7 @@ bool constant_propagator_domaint::two_way_propagate_rec(
258264
assign_rec(copy_values, lhs, rhs, ns);
259265
if(!values.is_constant(rhs) || values.is_constant(lhs))
260266
assign_rec(values, rhs, lhs, ns);
261-
change=values.meet(copy_values);
267+
change = values.meet(copy_values, ns);
262268
}
263269
#endif
264270

@@ -469,7 +475,9 @@ bool constant_propagator_domaint::valuest::merge(const valuest &src)
469475

470476
/// meet
471477
/// \return Return true if "this" has changed.
472-
bool constant_propagator_domaint::valuest::meet(const valuest &src)
478+
bool constant_propagator_domaint::valuest::meet(
479+
const valuest &src,
480+
const namespacet &ns)
473481
{
474482
if(src.is_bottom || is_bottom)
475483
return false;
@@ -492,6 +500,9 @@ bool constant_propagator_domaint::valuest::meet(const valuest &src)
492500
}
493501
else
494502
{
503+
DATA_INVARIANT(
504+
base_type_eq(ns.lookup(m.first).type, m.second.type(), ns),
505+
"type of constant to be stored should match");
495506
set_to(m.first, m.second);
496507
changed=true;
497508
}

src/analyses/constant_propagator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class constant_propagator_domaint:public ai_domain_baset
7575
bool is_bottom = true;
7676

7777
bool merge(const valuest &src);
78-
bool meet(const valuest &src);
78+
bool meet(const valuest &src, const namespacet &ns);
7979

8080
// set whole state
8181

0 commit comments

Comments
 (0)