From de4c581c9445c4f07f2bf62a7821545ab1cb3d67 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Mon, 8 Apr 2019 15:41:07 +0000 Subject: [PATCH] Ensure Java stubbing names parameters For functions with a body we require that parameters are named so that we can generate assignments to them (even when the body may not read the value). Also guard against future regressions by sanity checking parameter names for any converted function. --- .../java_bytecode/simple_method_stubbing.cpp | 19 ++++++++++++++++++- src/goto-programs/goto_convert_functions.cpp | 9 +++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/jbmc/src/java_bytecode/simple_method_stubbing.cpp b/jbmc/src/java_bytecode/simple_method_stubbing.cpp index 9a1866bedf5..7ce819fbbbc 100644 --- a/jbmc/src/java_bytecode/simple_method_stubbing.cpp +++ b/jbmc/src/java_bytecode/simple_method_stubbing.cpp @@ -148,12 +148,29 @@ void java_simple_method_stubst::create_method_stub_at( void java_simple_method_stubst::create_method_stub(symbolt &symbol) { code_blockt new_instructions; - const java_method_typet &required_type = to_java_method_type(symbol.type); + java_method_typet &required_type = to_java_method_type(symbol.type); // synthetic source location that contains the opaque function name only source_locationt synthesized_source_location; synthesized_source_location.set_function(symbol.name); + // make sure all parameters are named + for(auto ¶meter : required_type.parameters()) + { + if(parameter.get_identifier().empty()) + { + symbolt ¶meter_symbol = fresh_java_symbol( + parameter.type(), + "#anon", + synthesized_source_location, + symbol.name, + symbol_table); + parameter_symbol.is_parameter = true; + parameter.set_base_name(parameter_symbol.base_name); + parameter.set_identifier(parameter_symbol.name); + } + } + // Initialize the return value or `this` parameter under construction. // Note symbol.type is required_type, but with write access // Probably required_type should not be const diff --git a/src/goto-programs/goto_convert_functions.cpp b/src/goto-programs/goto_convert_functions.cpp index 24f515685e5..146e4f5a0e2 100644 --- a/src/goto-programs/goto_convert_functions.cpp +++ b/src/goto-programs/goto_convert_functions.cpp @@ -159,6 +159,15 @@ void goto_convert_functionst::convert_function( symbol.is_compiled()) /* goto_inline may have removed the body */ return; + // we have a body, make sure all parameter names are valid + for(const auto &p : f.parameter_identifiers) + { + DATA_INVARIANT(!p.empty(), "parameter identifier should not be empty"); + DATA_INVARIANT( + symbol_table.has_symbol(p), + "parameter identifier must be a known symbol"); + } + lifetimet parent_lifetime = lifetime; lifetime = identifier == INITIALIZE_FUNCTION ? lifetimet::STATIC_GLOBAL : lifetimet::AUTOMATIC_LOCAL;