Skip to content

Commit 5961234

Browse files
committed
address_mapt keys are std::size_t
... as that's the type of keys being used during lookup.
1 parent 45f469d commit 5961234

File tree

3 files changed

+92
-89
lines changed

3 files changed

+92
-89
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ void java_bytecode_convert_methodt::replace_goto_target(
714714
code_blockt &java_bytecode_convert_methodt::get_block_for_pcrange(
715715
block_tree_nodet &tree,
716716
code_blockt &this_block,
717-
unsigned address_start,
718-
unsigned address_limit,
719-
unsigned next_block_start_address)
717+
std::size_t address_start,
718+
std::size_t address_limit,
719+
std::size_t next_block_start_address)
720720
{
721721
address_mapt dummy;
722722
return get_or_create_block_for_pcrange(
@@ -746,9 +746,9 @@ code_blockt &java_bytecode_convert_methodt::get_block_for_pcrange(
746746
code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
747747
block_tree_nodet &tree,
748748
code_blockt &this_block,
749-
unsigned address_start,
750-
unsigned address_limit,
751-
unsigned next_block_start_address,
749+
std::size_t address_start,
750+
std::size_t address_limit,
751+
std::size_t next_block_start_address,
752752
const address_mapt &amap,
753753
bool allow_merge)
754754
{
@@ -778,10 +778,9 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
778778
tree.branch_addresses.begin(),
779779
tree.branch_addresses.end(),
780780
address_limit);
781-
unsigned findlim_block_start_address=
782-
findlim==tree.branch_addresses.end() ?
783-
next_block_start_address :
784-
(*findlim);
781+
const auto findlim_block_start_address =
782+
findlim == tree.branch_addresses.end() ? next_block_start_address
783+
: (*findlim);
785784

786785
// If all children are in scope, return this.
787786
if(findstart==tree.branch_addresses.begin() &&
@@ -924,7 +923,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
924923
}
925924

926925
static void gather_symbol_live_ranges(
927-
unsigned pc,
926+
std::size_t pc,
928927
const exprt &e,
929928
std::map<irep_idt, java_bytecode_convert_methodt::variablet> &result)
930929
{
@@ -1002,9 +1001,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
10021001
// first pass: get targets and map addresses to instructions
10031002

10041003
address_mapt address_map;
1005-
std::set<unsigned> targets;
1004+
std::set<std::size_t> targets;
10061005

1007-
std::vector<unsigned> jsr_ret_targets;
1006+
std::vector<std::size_t> jsr_ret_targets;
10081007
std::vector<instructionst::const_iterator> ret_instructions;
10091008

10101009
for(auto i_it = instructions.begin(); i_it != instructions.end(); i_it++)
@@ -1049,9 +1048,9 @@ codet java_bytecode_convert_methodt::convert_instructions(
10491048
(threading_support && (i_it->statement=="monitorenter" ||
10501049
i_it->statement=="monitorexit")))
10511050
{
1052-
const std::vector<unsigned int> handler =
1051+
const std::vector<std::size_t> handler =
10531052
try_catch_handler(i_it->address, method.exception_table);
1054-
std::list<unsigned int> &successors = a_entry.first->second.successors;
1053+
std::list<std::size_t> &successors = a_entry.first->second.successors;
10551054
successors.insert(successors.end(), handler.begin(), handler.end());
10561055
targets.insert(handler.begin(), handler.end());
10571056
}
@@ -1110,7 +1109,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
11101109

11111110
for(const auto &address : address_map)
11121111
{
1113-
for(unsigned s : address.second.successors)
1112+
for(auto s : address.second.successors)
11141113
{
11151114
const auto a_it = address_map.find(s);
11161115
CHECK_RETURN(a_it != address_map.end());
@@ -1128,7 +1127,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
11281127
// (these require the graph to determine live ranges)
11291128
setup_local_variables(method, address_map);
11301129

1131-
std::set<unsigned> working_set;
1130+
std::set<std::size_t> working_set;
11321131

11331132
if(!instructions.empty())
11341133
working_set.insert(instructions.front().address);
@@ -1139,7 +1138,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
11391138
auto address_it = address_map.find(*cur);
11401139
CHECK_RETURN(address_it != address_map.end());
11411140
auto &instruction = address_it->second;
1142-
unsigned cur_pc=*cur;
1141+
const std::size_t cur_pc = *cur;
11431142
working_set.erase(cur);
11441143

11451144
if(instruction.done)
@@ -1698,7 +1697,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
16981697
push(results);
16991698

17001699
instruction.done = true;
1701-
for(const unsigned address : instruction.successors)
1700+
for(const auto address : instruction.successors)
17021701
{
17031702
address_mapt::iterator a_it2=address_map.find(address);
17041703
CHECK_RETURN(a_it2 != address_map.end());
@@ -1807,10 +1806,10 @@ codet java_bytecode_convert_methodt::convert_instructions(
18071806
// constructs as variable live-ranges require next.
18081807
bool start_new_block=true;
18091808
bool has_seen_previous_address=false;
1810-
unsigned previous_address=0;
1809+
std::size_t previous_address = 0;
18111810
for(const auto &address_pair : address_map)
18121811
{
1813-
const unsigned address=address_pair.first;
1812+
const std::size_t address = address_pair.first;
18141813
assert(address_pair.first==address_pair.second.source->address);
18151814
const codet &c=address_pair.second.code;
18161815

@@ -1890,8 +1889,8 @@ codet java_bytecode_convert_methodt::convert_instructions(
18901889
root,
18911890
root_block,
18921891
v.start_pc,
1893-
v.start_pc+v.length,
1894-
std::numeric_limits<unsigned>::max(),
1892+
v.start_pc + v.length,
1893+
std::numeric_limits<std::size_t>::max(),
18951894
address_map);
18961895
}
18971896
for(const auto vp : vars_to_process)
@@ -1902,12 +1901,12 @@ codet java_bytecode_convert_methodt::convert_instructions(
19021901
// Skip anonymous variables:
19031902
if(v.symbol_expr.get_identifier().empty())
19041903
continue;
1905-
auto &block=get_block_for_pcrange(
1904+
auto &block = get_block_for_pcrange(
19061905
root,
19071906
root_block,
19081907
v.start_pc,
1909-
v.start_pc+v.length,
1910-
std::numeric_limits<unsigned>::max());
1908+
v.start_pc + v.length,
1909+
std::numeric_limits<std::size_t>::max());
19111910
code_declt d(v.symbol_expr);
19121911
block.operands().insert(block.operands().begin(), d);
19131912
}
@@ -1963,7 +1962,8 @@ codet java_bytecode_convert_methodt::convert_switch(
19631962
// to the jump target of the tableswitch/lookupswitch case at
19641963
// hand. Therefore we consider this code to belong to the source bytecode
19651964
// instruction and not the target instruction.
1966-
code_case.code() = code_gotot(label(integer2string(number)));
1965+
const std::size_t label_number = numeric_cast_v<std::size_t>(number);
1966+
code_case.code() = code_gotot(label(std::to_string(label_number)));
19671967
code_case.code().add_source_location() = location;
19681968

19691969
if(a_it == args.begin())
@@ -2338,8 +2338,8 @@ void java_bytecode_convert_methodt::convert_athrow(
23382338

23392339
codet &java_bytecode_convert_methodt::do_exception_handling(
23402340
const java_bytecode_convert_methodt::methodt &method,
2341-
const std::set<unsigned int> &working_set,
2342-
unsigned int cur_pc,
2341+
const std::set<std::size_t> &working_set,
2342+
std::size_t cur_pc,
23432343
codet &c)
23442344
{
23452345
std::vector<irep_idt> exception_ids;
@@ -2722,7 +2722,7 @@ codet java_bytecode_convert_methodt::convert_iinc(
27222722
const exprt &arg0,
27232723
const exprt &arg1,
27242724
const source_locationt &location,
2725-
const unsigned address)
2725+
const std::size_t address)
27262726
{
27272727
code_blockt block;
27282728
block.add_source_location() = location;
@@ -2756,9 +2756,10 @@ codet java_bytecode_convert_methodt::convert_ifnull(
27562756
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
27572757
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
27582758
code_branch.cond() = binary_relation_exprt(lhs, ID_equal, rhs);
2759-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2759+
const std::size_t label_number = numeric_cast_v<std::size_t>(number);
2760+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27602761
code_branch.then_case().add_source_location() =
2761-
address_map.at(integer2unsigned(number)).source->source_location;
2762+
address_map.at(label_number).source->source_location;
27622763
code_branch.add_source_location() = location;
27632764
return code_branch;
27642765
}
@@ -2773,9 +2774,10 @@ codet java_bytecode_convert_methodt::convert_ifnonull(
27732774
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
27742775
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
27752776
code_branch.cond() = binary_relation_exprt(lhs, ID_notequal, rhs);
2776-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2777+
const std::size_t label_number = numeric_cast_v<std::size_t>(number);
2778+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27772779
code_branch.then_case().add_source_location() =
2778-
address_map.at(integer2unsigned(number)).source->source_location;
2780+
address_map.at(label_number).source->source_location;
27792781
code_branch.add_source_location() = location;
27802782
return code_branch;
27812783
}
@@ -2792,9 +2794,10 @@ codet java_bytecode_convert_methodt::convert_if(
27922794
binary_relation_exprt(op[0], id, from_integer(0, op[0].type()));
27932795
code_branch.cond().add_source_location() = location;
27942796
code_branch.cond().add_source_location().set_function(method_id);
2795-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2797+
const std::size_t label_number = numeric_cast_v<std::size_t>(number);
2798+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27962799
code_branch.then_case().add_source_location() =
2797-
address_map.at(integer2unsigned(number)).source->source_location;
2800+
address_map.at(label_number).source->source_location;
27982801
code_branch.then_case().add_source_location().set_function(method_id);
27992802
code_branch.add_source_location() = location;
28002803
code_branch.add_source_location().set_function(method_id);
@@ -2821,19 +2824,20 @@ codet java_bytecode_convert_methodt::convert_if_cmp(
28212824

28222825
code_branch.cond() = condition;
28232826
code_branch.cond().add_source_location() = location;
2824-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2827+
const std::size_t label_number = numeric_cast_v<std::size_t>(number);
2828+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
28252829
code_branch.then_case().add_source_location() =
2826-
address_map.at(integer2unsigned(number)).source->source_location;
2830+
address_map.at(label_number).source->source_location;
28272831
code_branch.add_source_location() = location;
28282832

28292833
return code_branch;
28302834
}
28312835

28322836
code_blockt java_bytecode_convert_methodt::convert_ret(
2833-
const std::vector<unsigned int> &jsr_ret_targets,
2837+
const std::vector<std::size_t> &jsr_ret_targets,
28342838
const exprt &arg0,
28352839
const source_locationt &location,
2836-
const unsigned address)
2840+
const std::size_t address)
28372841
{
28382842
code_blockt c;
28392843
auto retvar = variable(arg0, 'a', address, NO_CAST);
@@ -2885,7 +2889,7 @@ codet java_bytecode_convert_methodt::convert_store(
28852889
const irep_idt &statement,
28862890
const exprt &arg0,
28872891
const exprt::operandst &op,
2888-
const unsigned address,
2892+
const std::size_t address,
28892893
const source_locationt &location)
28902894
{
28912895
const exprt var = variable(arg0, statement[0], address, NO_CAST);
@@ -2974,7 +2978,7 @@ optionalt<exprt> java_bytecode_convert_methodt::convert_invoke_dynamic(
29742978

29752979
void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
29762980
java_bytecode_convert_methodt::address_mapt &address_map,
2977-
const std::vector<unsigned int> &jsr_ret_targets,
2981+
const std::vector<std::size_t> &jsr_ret_targets,
29782982
const std::vector<
29792983
std::vector<java_bytecode_parse_treet::instructiont>::const_iterator>
29802984
&ret_instructions) const
@@ -2988,12 +2992,12 @@ void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
29882992
}
29892993
}
29902994

2991-
std::vector<unsigned> java_bytecode_convert_methodt::try_catch_handler(
2992-
const unsigned int address,
2995+
std::vector<std::size_t> java_bytecode_convert_methodt::try_catch_handler(
2996+
const std::size_t address,
29932997
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
29942998
const
29952999
{
2996-
std::vector<unsigned> result;
3000+
std::vector<std::size_t> result;
29973001
for(const auto &exception_row : exception_table)
29983002
{
29993003
if(address >= exception_row.start_pc && address < exception_row.end_pc)

0 commit comments

Comments
 (0)