Skip to content

Commit 932b7f5

Browse files
committed
Expression simplification must not alter the type
Expression simplification should return an expression that is semantically equivalent. The type may only differ in moving from a tag to an expanded type or vice-versa, but the underlying types must always remain consistent.
1 parent 8ca0aca commit 932b7f5

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/util/simplify_expr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,7 @@ bool simplify_exprt::simplify_rec(exprt &expr)
22932293

22942294
if(!result)
22952295
{
2296+
POSTCONDITION(type_eq(tmp.type(), expr.type(), ns));
22962297
expr.swap(tmp);
22972298

22982299
#ifdef USE_CACHE

src/util/simplify_expr_struct.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include "arith_tools.h"
1212
#include "base_type.h"
1313
#include "byte_operators.h"
14+
#include "invariant.h"
1415
#include "namespace.h"
1516
#include "pointer_offset_size.h"
1617
#include "std_expr.h"
@@ -45,6 +46,9 @@ bool simplify_exprt::simplify_member(exprt &expr)
4546
if(op1.get(ID_component_name)==component_name)
4647
{
4748
// found it!
49+
DATA_INVARIANT(
50+
base_type_eq(op2.type(), expr.type(), ns),
51+
"member expression type must match component type");
4852
exprt tmp;
4953
tmp.swap(op2);
5054
expr.swap(tmp);
@@ -134,6 +138,9 @@ bool simplify_exprt::simplify_member(exprt &expr)
134138
if(struct_type.has_component(component_name))
135139
{
136140
std::size_t number=struct_type.component_number(component_name);
141+
DATA_INVARIANT(
142+
base_type_eq(op.operands()[number].type(), expr.type(), ns),
143+
"member expression type must match component type");
137144
exprt tmp;
138145
tmp.swap(op.operands()[number]);
139146
expr.swap(tmp);

0 commit comments

Comments
 (0)