Skip to content

Commit f121748

Browse files
author
Remi Delmas
committed
CONTRACTS: use INVARIANT instead of exit(0)
1 parent 9ed7fde commit f121748

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/goto-instrument/contracts/dynamic-frames/dfcc_spec_functions.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,10 @@ void dfcc_spec_functionst::generate_havoc_function(
118118
const irep_idt &havoc_function_id,
119119
int &nof_targets)
120120
{
121-
if(goto_model.symbol_table.has_symbol(havoc_function_id))
122-
{
123-
log.error() << "dfcc_spec_functionst::generate_havoc_function: '"
124-
<< havoc_function_id << "' already exists" << messaget::eom;
125-
exit(0);
126-
}
121+
INVARIANT(
122+
!goto_model.symbol_table.has_symbol(havoc_function_id),
123+
"DFCC: havoc function id '" + id2string(havoc_function_id) +
124+
"' already exists");
127125

128126
const auto &function_symbol = utils.get_function_symbol(function_id);
129127

@@ -153,14 +151,11 @@ void dfcc_spec_functionst::generate_havoc_function(
153151
havoc_function_symbol.module = function_symbol.module;
154152
havoc_function_symbol.location = function_symbol.location;
155153
havoc_function_symbol.set_compiled();
156-
157-
if(goto_model.symbol_table.add(havoc_function_symbol))
158-
{
159-
log.error() << "dfcc_spec_functionst::generate_havoc_function: could not "
160-
"insert symbol '"
161-
<< havoc_function_id << "' in symbol table" << messaget::eom;
162-
exit(0);
163-
}
154+
bool add_function_failed = goto_model.symbol_table.add(havoc_function_symbol);
155+
INVARIANT(
156+
!add_function_failed,
157+
"DFCC: could not insert havoc function '" + id2string(havoc_function_id) +
158+
"' in the symbol table");
164159

165160
// create new goto_function
166161
goto_functiont dummy_havoc_function;

src/goto-instrument/contracts/dynamic-frames/dfcc_utils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ exprt dfcc_utilst::make_sizeof_expr(const exprt &expr)
456456
exprt dfcc_utilst::make_map_start_address(const exprt &expr)
457457
{
458458
return typecast_exprt::conditional_cast(
459-
address_of_exprt(index_exprt(expr, from_integer(0, c_index_type()))),
459+
address_of_exprt(index_exprt(
460+
expr, from_integer(0, to_array_type(expr.type()).index_type()))),
460461
pointer_type(bool_typet()));
461462
}
462463

0 commit comments

Comments
 (0)