15
15
#include < memory>
16
16
#include < sstream>
17
17
18
+ #include < util/invariant.h>
18
19
#include < util/std_expr.h>
19
20
#include < util/std_code.h>
20
21
@@ -220,7 +221,7 @@ void ai_baset::finalize()
220
221
ai_baset::locationt ai_baset::get_next (
221
222
working_sett &working_set)
222
223
{
223
- assert (!working_set.empty ());
224
+ PRECONDITION (!working_set.empty ());
224
225
225
226
working_sett::iterator i=working_set.begin ();
226
227
locationt l=i->second ;
@@ -248,6 +249,16 @@ bool ai_baset::fixedpoint(
248
249
{
249
250
locationt l=get_next (working_set);
250
251
252
+ // goto_program is really only needed for iterator manipulation
253
+ auto it = goto_functions.function_map .find (l->function );
254
+
255
+ DATA_INVARIANT (
256
+ it != goto_functions.function_map .end (),
257
+ " instruction.function must be a mapped function" );
258
+ DATA_INVARIANT (
259
+ it->second .body_available (),
260
+ " instruction.function implies instruction is in function" );
261
+
251
262
if (visit (l, working_set, goto_program, goto_functions, ns))
252
263
new_data=true ;
253
264
}
@@ -323,6 +334,8 @@ bool ai_baset::do_function_call(
323
334
// initialize state, if necessary
324
335
get_state (l_return);
325
336
337
+ PRECONDITION (l_call->is_function_call ());
338
+
326
339
const goto_functionst::goto_functiont &goto_function=
327
340
f_it->second ;
328
341
@@ -388,7 +401,17 @@ bool ai_baset::do_function_call_rec(
388
401
const goto_functionst &goto_functions,
389
402
const namespacet &ns)
390
403
{
391
- assert (!goto_functions.function_map .empty ());
404
+ PRECONDITION (!goto_functions.function_map .empty ());
405
+
406
+ // We can't really do this here -- we rely on
407
+ // these being removed by some previous analysis.
408
+ PRECONDITION (function.id () != ID_dereference);
409
+
410
+ // Can't be a function
411
+ DATA_INVARIANT (
412
+ function.id () != " NULL-object" , " Function cannot be null object" );
413
+ DATA_INVARIANT (function.id () != ID_member, " Function cannot be struct field" );
414
+ DATA_INVARIANT (function.id () != ID_index, " Function cannot be array element" );
392
415
393
416
bool new_data=false ;
394
417
@@ -411,8 +434,7 @@ bool ai_baset::do_function_call_rec(
411
434
}
412
435
else if (function.id ()==ID_if)
413
436
{
414
- if (function.operands ().size ()!=3 )
415
- throw " if has three operands" ;
437
+ DATA_INVARIANT (function.operands ().size () != 3 , " if has three operands" );
416
438
417
439
bool new_data1=
418
440
do_function_call_rec (
@@ -433,19 +455,6 @@ bool ai_baset::do_function_call_rec(
433
455
if (new_data1 || new_data2)
434
456
new_data=true ;
435
457
}
436
- else if (function.id ()==ID_dereference)
437
- {
438
- // We can't really do this here -- we rely on
439
- // these being removed by some previous analysis.
440
- }
441
- else if (function.id () == ID_null_object)
442
- {
443
- // ignore, can't be a function
444
- }
445
- else if (function.id ()==ID_member || function.id ()==ID_index)
446
- {
447
- // ignore, can't be a function
448
- }
449
458
else
450
459
{
451
460
throw " unexpected function_call argument: " +
0 commit comments