Skip to content

Commit 5c2717a

Browse files
committed
Fix invokedynamic typing
1 parent c1a2f4d commit 5c2717a

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,30 @@ exprt::operandst &java_bytecode_convert_methodt::convert_const(
21202120
return results;
21212121
}
21222122

2123+
static void adjust_invoke_argument_types(
2124+
const java_method_typet::parameterst &parameters,
2125+
code_function_callt::argumentst &arguments)
2126+
{
2127+
// do some type adjustment for the arguments,
2128+
// as Java promotes arguments
2129+
// Also cast pointers since intermediate locals
2130+
// can be void*.
2131+
INVARIANT(
2132+
parameters.size() == arguments.size(),
2133+
"for each parameter there must be exactly one argument");
2134+
for(std::size_t i = 0; i < parameters.size(); i++)
2135+
{
2136+
const typet &type = parameters[i].type();
2137+
if(
2138+
type == java_boolean_type() || type == java_char_type() ||
2139+
type == java_byte_type() || type == java_short_type() ||
2140+
type.id() == ID_pointer)
2141+
{
2142+
arguments[i] = typecast_exprt::conditional_cast(arguments[i], type);
2143+
}
2144+
}
2145+
}
2146+
21232147
void java_bytecode_convert_methodt::convert_invoke(
21242148
source_locationt location,
21252149
const irep_idt &statement,
@@ -2197,24 +2221,7 @@ void java_bytecode_convert_methodt::convert_invoke(
21972221
!use_this || arguments.front().type().id() == ID_pointer,
21982222
"first argument must be a pointer");
21992223

2200-
// do some type adjustment for the arguments,
2201-
// as Java promotes arguments
2202-
// Also cast pointers since intermediate locals
2203-
// can be void*.
2204-
INVARIANT(
2205-
parameters.size() == arguments.size(),
2206-
"for each parameter there must be exactly one argument");
2207-
for(std::size_t i = 0; i < parameters.size(); i++)
2208-
{
2209-
const typet &type = parameters[i].type();
2210-
if(
2211-
type == java_boolean_type() || type == java_char_type() ||
2212-
type == java_byte_type() || type == java_short_type() ||
2213-
type.id() == ID_pointer)
2214-
{
2215-
arguments[i] = typecast_exprt::conditional_cast(arguments[i], type);
2216-
}
2217-
}
2224+
adjust_invoke_argument_types(parameters, arguments);
22182225

22192226
// do some type adjustment for return values
22202227
exprt lhs = nil_exprt();
@@ -3022,6 +3029,9 @@ optionalt<exprt> java_bytecode_convert_methodt::convert_invoke_dynamic(
30223029
// lambda_new.<init>(capture_1, capture_2, ...);
30233030
// Add the implicit 'this' parameter:
30243031
arguments.insert(arguments.begin(), new_instance);
3032+
adjust_invoke_argument_types(
3033+
to_code_type(constructor_symbol.type).parameters(), arguments);
3034+
30253035
code_function_callt constructor_call(
30263036
constructor_symbol.symbol_expr(), arguments);
30273037
constructor_call.add_source_location() = location;

0 commit comments

Comments
 (0)