Skip to content

Commit cf26008

Browse files
committed
Discard LVT if bytecode > codet translation cannot make sense of it
1 parent 1e68ad2 commit cf26008

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/java_bytecode/java_local_variable_table.cpp

+26-8
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,12 @@ static void populate_predecessor_map(
289289
if(it->is_parameter)
290290
continue;
291291

292-
msg.debug() << "ppm: processing var idx " << it->var.index
292+
#ifdef DEBUG
293+
msg.debug() << "jcm: ppm: processing var idx " << it->var.index
293294
<< " name '" << it->var.name << "' start-pc "
294295
<< it->var.start_pc << " len " << it->var.length
295296
<< "; holes " << it->holes.size() << messaget::eom;
297+
#endif
296298

297299
// Find the last instruction within the live range:
298300
unsigned end_pc=it->var.start_pc+it->var.length;
@@ -362,11 +364,11 @@ static void populate_predecessor_map(
362364
*(inst_before_this->second.source),
363365
it->var.index))
364366
{
365-
msg.error() << "Local variable table: didn't find initializing "
366-
<< "store for predecessor of bytecode at address "
367-
<< amapit->first << " ("
368-
<< amapit->second.predecessors.size()
369-
<< " predecessors)" << msg.eom;
367+
msg.warning() << "Local variable table: didn't find initializing "
368+
<< "store for predecessor of bytecode at address "
369+
<< amapit->first << " ("
370+
<< amapit->second.predecessors.size()
371+
<< " predecessors)" << msg.eom;
370372
throw "local variable table: unexpected live ranges";
371373
}
372374
new_start_pc=pred;
@@ -720,8 +722,24 @@ void java_bytecode_convert_methodt::setup_local_variables(
720722
for(const auto &v : m.local_variable_table)
721723
vars_with_holes.push_back({v, is_parameter(v), {}});
722724

723-
// Merge variable records:
724-
find_initializers(vars_with_holes, amap, dominator_analysis);
725+
// Merge variable records. See documentation of in
726+
// `find_initializers_for_slot` for more details. If the strategy employed
727+
// there fails with an exception, we just ignore the LVT for this method, no
728+
// variable is generated in `this->variables[]` (because we return here and
729+
// dont let the for loop below to execute), and as a result the method
730+
// this->variable() will be forced to create new `anonlocal::` variables, as
731+
// the only source of variable names for that method is `this->variables[]`.
732+
try
733+
{
734+
find_initializers(vars_with_holes, amap, dominator_analysis);
735+
}
736+
catch(const char *message)
737+
{
738+
warning() << "Bytecode -> codet translation error: " << message << eom
739+
<< "This is probably due to an unexpected LVT, "
740+
<< "falling back to translation without LVT" << eom;
741+
return;
742+
}
725743

726744
// Clean up removed records from the variable table:
727745
cleanup_var_table(vars_with_holes);

0 commit comments

Comments
 (0)