Skip to content

Commit 814426b

Browse files
committed
Object factory: assert exact type consistency
At the moment --validate-goto-model doesn't give this strong a guarantee, but at least within the object factory we should only be producing exactly type-consistent statements.
1 parent cf85073 commit 814426b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,22 @@ void java_object_factoryt::gen_nondet_enum_init(
14981498
assignments.add(enum_assign);
14991499
}
15001500

1501+
static void assert_type_consistency(const code_blockt &assignments)
1502+
{
1503+
// In future we'll be able to use codet::validate for this;
1504+
// at present that only verifies `lhs.type base_type_eq right.type`,
1505+
// whereas we want to check exact equality.
1506+
for(const auto &code : assignments.statements())
1507+
{
1508+
if(code.get_statement() != ID_assign)
1509+
continue;
1510+
const auto &assignment = to_code_assign(code);
1511+
INVARIANT(
1512+
assignment.lhs().type() == assignment.rhs().type(),
1513+
"object factory should produce type-consistent assignments");
1514+
}
1515+
}
1516+
15011517
/// Similar to `gen_nondet_init` below, but instead of allocating and
15021518
/// non-deterministically initializing the the argument `expr` passed to that
15031519
/// function, we create a static global object of type \p type and
@@ -1558,6 +1574,7 @@ exprt object_factory(
15581574
state.add_created_symbol(main_symbol_ptr);
15591575
state.declare_created_symbols(init_code);
15601576

1577+
assert_type_consistency(assignments);
15611578
init_code.append(assignments);
15621579
return object;
15631580
}
@@ -1628,6 +1645,7 @@ void gen_nondet_init(
16281645

16291646
state.declare_created_symbols(init_code);
16301647

1648+
assert_type_consistency(assignments);
16311649
init_code.append(assignments);
16321650
}
16331651

0 commit comments

Comments
 (0)