@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com
1515#include < memory>
1616#include < sstream>
1717
18+ #include < util/invariant.h>
1819#include < util/std_expr.h>
1920#include < util/std_code.h>
2021
@@ -220,7 +221,7 @@ void ai_baset::finalize()
220221ai_baset::locationt ai_baset::get_next (
221222 working_sett &working_set)
222223{
223- assert (!working_set.empty ());
224+ PRECONDITION (!working_set.empty ());
224225
225226 working_sett::iterator i=working_set.begin ();
226227 locationt l=i->second ;
@@ -248,6 +249,16 @@ bool ai_baset::fixedpoint(
248249 {
249250 locationt l=get_next (working_set);
250251
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+
251262 if (visit (l, working_set, goto_program, goto_functions, ns))
252263 new_data=true ;
253264 }
@@ -323,6 +334,8 @@ bool ai_baset::do_function_call(
323334 // initialize state, if necessary
324335 get_state (l_return);
325336
337+ PRECONDITION (l_call->is_function_call ());
338+
326339 const goto_functionst::goto_functiont &goto_function=
327340 f_it->second ;
328341
@@ -388,7 +401,17 @@ bool ai_baset::do_function_call_rec(
388401 const goto_functionst &goto_functions,
389402 const namespacet &ns)
390403{
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" );
392415
393416 bool new_data=false ;
394417
@@ -411,8 +434,7 @@ bool ai_baset::do_function_call_rec(
411434 }
412435 else if (function.id ()==ID_if)
413436 {
414- if (function.operands ().size ()!=3 )
415- throw " if has three operands" ;
437+ DATA_INVARIANT (function.operands ().size () != 3 , " if has three operands" );
416438
417439 bool new_data1=
418440 do_function_call_rec (
@@ -433,19 +455,6 @@ bool ai_baset::do_function_call_rec(
433455 if (new_data1 || new_data2)
434456 new_data=true ;
435457 }
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- }
449458 else
450459 {
451460 throw " unexpected function_call argument: " +
0 commit comments