Skip to content

Commit 84b3d4b

Browse files
Do not call assign_from_json if not in symbol_table
The assign_from_json will fail with an invariant failure if it is called on a method name that does not exist in the symbol table so we should be careful when calling it. This also make the function return early when the real clinit is not in the symbol table, which can avoid some unecessary computation.
1 parent bc75a6c commit 84b3d4b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,14 @@ code_blockt get_user_specified_clinit_body(
792792
&class_to_declared_symbols_map)
793793
{
794794
const irep_idt &real_clinit_name = clinit_function_name(class_id);
795+
const auto clinit_func = symbol_table.lookup(real_clinit_name);
796+
if(clinit_func == nullptr)
797+
{
798+
// Case where the real clinit doesn't appear in the symbol table, even
799+
// though their is user specifed one. This may occur when some class
800+
// substitution happened after compilation.
801+
return code_blockt{};
802+
}
795803
const auto class_entry =
796804
static_values_json.find(id2string(strip_java_namespace_prefix(class_id)));
797805
if(class_entry != static_values_json.end())
@@ -833,9 +841,7 @@ code_blockt get_user_specified_clinit_body(
833841
return body;
834842
}
835843
}
836-
if(const auto clinit_func = symbol_table.lookup(real_clinit_name))
837-
return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}};
838-
return code_blockt{};
844+
return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}};
839845
}
840846

841847
/// Create static initializer wrappers and possibly user-specified functions for

0 commit comments

Comments
 (0)