Skip to content

Commit b40dc2b

Browse files
smowtonpeterschrammel
authored andcommitted
Add option for simplify-expr to keep identical structs
Normally it will eliminate casts from one struct type to another if they have like members, but this leads to type errors in languages like Java where they cannot be used interchangeably unless they also have a subtype relationship.
1 parent 885bedf commit b40dc2b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/util/simplify_expr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
261261
}
262262

263263
// eliminate redundant typecasts
264-
if(base_type_eq(expr.type(), expr.op0().type(), ns))
264+
if((!keep_identical_structs) &&
265+
base_type_eq(expr.type(), expr.op0().type(), ns))
265266
{
266267
exprt tmp;
267268
tmp.swap(expr.op0());

src/util/simplify_expr_class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class simplify_exprt
3838
public:
3939
explicit simplify_exprt(const namespacet &_ns):
4040
do_simplify_if(true),
41+
keep_identical_structs(false),
4142
ns(_ns)
4243
#ifdef DEBUG_ON_DEMAND
4344
, debug_on(false)
@@ -54,6 +55,7 @@ class simplify_exprt
5455
}
5556

5657
bool do_simplify_if;
58+
bool keep_identical_structs;
5759

5860
// These below all return 'true' if the simplification wasn't applicable.
5961
// If false is returned, the expression has changed.

0 commit comments

Comments
 (0)