Skip to content

Commit 517390e

Browse files
committed
Extend the usage of method_offsett
1 parent 247f81a commit 517390e

7 files changed

+60
-50
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ symbol_exprt java_bytecode_convert_methodt::tmp_variable(
196196
exprt java_bytecode_convert_methodt::variable(
197197
const exprt &arg,
198198
char type_char,
199-
size_t address)
199+
method_offsett address)
200200
{
201201
const std::size_t number_int =
202202
numeric_cast_v<std::size_t>(to_constant_expr(arg));
@@ -942,7 +942,7 @@ code_blockt &java_bytecode_convert_methodt::get_or_create_block_for_pcrange(
942942
}
943943

944944
static void gather_symbol_live_ranges(
945-
java_bytecode_convert_methodt::method_offsett pc,
945+
method_offsett pc,
946946
const exprt &e,
947947
std::map<irep_idt, java_bytecode_convert_methodt::variablet> &result)
948948
{
@@ -964,7 +964,8 @@ static void gather_symbol_live_ranges(
964964
}
965965
else
966966
{
967-
var.length=std::max(var.length, (pc-var.start_pc)+1);
967+
var.length = std::max(
968+
var.length, static_cast<method_offsett>((pc - var.start_pc) + 1));
968969
}
969970
}
970971
}
@@ -1136,7 +1137,8 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
11361137
// clang-format on
11371138
PRECONDITION(!i_it->args.empty());
11381139

1139-
auto target = numeric_cast_v<unsigned>(to_constant_expr(i_it->args[0]));
1140+
auto target =
1141+
numeric_cast_v<method_offsett>(to_constant_expr(i_it->args[0]));
11401142
targets.insert(target);
11411143

11421144
a_entry.first->second.successors.push_back(target);
@@ -1157,7 +1159,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
11571159
{
11581160
if(is_label)
11591161
{
1160-
auto target = numeric_cast_v<unsigned>(to_constant_expr(arg));
1162+
auto target = numeric_cast_v<method_offsett>(to_constant_expr(arg));
11611163
targets.insert(target);
11621164
a_entry.first->second.successors.push_back(target);
11631165
}
@@ -2001,7 +2003,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
20012003
root,
20022004
root_block,
20032005
v.start_pc,
2004-
v.start_pc + v.length,
2006+
static_cast<method_offsett>(v.start_pc + v.length),
20052007
std::numeric_limits<method_offsett>::max(),
20062008
address_map);
20072009
}
@@ -2017,7 +2019,7 @@ java_bytecode_convert_methodt::convert_instructions(const methodt &method)
20172019
root,
20182020
root_block,
20192021
v.start_pc,
2020-
v.start_pc + v.length,
2022+
static_cast<method_offsett>(v.start_pc + v.length),
20212023
std::numeric_limits<method_offsett>::max());
20222024
code_declt d(v.symbol_expr);
20232025
block.statements().insert(block.statements().begin(), d);
@@ -3172,7 +3174,7 @@ void java_bytecode_convert_methodt::draw_edges_from_ret_to_jsr(
31723174
}
31733175
}
31743176

3175-
std::vector<java_bytecode_convert_methodt::method_offsett>
3177+
std::vector<method_offsett>
31763178
java_bytecode_convert_methodt::try_catch_handler(
31773179
const method_offsett address,
31783180
const java_bytecode_parse_treet::methodt::exception_tablet &exception_table)
@@ -3211,7 +3213,7 @@ void java_bytecode_initialize_parameter_names(
32113213
java_method_typet::parameterst &parameters = method_type.parameters();
32123214

32133215
// Find number of parameters
3214-
unsigned slots_for_parameters = java_method_parameter_slots(method_type);
3216+
auto slots_for_parameters = java_method_parameter_slots(method_type);
32153217

32163218
// Find parameter names in the local variable table:
32173219
typedef std::pair<irep_idt, irep_idt> base_name_and_identifiert;

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_METHOD_CLASS_H
1414

1515
#include "java_bytecode_convert_class.h"
16+
#include "java_utils.h"
1617

1718
#include <util/expanding_vector.h>
1819
#include <util/message.h>
@@ -74,8 +75,6 @@ class java_bytecode_convert_methodt
7475
convert(class_symbol, method, method_context);
7576
}
7677

77-
typedef uint16_t method_offsett;
78-
7978
protected:
8079
messaget log;
8180
symbol_table_baset &symbol_table;
@@ -126,8 +125,8 @@ class java_bytecode_convert_methodt
126125
{
127126
public:
128127
symbol_exprt symbol_expr;
129-
size_t start_pc;
130-
size_t length;
128+
method_offsett start_pc;
129+
method_offsett length;
131130
bool is_parameter = false;
132131
std::vector<holet> holes;
133132

@@ -183,7 +182,7 @@ class java_bytecode_convert_methodt
183182

184183
// return corresponding reference of variable
185184
const variablet &find_variable_for_slot(
186-
size_t address,
185+
method_offsett address,
187186
variablest &var_list);
188187

189188
// JVM local variables
@@ -193,7 +192,7 @@ class java_bytecode_convert_methodt
193192
NO_CAST
194193
};
195194

196-
exprt variable(const exprt &arg, char type_char, size_t address);
195+
exprt variable(const exprt &arg, char type_char, method_offsett address);
197196

198197
// temporary variables
199198
std::list<symbol_exprt> tmp_vars;

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Author: Daniel Kroening, [email protected]
1919
#include <map>
2020
#include <set>
2121

22+
typedef uint16_t method_offsett;
23+
2224
struct java_bytecode_parse_treet
2325
{
2426
// Disallow copy construction and copy assignment, but allow move construction
@@ -55,7 +57,7 @@ struct java_bytecode_parse_treet
5557
struct instructiont
5658
{
5759
source_locationt source_location;
58-
unsigned address;
60+
method_offsett address;
5961
u8 bytecode;
6062
typedef std::vector<exprt> argst;
6163
argst args;
@@ -112,9 +114,9 @@ struct java_bytecode_parse_treet
112114
{
113115
}
114116

115-
std::size_t start_pc;
116-
std::size_t end_pc;
117-
std::size_t handler_pc;
117+
method_offsett start_pc;
118+
method_offsett end_pc;
119+
method_offsett handler_pc;
118120
struct_tag_typet catch_type;
119121
};
120122

@@ -128,9 +130,9 @@ struct java_bytecode_parse_treet
128130
irep_idt name;
129131
std::string descriptor;
130132
std::optional<std::string> signature;
131-
std::size_t index;
132-
std::size_t start_pc;
133-
std::size_t length;
133+
method_offsett index;
134+
method_offsett start_pc;
135+
method_offsett length;
134136
};
135137

136138
typedef std::vector<local_variablet> local_variable_tablet;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ void java_bytecode_parsert::rbytecode(std::vector<instructiont> &instructions)
923923
instructions.emplace_back();
924924
instructiont &instruction=instructions.back();
925925
instruction.bytecode = bytecode;
926-
instruction.address=start_of_instruction;
926+
instruction.address=static_cast<method_offsett>(start_of_instruction);
927927
instruction.source_location
928928
.set_java_bytecode_index(std::to_string(bytecode_index));
929929

@@ -1604,7 +1604,7 @@ void java_bytecode_parsert::rinner_classes_attribute(
16041604
classt &parsed_class = parse_tree.parsed_class;
16051605
std::string name = parsed_class.name.c_str();
16061606
const u2 number_of_classes = read<u2>();
1607-
const u4 number_of_bytes_to_be_read = number_of_classes * 8 + 2;
1607+
const u4 number_of_bytes_to_be_read = static_cast<u4>(number_of_classes * 8 + 2);
16081608
INVARIANT(
16091609
number_of_bytes_to_be_read == attribute_length,
16101610
"The number of bytes to be read for the InnerClasses attribute does not "

jbmc/src/java_bytecode/java_local_variable_table.cpp

+28-22
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ template <class T>
2727
struct procedure_local_cfg_baset<
2828
T,
2929
java_bytecode_convert_methodt::method_with_amapt,
30-
java_bytecode_convert_methodt::method_offsett>
30+
method_offsett>
3131
: public grapht<
32-
cfg_base_nodet<T, java_bytecode_convert_methodt::method_offsett>>
32+
cfg_base_nodet<T, method_offsett>>
3333
{
3434
typedef grapht<
3535
cfg_base_nodet<T, java_bytecode_convert_methodt::method_offsett>>
@@ -51,7 +51,7 @@ struct procedure_local_cfg_baset<
5151
for(const auto &inst : amap)
5252
{
5353
// Map instruction PCs onto node indices:
54-
entry_map[inst.first]=this->add_node();
54+
entry_map[inst.first] = static_cast<method_offsett>(this->add_node());
5555
// Map back:
5656
(*this)[entry_map[inst.first]].PC=inst.first;
5757
}
@@ -238,14 +238,13 @@ static bool is_store_to_slot(
238238
/// \param [out] var: A hole is added to `var`, unless it would be of zero size
239239
static void maybe_add_hole(
240240
local_variable_with_holest &var,
241-
java_bytecode_convert_methodt::method_offsett from,
242-
java_bytecode_convert_methodt::method_offsett to)
241+
method_offsett from,
242+
method_offsett to)
243243
{
244244
PRECONDITION(to>=from);
245245
if(to!=from)
246246
var.holes.push_back(
247-
{from,
248-
static_cast<java_bytecode_convert_methodt::method_offsett>(to - from)});
247+
{from, static_cast<method_offsett>(to - from)});
249248
}
250249

251250
/// See above
@@ -262,10 +261,17 @@ static void populate_variable_address_map(
262261
{
263262
for(auto it=firstvar, itend=varlimit; it!=itend; ++it)
264263
{
265-
if(it->var.start_pc+it->var.length>live_variable_at_address.size())
266-
live_variable_at_address.resize(it->var.start_pc+it->var.length);
264+
if(
265+
static_cast<std::size_t>(it->var.start_pc + it->var.length) >
266+
live_variable_at_address.size())
267+
{
268+
live_variable_at_address.resize(
269+
static_cast<std::size_t>(it->var.start_pc + it->var.length));
270+
}
267271

268-
for(auto idx = it->var.start_pc, idxlim = it->var.start_pc + it->var.length;
272+
for(method_offsett idx = it->var.start_pc,
273+
idxlim = static_cast<method_offsett>(
274+
it->var.start_pc + it->var.length);
269275
idx != idxlim;
270276
++idx)
271277
{
@@ -332,7 +338,8 @@ static void populate_predecessor_map(
332338
#endif
333339

334340
// Find the last instruction within the live range:
335-
const auto end_pc = it->var.start_pc + it->var.length;
341+
const auto end_pc =
342+
static_cast<method_offsett>(it->var.start_pc + it->var.length);
336343
auto amapit=amap.find(end_pc);
337344
INVARIANT(
338345
amapit!=amap.begin(),
@@ -445,22 +452,20 @@ static void populate_predecessor_map(
445452
/// \return Returns the bytecode address of the closest common dominator of all
446453
/// given variable table entries. In the worst case the function entry point
447454
/// should always satisfy this criterion.
448-
static java_bytecode_convert_methodt::method_offsett get_common_dominator(
455+
static method_offsett get_common_dominator(
449456
const std::set<local_variable_with_holest *> &merge_vars,
450457
const java_cfg_dominatorst &dominator_analysis)
451458
{
452459
PRECONDITION(!merge_vars.empty());
453460

454-
auto first_pc =
455-
std::numeric_limits<java_bytecode_convert_methodt::method_offsett>::max();
461+
auto first_pc = std::numeric_limits<method_offsett>::max();
456462
for(auto v : merge_vars)
457463
{
458464
if(v->var.start_pc<first_pc)
459465
first_pc=v->var.start_pc;
460466
}
461467

462-
std::vector<java_bytecode_convert_methodt::method_offsett>
463-
candidate_dominators;
468+
std::vector<method_offsett> candidate_dominators;
464469
for(auto v : merge_vars)
465470
{
466471
const auto &dominator_nodeidx=
@@ -507,7 +512,7 @@ static java_bytecode_convert_methodt::method_offsett get_common_dominator(
507512
static void populate_live_range_holes(
508513
local_variable_with_holest &merge_into,
509514
const std::set<local_variable_with_holest *> &merge_vars,
510-
java_bytecode_convert_methodt::method_offsett expanded_live_range_start)
515+
method_offsett expanded_live_range_start)
511516
{
512517
std::vector<local_variable_with_holest *> sorted_by_startpc(
513518
merge_vars.begin(), merge_vars.end());
@@ -555,16 +560,17 @@ static void merge_variable_table_entries(
555560
// as it was not visible in the original local variable table)
556561
populate_live_range_holes(merge_into, merge_vars, found_dominator);
557562

558-
java_bytecode_convert_methodt::method_offsett last_pc = 0;
563+
method_offsett last_pc = 0;
559564
for(auto v : merge_vars)
560565
{
561-
if(v->var.start_pc+v->var.length>last_pc)
562-
last_pc=v->var.start_pc+v->var.length;
566+
if(static_cast<method_offsett>(v->var.start_pc + v->var.length) > last_pc)
567+
last_pc = static_cast<method_offsett>(v->var.start_pc + v->var.length);
563568
}
564569

565570
// Apply the changes:
566571
merge_into.var.start_pc=found_dominator;
567-
merge_into.var.length=last_pc-found_dominator;
572+
merge_into.var.length =
573+
static_cast<method_offsett>(last_pc - found_dominator);
568574

569575
#ifdef DEBUG
570576
debug_out << "Merged " << merge_vars.size() << " variables named "
@@ -850,7 +856,7 @@ void java_bytecode_convert_methodt::setup_local_variables(
850856
/// nothing covers `address`.
851857
const java_bytecode_convert_methodt::variablet &
852858
java_bytecode_convert_methodt::find_variable_for_slot(
853-
size_t address,
859+
method_offsett address,
854860
variablest &var_list)
855861
{
856862
for(const variablet &var : var_list)

jbmc/src/java_bytecode/java_utils.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,13 @@ unsigned java_local_variable_slots(const typet &t)
144144
return bitwidth == 64 ? 2u : 1u;
145145
}
146146

147-
unsigned java_method_parameter_slots(const java_method_typet &t)
147+
method_offsett java_method_parameter_slots(const java_method_typet &t)
148148
{
149-
unsigned slots=0;
149+
method_offsett slots = 0;
150150

151151
for(const auto &p : t.parameters())
152-
slots+=java_local_variable_slots(p.type());
152+
slots =
153+
static_cast<method_offsett>(slots + java_local_variable_slots(p.type()));
153154

154155
return slots;
155156
}

jbmc/src/java_bytecode/java_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ unsigned java_local_variable_slots(const typet &t);
8383

8484
/// Returns the the number of JVM local variables (slots) used by the JVM to
8585
/// pass, upon call, the arguments of a Java method whose type is \p t.
86-
unsigned java_method_parameter_slots(const java_method_typet &t);
86+
method_offsett java_method_parameter_slots(const java_method_typet &t);
8787

8888
const std::string java_class_to_package(const std::string &canonical_classname);
8989

0 commit comments

Comments
 (0)