Skip to content

Commit cfeade5

Browse files
committed
Fix the this argument used when checking a constructor
The `this` argument used for a constructor should be a reference to zero initialized memory, rather than nondet initialised.
1 parent d263955 commit cfeade5

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
297297
const select_pointer_typet &pointer_type_selector,
298298
message_handlert &message_handler)
299299
{
300-
const java_method_typet::parameterst &parameters =
301-
to_java_method_type(function.type).parameters();
300+
const java_method_typet &function_type = to_java_method_type(function.type);
301+
const java_method_typet::parameterst &parameters = function_type.parameters();
302302

303303
code_blockt init_code;
304304
exprt::operandst main_arguments;
@@ -324,6 +324,22 @@ std::pair<code_blockt, std::vector<exprt>> java_build_arguments(
324324
// be null
325325
bool is_this=(param_number==0) && parameters[param_number].get_this();
326326

327+
if(is_this && function_type.get_is_constructor())
328+
{
329+
const symbol_exprt result = fresh_java_symbol(
330+
p.type(),
331+
"this_parameter",
332+
function.location,
333+
function.name,
334+
symbol_table)
335+
.symbol_expr();
336+
main_arguments[param_number] = result;
337+
init_code.add(code_declt{result});
338+
init_code.add(
339+
code_assignt{result, side_effect_exprt(ID_java_new, p.type())});
340+
continue;
341+
}
342+
327343
java_object_factory_parameterst factory_parameters =
328344
object_factory_parameters;
329345
// only pointer must be non-null

0 commit comments

Comments
 (0)