Skip to content

Commit 87c6b28

Browse files
Don't erase symbol in java_bytecode_convert_methodt::convert
The symbolt was erased and recreated rather than being modified. This was bad as it invalidated the reference to the symbol that we now use later.
1 parent e3e44c8 commit 87c6b28

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ void java_bytecode_convert_methodt::convert(
382382
id2string(class_symbol.name)+"."+id2string(m.name)+":"+m.descriptor;
383383
method_id=method_identifier;
384384

385-
const symbolt &old_sym=*symbol_table.lookup(method_identifier);
385+
symbolt &method_symbol=*symbol_table.get_writeable(method_identifier);
386386

387387
// Obtain a std::vector of code_typet::parametert objects from the
388388
// (function) type of the symbol
389-
typet member_type=old_sym.type;
389+
typet member_type=method_symbol.type;
390390
code_typet &code_type=to_code_type(member_type);
391391
method_return_type=code_type.return_type();
392392
code_typet::parameterst &parameters=code_type.parameters();
@@ -527,10 +527,17 @@ void java_bytecode_convert_methodt::convert(
527527
if(is_constructor(method))
528528
method.set(ID_constructor, true);
529529

530-
// we add the symbol for the method
531-
symbolt method_symbol;
532-
method_symbol.name=method.get_name();
533-
method_symbol.base_name=method.get_base_name();
530+
// Check the fields that can't change are valid
531+
INVARIANT(
532+
method_symbol.name==method.get_name(),
533+
"Name of method symbol shouldn't change");
534+
INVARIANT(
535+
method_symbol.base_name==method.get_base_name(),
536+
"Base name of method symbol shouldn't change");
537+
INVARIANT(
538+
method_symbol.module.empty(),
539+
"Method symbol shouldn't have module");
540+
// Update the symbol for the method
534541
method_symbol.mode=ID_java;
535542
method_symbol.location=m.source_location;
536543
method_symbol.location.set_function(method_identifier);
@@ -554,16 +561,6 @@ void java_bytecode_convert_methodt::convert(
554561
method_has_this=code_type.has_this();
555562
if((!m.is_abstract) && (!m.is_native))
556563
method_symbol.value=convert_instructions(m, code_type, method_symbol.name);
557-
558-
// Replace the existing stub symbol with the real deal:
559-
const auto s_it=symbol_table.symbols.find(method.get_name());
560-
INVARIANT(
561-
s_it!=symbol_table.symbols.end(),
562-
"the symbol was there earlier on this function; it must be there now");
563-
symbol_table.erase(s_it);
564-
565-
// Insert the method symbol in the symbol table
566-
symbol_table.add(method_symbol);
567564
}
568565

569566
const bytecode_infot &java_bytecode_convert_methodt::get_bytecode_info(

0 commit comments

Comments
 (0)