Skip to content

Avoid default constructing code_function_callt [blocks: #3800, #3938] #3933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions jbmc/src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2150,25 +2150,22 @@ void java_bytecode_convert_methodt::convert_invoke(
}
}

code_function_callt call;
location.set_function(method_id);

call.add_source_location() = location;
call.arguments() = pop(parameters.size());
code_function_callt::argumentst arguments = pop(parameters.size());

// double-check a bit
if(use_this)
{
const exprt &this_arg = call.arguments().front();
INVARIANT(
this_arg.type().id() == ID_pointer, "first argument must be a pointer");
}
INVARIANT(
!use_this || arguments.front().type().id() == ID_pointer,
"first argument must be a pointer");

// do some type adjustment for the arguments,
// as Java promotes arguments
// Also cast pointers since intermediate locals
// can be void*.

INVARIANT(
parameters.size() == arguments.size(),
"for each parameter there must be exactly one argument");
for(std::size_t i = 0; i < parameters.size(); i++)
{
const typet &type = parameters[i].type();
Expand All @@ -2177,21 +2174,20 @@ void java_bytecode_convert_methodt::convert_invoke(
type == java_byte_type() || type == java_short_type() ||
type.id() == ID_pointer)
{
assert(i < call.arguments().size());
if(type != call.arguments()[i].type())
call.arguments()[i].make_typecast(type);
if(type != arguments[i].type())
arguments[i].make_typecast(type);
}
}

// do some type adjustment for return values

exprt lhs = nil_exprt();
const typet &return_type = method_type.return_type();

if(return_type.id() != ID_empty)
{
// return types are promoted in Java
call.lhs() = tmp_variable("return", return_type);
exprt promoted = java_bytecode_promotion(call.lhs());
lhs = tmp_variable("return", return_type);
exprt promoted = java_bytecode_promotion(lhs);
results.resize(1);
results[0] = promoted;
}
Expand Down Expand Up @@ -2233,19 +2229,20 @@ void java_bytecode_convert_methodt::convert_invoke(
symbol_table.add(symbol);
}

exprt function;
if(is_virtual)
{
// dynamic binding
assert(use_this);
assert(!call.arguments().empty());
call.function() = arg0;
PRECONDITION(use_this);
PRECONDITION(!arguments.empty());
function = arg0;
// Populate needed methods later,
// once we know what object types can exist.
}
else
{
// static binding
call.function() = symbol_exprt(invoked_method_id, method_type);
function = symbol_exprt(invoked_method_id, method_type);
if(needed_lazy_methods)
{
needed_lazy_methods->add_needed_method(invoked_method_id);
Expand All @@ -2254,6 +2251,9 @@ void java_bytecode_convert_methodt::convert_invoke(
}
}

code_function_callt call(
std::move(lhs), std::move(function), std::move(arguments));
call.add_source_location() = location;
call.function().add_source_location() = location;

// Replacing call if it is a function of the Character library,
Expand Down
3 changes: 2 additions & 1 deletion src/goto-analyzer/taint_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ bool taint_analysist::operator()(
if(f_it->second.body_available() &&
f_it->first!=goto_functionst::entry_point())
{
const symbolt &symbol = ns.lookup(f_it->first);
goto_programt::targett t=calls.add_instruction();
const code_function_callt call(ns.lookup(f_it->first).symbol_expr());
const code_function_callt call(symbol.symbol_expr());
t->make_function_call(call);
calls.add_instruction()->make_goto(end.instructions.begin());
goto_programt::targett g=gotos.add_instruction();
Expand Down
9 changes: 4 additions & 5 deletions src/goto-programs/remove_asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ void remove_asmt::gcc_asm_function_call(
{
irep_idt function_identifier=function_base_name;

code_function_callt function_call;
function_call.lhs().make_nil();
code_function_callt::argumentst arguments;

const typet void_pointer=
pointer_type(void_typet());
Expand All @@ -87,7 +86,7 @@ void remove_asmt::gcc_asm_function_call(
{
if(it->operands().size()==2)
{
function_call.arguments().push_back(
arguments.push_back(
typecast_exprt(address_of_exprt(it->op1()), void_pointer));
}
}
Expand All @@ -97,7 +96,7 @@ void remove_asmt::gcc_asm_function_call(
{
if(it->operands().size()==2)
{
function_call.arguments().push_back(
arguments.push_back(
typecast_exprt(address_of_exprt(it->op1()), void_pointer));
}
}
Expand All @@ -107,7 +106,7 @@ void remove_asmt::gcc_asm_function_call(

symbol_exprt fkt(function_identifier, fkt_type);

function_call.function()=fkt;
code_function_callt function_call(std::move(fkt), std::move(arguments));

goto_programt::targett call=dest.add_instruction(FUNCTION_CALL);
call->code=function_call;
Expand Down
4 changes: 1 addition & 3 deletions unit/analyses/ai/ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ class instruction_counter_analysist : public ait<instruction_counter_domaint>

static code_function_callt make_void_call(const symbol_exprt &function)
{
code_function_callt ret;
ret.function() = function;
return ret;
return code_function_callt(function, {});
}

SCENARIO(
Expand Down