@@ -773,20 +773,20 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
773773 bool allow_merge)
774774{
775775 // Check the tree shape invariant:
776- assert (tree.branch .size ()== tree.branch_addresses .size ());
776+ PRECONDITION (tree.branch .size () == tree.branch_addresses .size ());
777777
778778 // If there are no child blocks, return this.
779779 if (tree.leaf )
780780 return this_block;
781- assert (!tree.branch .empty ());
781+ PRECONDITION (!tree.branch .empty ());
782782
783783 // Find child block starting > address_start:
784784 const auto afterstart=
785785 std::upper_bound (
786786 tree.branch_addresses .begin (),
787787 tree.branch_addresses .end (),
788788 address_start);
789- assert (afterstart!= tree.branch_addresses .begin ());
789+ CHECK_RETURN (afterstart != tree.branch_addresses .begin ());
790790 auto findstart=afterstart;
791791 --findstart;
792792 auto child_offset=
@@ -814,9 +814,9 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
814814 while (child_iter != this_block.statements ().end () &&
815815 child_iter->get_statement () == ID_decl)
816816 ++child_iter;
817- assert (child_iter != this_block.statements ().end ());
817+ CHECK_RETURN (child_iter != this_block.statements ().end ());
818818 std::advance (child_iter, child_offset);
819- assert (child_iter != this_block.statements ().end ());
819+ CHECK_RETURN (child_iter != this_block.statements ().end ());
820820 auto &child_label=to_code_label (*child_iter);
821821 auto &child_block=to_code_block (child_label.code ());
822822
@@ -848,7 +848,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
848848 // Check for incoming control-flow edges targeting non-header
849849 // blocks of the new proposed block range:
850850 auto checkit=amap.find (*findstart);
851- assert (checkit!= amap.end ());
851+ CHECK_RETURN (checkit != amap.end ());
852852 ++checkit; // Skip the header, which can have incoming edges from outside.
853853 for (;
854854 checkit!=amap.end () && (checkit->first )<(findlim_block_start_address);
@@ -880,15 +880,15 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
880880 code_labelt newlabel (child_label_name, code_blockt ());
881881 code_blockt &newblock=to_code_block (newlabel.code ());
882882 auto nblocks=std::distance (findstart, findlim);
883- assert (nblocks>= 2 );
883+ CHECK_RETURN (nblocks >= 2 );
884884 log.debug () << " Generating codet: combining "
885885 << std::distance (findstart, findlim) << " blocks for addresses "
886886 << (*findstart) << " -" << findlim_block_start_address
887887 << messaget::eom;
888888
889889 // Make a new block containing every child of interest:
890890 auto &this_block_children = this_block.statements ();
891- assert (tree.branch .size ()== this_block_children.size ());
891+ CHECK_RETURN (tree.branch .size () == this_block_children.size ());
892892 for (auto blockidx=child_offset, blocklim=child_offset+nblocks;
893893 blockidx!=blocklim;
894894 ++blockidx)
@@ -918,7 +918,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
918918 ++branchstart;
919919 tree.branch .erase (branchstart, branchlim);
920920
921- assert (tree.branch .size ()== this_block_children.size ());
921+ CHECK_RETURN (tree.branch .size () == this_block_children.size ());
922922
923923 auto branchaddriter=tree.branch_addresses .begin ();
924924 std::advance (branchaddriter, child_offset);
@@ -934,7 +934,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
934934
935935 tree.branch [child_offset]=std::move (newnode);
936936
937- assert (tree.branch .size ()== tree.branch_addresses .size ());
937+ CHECK_RETURN (tree.branch .size () == tree.branch_addresses .size ());
938938
939939 return
940940 to_code_block (
@@ -1074,10 +1074,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
10741074 converted_instructiont ins=converted_instructiont (i_it, code_skipt ());
10751075 std::pair<address_mapt::iterator, bool > a_entry=
10761076 address_map.insert (std::make_pair (i_it->address , ins));
1077- assert (a_entry.second );
1077+ CHECK_RETURN (a_entry.second );
10781078 // addresses are strictly increasing, hence we must have inserted
10791079 // a new maximal key
1080- assert (a_entry.first == --address_map.end ());
1080+ CHECK_RETURN (a_entry.first == --address_map.end ());
10811081
10821082 const auto bytecode = i_it->bytecode ;
10831083 const std::string statement = bytecode_info[i_it->bytecode ].mnemonic ;
@@ -1217,9 +1217,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
12171217 instruction.stack .clear ();
12181218 codet &c = instruction.code ;
12191219
1220- assert (
1220+ INVARIANT (
12211221 stack.empty () || instruction.predecessors .size () <= 1 ||
1222- has_prefix (stack.front ().get_string (ID_C_base_name), " $stack" ));
1222+ has_prefix (stack.front ().get_string (ID_C_base_name), " $stack" ),
1223+ " inconsistent stack" );
12231224
12241225 exprt arg0=i_it->args .size ()>=1 ?i_it->args [0 ]:nil_exprt ();
12251226 exprt arg1=i_it->args .size ()>=2 ?i_it->args [1 ]:nil_exprt ();
@@ -1288,7 +1289,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
12881289
12891290 if (bytecode == BC_aconst_null)
12901291 {
1291- assert (results.size ()== 1 );
1292+ PRECONDITION (results.size () == 1 );
12921293 results[0 ] = null_pointer_exprt (java_reference_type (java_void_type ()));
12931294 }
12941295 else if (bytecode == BC_athrow)
@@ -1428,23 +1429,23 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
14281429 // and write something like:
14291430 // if(retaddr==5) goto 5; else if(retaddr==10) goto 10; ...
14301431 PRECONDITION (op.empty () && results.empty ());
1431- assert (!jsr_ret_targets.empty ());
1432+ PRECONDITION (!jsr_ret_targets.empty ());
14321433 c = convert_ret (
14331434 jsr_ret_targets, arg0, i_it->source_location , i_it->address );
14341435 }
14351436 else if (bytecode == BC_iconst_m1)
14361437 {
1437- assert (results.size ()== 1 );
1438+ CHECK_RETURN (results.size () == 1 );
14381439 results[0 ]=from_integer (-1 , java_int_type ());
14391440 }
14401441 else if (bytecode == patternt (" ?const_?" ))
14411442 {
1442- assert (results.size ()== 1 );
1443+ CHECK_RETURN (results.size () == 1 );
14431444 results = convert_const (statement, to_constant_expr (arg0), results);
14441445 }
14451446 else if (bytecode == patternt (" ?ipush" ))
14461447 {
1447- PRECONDITION (results.size ()== 1 );
1448+ CHECK_RETURN (results.size () == 1 );
14481449 DATA_INVARIANT (
14491450 arg0.id ()==ID_constant,
14501451 " ipush argument expected to be constant" );
@@ -1737,7 +1738,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
17371738 numeric_cast_v<std::size_t >(to_constant_expr (arg1));
17381739
17391740 op=pop (dimension);
1740- assert (results.size ()== 1 );
1741+ CHECK_RETURN (results.size () == 1 );
17411742 c = convert_multianewarray (i_it->source_location , arg0, op, results);
17421743 }
17431744 else if (bytecode == BC_arraylength)
@@ -1848,7 +1849,9 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
18481849 stackt::const_iterator os_it=a_it2->second .stack .begin ();
18491850 for (auto &expr : stack)
18501851 {
1851- assert (has_prefix (os_it->get_string (ID_C_base_name), " $stack" ));
1852+ INVARIANT (
1853+ has_prefix (os_it->get_string (ID_C_base_name), " $stack" ),
1854+ " invalid base name" );
18521855 symbol_exprt lhs=to_symbol_expr (*os_it);
18531856 code_assignt a (lhs, expr);
18541857 more_code.add (a);
@@ -1917,7 +1920,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
19171920 for (const auto &address_pair : address_map)
19181921 {
19191922 const method_offsett address = address_pair.first ;
1920- assert (address_pair.first == address_pair.second .source ->address );
1923+ CHECK_RETURN (address_pair.first == address_pair.second .source ->address );
19211924 const codet &c=address_pair.second .code ;
19221925
19231926 // Start a new lexical block if this is a branch target:
@@ -1946,9 +1949,10 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
19461949 root_block.add (
19471950 code_labelt{label (std::to_string (address)), code_blockt{}});
19481951 root.branch .push_back (block_tree_nodet::get_leaf ());
1949- assert ((root.branch_addresses .empty () ||
1950- root.branch_addresses .back ()<address) &&
1951- " Block addresses should be unique and increasing" );
1952+ INVARIANT (
1953+ (root.branch_addresses .empty () ||
1954+ root.branch_addresses .back () < address),
1955+ " Block addresses should be unique and increasing" );
19521956 root.branch_addresses .push_back (address);
19531957 }
19541958
0 commit comments