@@ -778,20 +778,20 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
778778 bool allow_merge)
779779{
780780 // Check the tree shape invariant:
781- assert (tree.branch .size ()== tree.branch_addresses .size ());
781+ PRECONDITION (tree.branch .size () == tree.branch_addresses .size ());
782782
783783 // If there are no child blocks, return this.
784784 if (tree.leaf )
785785 return this_block;
786- assert (!tree.branch .empty ());
786+ PRECONDITION (!tree.branch .empty ());
787787
788788 // Find child block starting > address_start:
789789 const auto afterstart=
790790 std::upper_bound (
791791 tree.branch_addresses .begin (),
792792 tree.branch_addresses .end (),
793793 address_start);
794- assert (afterstart!= tree.branch_addresses .begin ());
794+ CHECK_RETURN (afterstart != tree.branch_addresses .begin ());
795795 auto findstart=afterstart;
796796 --findstart;
797797 auto child_offset=
@@ -819,9 +819,9 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
819819 while (child_iter != this_block.statements ().end () &&
820820 child_iter->get_statement () == ID_decl)
821821 ++child_iter;
822- assert (child_iter != this_block.statements ().end ());
822+ CHECK_RETURN (child_iter != this_block.statements ().end ());
823823 std::advance (child_iter, child_offset);
824- assert (child_iter != this_block.statements ().end ());
824+ CHECK_RETURN (child_iter != this_block.statements ().end ());
825825 auto &child_label=to_code_label (*child_iter);
826826 auto &child_block=to_code_block (child_label.code ());
827827
@@ -853,7 +853,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
853853 // Check for incoming control-flow edges targeting non-header
854854 // blocks of the new proposed block range:
855855 auto checkit=amap.find (*findstart);
856- assert (checkit!= amap.end ());
856+ CHECK_RETURN (checkit != amap.end ());
857857 ++checkit; // Skip the header, which can have incoming edges from outside.
858858 for (;
859859 checkit!=amap.end () && (checkit->first )<(findlim_block_start_address);
@@ -885,15 +885,15 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
885885 code_labelt newlabel (child_label_name, code_blockt ());
886886 code_blockt &newblock=to_code_block (newlabel.code ());
887887 auto nblocks=std::distance (findstart, findlim);
888- assert (nblocks>= 2 );
888+ CHECK_RETURN (nblocks >= 2 );
889889 log.debug () << " Generating codet: combining "
890890 << std::distance (findstart, findlim) << " blocks for addresses "
891891 << (*findstart) << " -" << findlim_block_start_address
892892 << messaget::eom;
893893
894894 // Make a new block containing every child of interest:
895895 auto &this_block_children = this_block.statements ();
896- assert (tree.branch .size ()== this_block_children.size ());
896+ CHECK_RETURN (tree.branch .size () == this_block_children.size ());
897897 for (auto blockidx=child_offset, blocklim=child_offset+nblocks;
898898 blockidx!=blocklim;
899899 ++blockidx)
@@ -923,7 +923,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
923923 ++branchstart;
924924 tree.branch .erase (branchstart, branchlim);
925925
926- assert (tree.branch .size ()== this_block_children.size ());
926+ CHECK_RETURN (tree.branch .size () == this_block_children.size ());
927927
928928 auto branchaddriter=tree.branch_addresses .begin ();
929929 std::advance (branchaddriter, child_offset);
@@ -939,7 +939,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
939939
940940 tree.branch [child_offset]=std::move (newnode);
941941
942- assert (tree.branch .size ()== tree.branch_addresses .size ());
942+ CHECK_RETURN (tree.branch .size () == tree.branch_addresses .size ());
943943
944944 return
945945 to_code_block (
@@ -1079,10 +1079,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
10791079 converted_instructiont ins=converted_instructiont (i_it, code_skipt ());
10801080 std::pair<address_mapt::iterator, bool > a_entry=
10811081 address_map.insert (std::make_pair (i_it->address , ins));
1082- assert (a_entry.second );
1082+ CHECK_RETURN (a_entry.second );
10831083 // addresses are strictly increasing, hence we must have inserted
10841084 // a new maximal key
1085- assert (a_entry.first == --address_map.end ());
1085+ CHECK_RETURN (a_entry.first == --address_map.end ());
10861086
10871087 const auto bytecode = i_it->bytecode ;
10881088 const std::string statement = bytecode_info[i_it->bytecode ].mnemonic ;
@@ -1222,9 +1222,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
12221222 instruction.stack .clear ();
12231223 codet &c = instruction.code ;
12241224
1225- assert (
1225+ INVARIANT (
12261226 stack.empty () || instruction.predecessors .size () <= 1 ||
1227- has_prefix (stack.front ().get_string (ID_C_base_name), " $stack" ));
1227+ has_prefix (stack.front ().get_string (ID_C_base_name), " $stack" ),
1228+ " inconsistent stack" );
12281229
12291230 exprt arg0=i_it->args .size ()>=1 ?i_it->args [0 ]:nil_exprt ();
12301231 exprt arg1=i_it->args .size ()>=2 ?i_it->args [1 ]:nil_exprt ();
@@ -1293,7 +1294,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
12931294
12941295 if (bytecode == BC_aconst_null)
12951296 {
1296- assert (results.size ()== 1 );
1297+ PRECONDITION (results.size () == 1 );
12971298 results[0 ] = null_pointer_exprt (java_reference_type (java_void_type ()));
12981299 }
12991300 else if (bytecode == BC_athrow)
@@ -1433,18 +1434,18 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
14331434 // and write something like:
14341435 // if(retaddr==5) goto 5; else if(retaddr==10) goto 10; ...
14351436 PRECONDITION (op.empty () && results.empty ());
1436- assert (!jsr_ret_targets.empty ());
1437+ PRECONDITION (!jsr_ret_targets.empty ());
14371438 c = convert_ret (
14381439 jsr_ret_targets, arg0, i_it->source_location , i_it->address );
14391440 }
14401441 else if (bytecode == BC_iconst_m1)
14411442 {
1442- assert (results.size ()== 1 );
1443+ PRECONDITION (results.size () == 1 );
14431444 results[0 ]=from_integer (-1 , java_int_type ());
14441445 }
14451446 else if (bytecode == patternt (" ?const_?" ))
14461447 {
1447- assert (results.size ()== 1 );
1448+ PRECONDITION (results.size () == 1 );
14481449 results = convert_const (statement, to_constant_expr (arg0), results);
14491450 }
14501451 else if (bytecode == patternt (" ?ipush" ))
@@ -1742,7 +1743,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
17421743 numeric_cast_v<std::size_t >(to_constant_expr (arg1));
17431744
17441745 op=pop (dimension);
1745- assert (results.size ()== 1 );
1746+ PRECONDITION (results.size () == 1 );
17461747 c = convert_multianewarray (i_it->source_location , arg0, op, results);
17471748 }
17481749 else if (bytecode == BC_arraylength)
@@ -1853,7 +1854,9 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
18531854 stackt::const_iterator os_it=a_it2->second .stack .begin ();
18541855 for (auto &expr : stack)
18551856 {
1856- assert (has_prefix (os_it->get_string (ID_C_base_name), " $stack" ));
1857+ INVARIANT (
1858+ has_prefix (os_it->get_string (ID_C_base_name), " $stack" ),
1859+ " invalid base name" );
18571860 symbol_exprt lhs=to_symbol_expr (*os_it);
18581861 code_assignt a (lhs, expr);
18591862 more_code.add (a);
@@ -1926,7 +1929,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
19261929 for (const auto &address_pair : address_map)
19271930 {
19281931 const method_offsett address = address_pair.first ;
1929- assert (address_pair.first == address_pair.second .source ->address );
1932+ CHECK_RETURN (address_pair.first == address_pair.second .source ->address );
19301933 const codet &c=address_pair.second .code ;
19311934
19321935 // Start a new lexical block if this is a branch target:
@@ -1955,9 +1958,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
19551958 root_block.add (
19561959 code_labelt{label (std::to_string (address)), code_blockt{}});
19571960 root.branch .push_back (block_tree_nodet::get_leaf ());
1958- assert ((root.branch_addresses .empty () ||
1959- root.branch_addresses .back ()<address) &&
1960- " Block addresses should be unique and increasing" );
1961+ INVARIANT (
1962+ (root.branch_addresses .empty () ||
1963+ root.branch_addresses .back () < address),
1964+ " Block addresses should be unique and increasing" );
19611965 root.branch_addresses .push_back (address);
19621966 }
19631967
0 commit comments