Skip to content

Commit 7dd720b

Browse files
authored
Merge pull request #4502 from tautschnig/parameter-names
Ensure Java stubbing names parameters [blocks: #4485]
2 parents 607df45 + de4c581 commit 7dd720b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

jbmc/src/java_bytecode/simple_method_stubbing.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,29 @@ void java_simple_method_stubst::create_method_stub_at(
148148
void java_simple_method_stubst::create_method_stub(symbolt &symbol)
149149
{
150150
code_blockt new_instructions;
151-
const java_method_typet &required_type = to_java_method_type(symbol.type);
151+
java_method_typet &required_type = to_java_method_type(symbol.type);
152152

153153
// synthetic source location that contains the opaque function name only
154154
source_locationt synthesized_source_location;
155155
synthesized_source_location.set_function(symbol.name);
156156

157+
// make sure all parameters are named
158+
for(auto &parameter : required_type.parameters())
159+
{
160+
if(parameter.get_identifier().empty())
161+
{
162+
symbolt &parameter_symbol = fresh_java_symbol(
163+
parameter.type(),
164+
"#anon",
165+
synthesized_source_location,
166+
symbol.name,
167+
symbol_table);
168+
parameter_symbol.is_parameter = true;
169+
parameter.set_base_name(parameter_symbol.base_name);
170+
parameter.set_identifier(parameter_symbol.name);
171+
}
172+
}
173+
157174
// Initialize the return value or `this` parameter under construction.
158175
// Note symbol.type is required_type, but with write access
159176
// Probably required_type should not be const

src/goto-programs/goto_convert_functions.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ void goto_convert_functionst::convert_function(
159159
symbol.is_compiled()) /* goto_inline may have removed the body */
160160
return;
161161

162+
// we have a body, make sure all parameter names are valid
163+
for(const auto &p : f.parameter_identifiers)
164+
{
165+
DATA_INVARIANT(!p.empty(), "parameter identifier should not be empty");
166+
DATA_INVARIANT(
167+
symbol_table.has_symbol(p),
168+
"parameter identifier must be a known symbol");
169+
}
170+
162171
lifetimet parent_lifetime = lifetime;
163172
lifetime = identifier == INITIALIZE_FUNCTION ? lifetimet::STATIC_GLOBAL
164173
: lifetimet::AUTOMATIC_LOCAL;

0 commit comments

Comments
 (0)