Skip to content

Commit 9255f33

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 4bf6ad8 commit 9255f33

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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)