Skip to content

Commit d940270

Browse files
committed
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 554f796 commit d940270

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/util/simplify_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ 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) && base_type_eq(expr.type(), expr.op0().type(), ns))
265265
{
266266
exprt tmp;
267267
tmp.swap(expr.op0());

src/util/simplify_expr_class.h

+2
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)