Skip to content

Commit 65af30b

Browse files
committed
Avoid default constructing code_function_callt
Construct them bottom-up, which is more efficient and type safe.
1 parent ab81ffc commit 65af30b

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,25 +2150,22 @@ void java_bytecode_convert_methodt::convert_invoke(
21502150
}
21512151
}
21522152

2153-
code_function_callt call;
21542153
location.set_function(method_id);
21552154

2156-
call.add_source_location() = location;
2157-
call.arguments() = pop(parameters.size());
2155+
code_function_callt::argumentst arguments = pop(parameters.size());
21582156

21592157
// double-check a bit
2160-
if(use_this)
2161-
{
2162-
const exprt &this_arg = call.arguments().front();
2163-
INVARIANT(
2164-
this_arg.type().id() == ID_pointer, "first argument must be a pointer");
2165-
}
2158+
INVARIANT(
2159+
!use_this || arguments.front().type().id() == ID_pointer,
2160+
"first argument must be a pointer");
21662161

21672162
// do some type adjustment for the arguments,
21682163
// as Java promotes arguments
21692164
// Also cast pointers since intermediate locals
21702165
// can be void*.
2171-
2166+
INVARIANT(
2167+
parameters.size() <= arguments.size(),
2168+
"for each parameter there must be an argument");
21722169
for(std::size_t i = 0; i < parameters.size(); i++)
21732170
{
21742171
const typet &type = parameters[i].type();
@@ -2177,21 +2174,20 @@ void java_bytecode_convert_methodt::convert_invoke(
21772174
type == java_byte_type() || type == java_short_type() ||
21782175
type.id() == ID_pointer)
21792176
{
2180-
assert(i < call.arguments().size());
2181-
if(type != call.arguments()[i].type())
2182-
call.arguments()[i].make_typecast(type);
2177+
if(type != arguments[i].type())
2178+
arguments[i].make_typecast(type);
21832179
}
21842180
}
21852181

21862182
// do some type adjustment for return values
2187-
2183+
exprt lhs = nil_exprt();
21882184
const typet &return_type = method_type.return_type();
21892185

21902186
if(return_type.id() != ID_empty)
21912187
{
21922188
// return types are promoted in Java
2193-
call.lhs() = tmp_variable("return", return_type);
2194-
exprt promoted = java_bytecode_promotion(call.lhs());
2189+
lhs = tmp_variable("return", return_type);
2190+
exprt promoted = java_bytecode_promotion(lhs);
21952191
results.resize(1);
21962192
results[0] = promoted;
21972193
}
@@ -2233,19 +2229,20 @@ void java_bytecode_convert_methodt::convert_invoke(
22332229
symbol_table.add(symbol);
22342230
}
22352231

2232+
exprt function;
22362233
if(is_virtual)
22372234
{
22382235
// dynamic binding
2239-
assert(use_this);
2240-
assert(!call.arguments().empty());
2241-
call.function() = arg0;
2236+
PRECONDITION(use_this);
2237+
PRECONDITION(!arguments.empty());
2238+
function = arg0;
22422239
// Populate needed methods later,
22432240
// once we know what object types can exist.
22442241
}
22452242
else
22462243
{
22472244
// static binding
2248-
call.function() = symbol_exprt(invoked_method_id, method_type);
2245+
function = symbol_exprt(invoked_method_id, method_type);
22492246
if(needed_lazy_methods)
22502247
{
22512248
needed_lazy_methods->add_needed_method(invoked_method_id);
@@ -2254,6 +2251,9 @@ void java_bytecode_convert_methodt::convert_invoke(
22542251
}
22552252
}
22562253

2254+
code_function_callt call(
2255+
std::move(lhs), std::move(function), std::move(arguments));
2256+
call.add_source_location() = location;
22572257
call.function().add_source_location() = location;
22582258

22592259
// Replacing call if it is a function of the Character library,

src/goto-analyzer/taint_analysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ bool taint_analysist::operator()(
284284
if(f_it->second.body_available() &&
285285
f_it->first!=goto_functionst::entry_point())
286286
{
287+
const symbolt &symbol = ns.lookup(f_it->first);
287288
goto_programt::targett t=calls.add_instruction();
288-
const code_function_callt call(ns.lookup(f_it->first).symbol_expr());
289+
const code_function_callt call(symbol.symbol_expr());
289290
t->make_function_call(call);
290291
calls.add_instruction()->make_goto(end.instructions.begin());
291292
goto_programt::targett g=gotos.add_instruction();

src/goto-programs/remove_asm.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void remove_asmt::gcc_asm_function_call(
7676
{
7777
irep_idt function_identifier=function_base_name;
7878

79-
code_function_callt function_call;
80-
function_call.lhs().make_nil();
79+
code_function_callt::argumentst arguments;
8180

8281
const typet void_pointer=
8382
pointer_type(void_typet());
@@ -87,7 +86,7 @@ void remove_asmt::gcc_asm_function_call(
8786
{
8887
if(it->operands().size()==2)
8988
{
90-
function_call.arguments().push_back(
89+
arguments.push_back(
9190
typecast_exprt(address_of_exprt(it->op1()), void_pointer));
9291
}
9392
}
@@ -97,7 +96,7 @@ void remove_asmt::gcc_asm_function_call(
9796
{
9897
if(it->operands().size()==2)
9998
{
100-
function_call.arguments().push_back(
99+
arguments.push_back(
101100
typecast_exprt(address_of_exprt(it->op1()), void_pointer));
102101
}
103102
}
@@ -107,7 +106,7 @@ void remove_asmt::gcc_asm_function_call(
107106

108107
symbol_exprt fkt(function_identifier, fkt_type);
109108

110-
function_call.function()=fkt;
109+
code_function_callt function_call(std::move(fkt), std::move(arguments));
111110

112111
goto_programt::targett call=dest.add_instruction(FUNCTION_CALL);
113112
call->code=function_call;

unit/analyses/ai/ai.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ class instruction_counter_analysist : public ait<instruction_counter_domaint>
111111

112112
static code_function_callt make_void_call(const symbol_exprt &function)
113113
{
114-
code_function_callt ret;
115-
ret.function() = function;
116-
return ret;
114+
return code_function_callt(function, {});
117115
}
118116

119117
SCENARIO(

0 commit comments

Comments
 (0)