Skip to content

Commit 2ec3300

Browse files
committed
Use goto_functiont::parameter_identifiers and remove goto_functiont::type
Having two function type definitions (one in the symbol table and one in goto_functiont) is just prone to become inconsistent. Instead, always look at the symbol table when we do need type information. If all we care about are the identifiers we can still use goto_functiont::parameter_identifiers.
1 parent 875a634 commit 2ec3300

21 files changed

+90
-255
lines changed

src/assembler/remove_asm.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ void remove_asmt::gcc_asm_function_call(
122122
symbol.mode = ID_C;
123123

124124
symbol_table.add(symbol);
125-
}
126125

127-
if(
128-
goto_functions.function_map.find(function_identifier) ==
129-
goto_functions.function_map.end())
126+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
127+
}
128+
else
130129
{
131-
auto &f = goto_functions.function_map[function_identifier];
132-
f.type = fkt_type;
130+
DATA_INVARIANT(
131+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
132+
"function types should match");
133133
}
134134
}
135135

@@ -171,14 +171,14 @@ void remove_asmt::msc_asm_function_call(
171171
symbol.mode = ID_C;
172172

173173
symbol_table.add(symbol);
174-
}
175174

176-
if(
177-
goto_functions.function_map.find(function_identifier) ==
178-
goto_functions.function_map.end())
175+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
176+
}
177+
else
179178
{
180-
auto &f = goto_functions.function_map[function_identifier];
181-
f.type = fkt_type;
179+
DATA_INVARIANT(
180+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
181+
"function types should match");
182182
}
183183
}
184184

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ void function_call_harness_generatort::implt::
253253

254254
auto const &generated_harness =
255255
symbol_table->lookup_ref(harness_function_name);
256-
goto_functions->function_map[harness_function_name].type =
257-
to_code_type(generated_harness.type);
258256
auto &body = goto_functions->function_map[harness_function_name].body;
259257
goto_convert(
260258
static_cast<const codet &>(generated_harness.value),

src/goto-instrument/code_contracts.cpp

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,13 @@ void code_contractst::add_contract_check(
266266
{
267267
assert(!dest.instructions.empty());
268268

269-
goto_functionst::function_mapt::iterator f_it=
270-
goto_functions.function_map.find(function);
271-
assert(f_it!=goto_functions.function_map.end());
272-
273-
const goto_functionst::goto_functiont &gf=f_it->second;
269+
const symbolt &function_symbol = ns.lookup(function);
270+
const code_typet &code_type = to_code_type(function_symbol.type);
274271

275-
const exprt &requires=
276-
static_cast<const exprt&>(gf.type.find(ID_C_spec_requires));
277-
const exprt &ensures=
278-
static_cast<const exprt&>(gf.type.find(ID_C_spec_ensures));
272+
const exprt &requires =
273+
static_cast<const exprt &>(code_type.find(ID_C_spec_requires));
274+
const exprt &ensures =
275+
static_cast<const exprt &>(code_type.find(ID_C_spec_ensures));
279276
assert(ensures.is_not_nil());
280277

281278
// build:
@@ -302,15 +299,14 @@ void code_contractst::add_contract_check(
302299
skip->source_location));
303300

304301
// prepare function call including all declarations
305-
const symbolt &function_symbol = ns.lookup(function);
306302
code_function_callt call(function_symbol.symbol_expr());
307303
replace_symbolt replace;
308304

309305
// decl ret
310-
if(gf.type.return_type()!=empty_typet())
306+
if(code_type.return_type() != empty_typet())
311307
{
312308
symbol_exprt r = new_tmp_symbol(
313-
gf.type.return_type(),
309+
code_type.return_type(),
314310
skip->source_location,
315311
function,
316312
function_symbol.mode)
@@ -324,22 +320,19 @@ void code_contractst::add_contract_check(
324320
}
325321

326322
// decl parameter1 ...
327-
for(code_typet::parameterst::const_iterator
328-
p_it=gf.type.parameters().begin();
329-
p_it!=gf.type.parameters().end();
330-
++p_it)
323+
for(const auto &parameter : code_type.parameters())
331324
{
332325
symbol_exprt p =
333326
new_tmp_symbol(
334-
p_it->type(), skip->source_location, function, function_symbol.mode)
327+
parameter.type(), skip->source_location, function, function_symbol.mode)
335328
.symbol_expr();
336329
check.add(goto_programt::make_decl(p, skip->source_location));
337330

338331
call.arguments().push_back(p);
339332

340-
if(!p_it->get_identifier().empty())
333+
if(!parameter.get_identifier().empty())
341334
{
342-
symbol_exprt cur_p(p_it->get_identifier(), p_it->type());
335+
symbol_exprt cur_p(parameter.get_identifier(), parameter.type());
343336
replace.insert(cur_p, p);
344337
}
345338
}

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ void generate_function_bodiest::generate_parameter_names(
6868

6969
++it;
7070
}
71-
function.type = to_code_type(function_symbol.type);
7271
}
7372

7473
class assume_false_generate_function_bodiest : public generate_function_bodiest
@@ -215,8 +214,9 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
215214
instruction->source_location = function_symbol.location;
216215
return instruction;
217216
};
218-
const namespacet ns(symbol_table);
219-
for(auto const &parameter : function.type.parameters())
217+
218+
const code_typet &code_type = to_code_type(function_symbol.type);
219+
for(auto const &parameter : code_type.parameters())
220220
{
221221
if(
222222
parameter.type().id() == ID_pointer &&
@@ -269,9 +269,9 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
269269
function.body.destructive_append(dest);
270270
}
271271

272-
if(function.type.return_type() != empty_typet())
272+
if(code_type.return_type() != empty_typet())
273273
{
274-
typet type(function.type.return_type());
274+
typet type(code_type.return_type());
275275
type.remove(ID_C_constant);
276276

277277
symbolt &aux_symbol = get_fresh_aux_symbol(
@@ -299,7 +299,7 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
299299
function.body.destructive_append(dest);
300300

301301
exprt return_expr = typecast_exprt::conditional_cast(
302-
aux_symbol.symbol_expr(), function.type.return_type());
302+
aux_symbol.symbol_expr(), code_type.return_type());
303303

304304
add_instruction(goto_programt::make_return(code_returnt(return_expr)));
305305

src/goto-programs/goto_convert_functions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bool goto_convert_functionst::hide(const goto_programt &goto_program)
8686

8787
void goto_convert_functionst::add_return(
8888
goto_functionst::goto_functiont &f,
89+
const typet &return_type,
8990
const source_locationt &source_location)
9091
{
9192
#if 0
@@ -132,7 +133,7 @@ void goto_convert_functionst::add_return(
132133

133134
#endif
134135

135-
side_effect_expr_nondett rhs(f.type.return_type(), source_location);
136+
side_effect_expr_nondett rhs(return_type, source_location);
136137

137138
f.body.add(
138139
goto_programt::make_return(code_returnt(std::move(rhs)), source_location));
@@ -183,16 +184,15 @@ void goto_convert_functionst::convert_function(
183184

184185
targets=targetst();
185186
targets.set_return(end_function);
186-
targets.has_return_value=
187-
f.type.return_type().id()!=ID_empty &&
188-
f.type.return_type().id()!=ID_constructor &&
189-
f.type.return_type().id()!=ID_destructor;
187+
targets.has_return_value = code_type.return_type().id() != ID_empty &&
188+
code_type.return_type().id() != ID_constructor &&
189+
code_type.return_type().id() != ID_destructor;
190190

191191
goto_convert_rec(code, f.body, mode);
192192

193193
// add non-det return value, if needed
194194
if(targets.has_return_value)
195-
add_return(f, end_location);
195+
add_return(f, code_type.return_type(), end_location);
196196

197197
// handle SV-COMP's __VERIFIER_atomic_
198198
if(!f.body.instructions.empty() &&

src/goto-programs/goto_convert_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class goto_convert_functionst:public goto_convertt
5858
//
5959
void add_return(
6060
goto_functionst::goto_functiont &,
61+
const typet &return_type,
6162
const source_locationt &);
6263
};
6364

src/goto-programs/goto_function.cpp

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ void get_local_identifiers(
2121
{
2222
goto_function.body.get_decl_identifiers(dest);
2323

24-
const code_typet::parameterst &parameters = goto_function.type.parameters();
25-
2624
// add parameters
27-
for(const auto &param : parameters)
25+
for(const auto &identifier : goto_function.parameter_identifiers)
2826
{
29-
const irep_idt &identifier = param.get_identifier();
3027
if(identifier != "")
3128
dest.insert(identifier);
3229
}
@@ -40,27 +37,4 @@ void goto_functiont::validate(const namespacet &ns, const validation_modet vm)
4037
const
4138
{
4239
body.validate(ns, vm);
43-
44-
find_symbols_sett typetags;
45-
find_type_symbols(type, typetags);
46-
const symbolt *symbol;
47-
for(const auto &identifier : typetags)
48-
{
49-
DATA_CHECK(
50-
vm, !ns.lookup(identifier, symbol), id2string(identifier) + " not found");
51-
}
52-
53-
// Check that a void function does not contain any RETURN instructions
54-
if(to_code_type(type).return_type().id() == ID_empty)
55-
{
56-
forall_goto_program_instructions(instruction, body)
57-
{
58-
DATA_CHECK(
59-
vm,
60-
!instruction->is_return(),
61-
"void function should not return a value");
62-
}
63-
}
64-
65-
validate_full_type(type, ns, vm);
6640
}

src/goto-programs/goto_function.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,63 +28,32 @@ class goto_functiont
2828
public:
2929
goto_programt body;
3030

31-
/// The type of the function, indicating the return type and parameter types
32-
/// This is deprecated; get the type from the namespace instead.
33-
code_typet type;
34-
3531
typedef std::vector<irep_idt> parameter_identifierst;
36-
3732
/// The identifiers of the parameters of this function
38-
///
39-
/// Note: This is now the preferred way of getting the identifiers of the
40-
/// parameters. The identifiers in the type will go away.
4133
parameter_identifierst parameter_identifiers;
4234

4335
bool body_available() const
4436
{
4537
return !body.instructions.empty();
4638
}
4739

48-
/// This is deprecated; get the type from the namespace instead.
49-
bool is_inlined() const
50-
{
51-
return type.get_bool(ID_C_inlined);
52-
}
53-
54-
/// This is deprecated; get the type from the namespace instead.
55-
bool is_hidden() const
56-
{
57-
return type.get_bool(ID_C_hide);
58-
}
59-
60-
/// This is deprecated; modify the type in the namespace instead.
61-
void make_hidden()
62-
{
63-
type.set(ID_C_hide, true);
64-
}
65-
66-
goto_functiont() : body(), type({}, empty_typet())
67-
{
68-
}
40+
goto_functiont() = default;
6941

7042
void clear()
7143
{
7244
body.clear();
73-
type.clear();
7445
parameter_identifiers.clear();
7546
}
7647

7748
void swap(goto_functiont &other)
7849
{
7950
body.swap(other.body);
80-
type.swap(other.type);
8151
parameter_identifiers.swap(other.parameter_identifiers);
8252
}
8353

8454
void copy_from(const goto_functiont &other)
8555
{
8656
body.copy_from(other.body);
87-
type = other.type;
8857
parameter_identifiers = other.parameter_identifiers;
8958
}
9059

@@ -93,15 +62,13 @@ class goto_functiont
9362

9463
goto_functiont(goto_functiont &&other)
9564
: body(std::move(other.body)),
96-
type(std::move(other.type)),
9765
parameter_identifiers(std::move(other.parameter_identifiers))
9866
{
9967
}
10068

10169
goto_functiont &operator=(goto_functiont &&other)
10270
{
10371
body = std::move(other.body);
104-
type = std::move(other.type);
10572
parameter_identifiers = std::move(other.parameter_identifiers);
10673
return *this;
10774
}

src/goto-programs/goto_functions.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ class goto_functionst
149149
}
150150

151151
goto_function.validate(ns, vm);
152+
153+
// Check that a void function does not contain any RETURN instructions
154+
if(to_code_type(function_symbol.type).return_type().id() == ID_empty)
155+
{
156+
forall_goto_program_instructions(instruction, goto_function.body)
157+
{
158+
DATA_CHECK(
159+
vm,
160+
!instruction->is_return(),
161+
"void function should not return a value");
162+
}
163+
}
152164
}
153165
}
154166
};

0 commit comments

Comments
 (0)