Skip to content

Commit 5202f4a

Browse files
authored
Merge pull request #3035 from tautschnig/address_mapt
address_mapt keys are std::size_t
2 parents e67c662 + 57cd9c1 commit 5202f4a

File tree

3 files changed

+111
-93
lines changed

3 files changed

+111
-93
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 53 additions & 47 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+
method_offsett address_start,
718+
method_offsett address_limit,
719+
method_offsett 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+
method_offsett address_start,
750+
method_offsett address_limit,
751+
method_offsett 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+
java_bytecode_convert_methodt::method_offsett 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<method_offsett> targets;
10061005

1007-
std::vector<unsigned> jsr_ret_targets;
1006+
std::vector<method_offsett> 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<method_offsett> 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<method_offsett> &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<method_offsett> 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 method_offsett 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+
method_offsett previous_address = 0;
18111810
for(const auto &address_pair : address_map)
18121811
{
1813-
const unsigned address=address_pair.first;
1812+
const method_offsett 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<method_offsett>::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<method_offsett>::max());
19111910
code_declt d(v.symbol_expr);
19121911
block.operands().insert(block.operands().begin(), d);
19131912
}
@@ -1963,7 +1962,9 @@ 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 method_offsett label_number =
1966+
numeric_cast_v<method_offsett>(number);
1967+
code_case.code() = code_gotot(label(std::to_string(label_number)));
19671968
code_case.code().add_source_location() = location;
19681969

19691970
if(a_it == args.begin())
@@ -2338,8 +2339,8 @@ void java_bytecode_convert_methodt::convert_athrow(
23382339

23392340
codet &java_bytecode_convert_methodt::do_exception_handling(
23402341
const java_bytecode_convert_methodt::methodt &method,
2341-
const std::set<unsigned int> &working_set,
2342-
unsigned int cur_pc,
2342+
const std::set<method_offsett> &working_set,
2343+
method_offsett cur_pc,
23432344
codet &c)
23442345
{
23452346
std::vector<irep_idt> exception_ids;
@@ -2350,8 +2351,8 @@ codet &java_bytecode_convert_methodt::do_exception_handling(
23502351
// together with a list of all the exception ids
23512352

23522353
// be aware of different try-catch blocks with the same starting pc
2353-
std::size_t pos = 0;
2354-
std::size_t end_pc = 0;
2354+
method_offsett pos = 0;
2355+
method_offsett end_pc = 0;
23552356
while(pos < method.exception_table.size())
23562357
{
23572358
// check if this is the beginning of a try block
@@ -2722,7 +2723,7 @@ codet java_bytecode_convert_methodt::convert_iinc(
27222723
const exprt &arg0,
27232724
const exprt &arg1,
27242725
const source_locationt &location,
2725-
const unsigned address)
2726+
const method_offsett address)
27262727
{
27272728
code_blockt block;
27282729
block.add_source_location() = location;
@@ -2756,9 +2757,10 @@ codet java_bytecode_convert_methodt::convert_ifnull(
27562757
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
27572758
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
27582759
code_branch.cond() = binary_relation_exprt(lhs, ID_equal, rhs);
2759-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2760+
const method_offsett label_number = numeric_cast_v<method_offsett>(number);
2761+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27602762
code_branch.then_case().add_source_location() =
2761-
address_map.at(integer2unsigned(number)).source->source_location;
2763+
address_map.at(label_number).source->source_location;
27622764
code_branch.add_source_location() = location;
27632765
return code_branch;
27642766
}
@@ -2773,9 +2775,10 @@ codet java_bytecode_convert_methodt::convert_ifnonull(
27732775
const typecast_exprt lhs(op[0], java_reference_type(empty_typet()));
27742776
const exprt rhs(null_pointer_exprt(to_pointer_type(lhs.type())));
27752777
code_branch.cond() = binary_relation_exprt(lhs, ID_notequal, rhs);
2776-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2778+
const method_offsett label_number = numeric_cast_v<method_offsett>(number);
2779+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27772780
code_branch.then_case().add_source_location() =
2778-
address_map.at(integer2unsigned(number)).source->source_location;
2781+
address_map.at(label_number).source->source_location;
27792782
code_branch.add_source_location() = location;
27802783
return code_branch;
27812784
}
@@ -2792,9 +2795,10 @@ codet java_bytecode_convert_methodt::convert_if(
27922795
binary_relation_exprt(op[0], id, from_integer(0, op[0].type()));
27932796
code_branch.cond().add_source_location() = location;
27942797
code_branch.cond().add_source_location().set_function(method_id);
2795-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2798+
const method_offsett label_number = numeric_cast_v<method_offsett>(number);
2799+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
27962800
code_branch.then_case().add_source_location() =
2797-
address_map.at(integer2unsigned(number)).source->source_location;
2801+
address_map.at(label_number).source->source_location;
27982802
code_branch.then_case().add_source_location().set_function(method_id);
27992803
code_branch.add_source_location() = location;
28002804
code_branch.add_source_location().set_function(method_id);
@@ -2821,19 +2825,20 @@ codet java_bytecode_convert_methodt::convert_if_cmp(
28212825

28222826
code_branch.cond() = condition;
28232827
code_branch.cond().add_source_location() = location;
2824-
code_branch.then_case() = code_gotot(label(integer2string(number)));
2828+
const method_offsett label_number = numeric_cast_v<method_offsett>(number);
2829+
code_branch.then_case() = code_gotot(label(std::to_string(label_number)));
28252830
code_branch.then_case().add_source_location() =
2826-
address_map.at(integer2unsigned(number)).source->source_location;
2831+
address_map.at(label_number).source->source_location;
28272832
code_branch.add_source_location() = location;
28282833

28292834
return code_branch;
28302835
}
28312836

28322837
code_blockt java_bytecode_convert_methodt::convert_ret(
2833-
const std::vector<unsigned int> &jsr_ret_targets,
2838+
const std::vector<method_offsett> &jsr_ret_targets,
28342839
const exprt &arg0,
28352840
const source_locationt &location,
2836-
const unsigned address)
2841+
const method_offsett address)
28372842
{
28382843
code_blockt c;
28392844
auto retvar = variable(arg0, 'a', address, NO_CAST);
@@ -2885,7 +2890,7 @@ codet java_bytecode_convert_methodt::convert_store(
28852890
const irep_idt &statement,
28862891
const exprt &arg0,
28872892
const exprt::operandst &op,
2888-
const unsigned address,
2893+
const method_offsett address,
28892894
const source_locationt &location)
28902895
{
28912896
const exprt var = variable(arg0, statement[0], address, NO_CAST);
@@ -2974,7 +2979,7 @@ optionalt<exprt> java_bytecode_convert_methodt::convert_invoke_dynamic(
29742979

29752980
void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
29762981
java_bytecode_convert_methodt::address_mapt &address_map,
2977-
const std::vector<unsigned int> &jsr_ret_targets,
2982+
const std::vector<method_offsett> &jsr_ret_targets,
29782983
const std::vector<
29792984
std::vector<java_bytecode_parse_treet::instructiont>::const_iterator>
29802985
&ret_instructions) const
@@ -2988,12 +2993,13 @@ void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
29882993
}
29892994
}
29902995

2991-
std::vector<unsigned> java_bytecode_convert_methodt::try_catch_handler(
2992-
const unsigned int address,
2996+
std::vector<java_bytecode_convert_methodt::method_offsett>
2997+
java_bytecode_convert_methodt::try_catch_handler(
2998+
const method_offsett address,
29932999
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
29943000
const
29953001
{
2996-
std::vector<unsigned> result;
3002+
std::vector<method_offsett> result;
29973003
for(const auto &exception_row : exception_table)
29983004
{
29993005
if(address >= exception_row.start_pc && address < exception_row.end_pc)

0 commit comments

Comments
 (0)