Skip to content

Commit a1631f1

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 795cf7f commit a1631f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+275
-366
lines changed

src/analyses/goto_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ void goto_checkt::goto_check(
16531653

16541654
if(enable_pointer_check)
16551655
local_bitvector_analysis =
1656-
util_make_unique<local_bitvector_analysist>(goto_function);
1656+
util_make_unique<local_bitvector_analysist>(goto_function, ns);
16571657

16581658
goto_programt &goto_program=goto_function.body;
16591659

src/analyses/local_bitvector_analysis.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ bool local_bitvector_analysist::merge(points_tot &a, points_tot &b)
6060
/// \return return 'true' iff we track the object with given identifier
6161
bool local_bitvector_analysist::is_tracked(const irep_idt &identifier)
6262
{
63-
localst::locals_mapt::const_iterator it=locals.locals_map.find(identifier);
64-
if(it==locals.locals_map.end() ||
65-
it->second.type().id()!=ID_pointer ||
66-
dirty(identifier))
67-
return false;
68-
69-
return true;
63+
localst::locals_sett::const_iterator it = locals.locals.find(identifier);
64+
return it != locals.locals.end() && ns.lookup(*it).type.id() == ID_pointer &&
65+
!dirty(identifier);
7066
}
7167

7268
void local_bitvector_analysist::assign_lhs(
@@ -254,9 +250,9 @@ void local_bitvector_analysist::build()
254250
// Gather the objects we track, and
255251
// feed in sufficiently bad defaults for their value
256252
// in the entry location.
257-
for(const auto &local : locals.locals_map)
258-
if(is_tracked(local.first))
259-
loc_infos[0][pointers.number(local.first)]=flagst::mk_unknown();
253+
for(const auto &local : locals.locals)
254+
if(is_tracked(local))
255+
loc_infos[0][pointers.number(local)] = flagst::mk_unknown();
260256

261257
while(!work_queue.empty())
262258
{

src/analyses/local_bitvector_analysis.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ class local_bitvector_analysist
2525
public:
2626
typedef goto_functionst::goto_functiont goto_functiont;
2727

28-
explicit local_bitvector_analysist(
29-
const goto_functiont &_goto_function):
30-
dirty(_goto_function),
31-
locals(_goto_function),
32-
cfg(_goto_function.body)
28+
local_bitvector_analysist(
29+
const goto_functiont &_goto_function,
30+
const namespacet &ns)
31+
: dirty(_goto_function),
32+
locals(_goto_function),
33+
cfg(_goto_function.body),
34+
ns(ns)
3335
{
3436
build();
3537
}
@@ -176,6 +178,7 @@ class local_bitvector_analysist
176178
const exprt &src);
177179

178180
protected:
181+
const namespacet &ns;
179182
void build();
180183

181184
typedef std::stack<unsigned> work_queuet;

src/analyses/locals.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ Date: March 2013
1818
void localst::build(const goto_functiont &goto_function)
1919
{
2020
forall_goto_program_instructions(it, goto_function.body)
21+
{
2122
if(it->is_decl())
22-
{
23-
const code_declt &code_decl=to_code_decl(it->code);
24-
locals_map.emplace(code_decl.get_identifier(), code_decl.symbol());
25-
}
26-
27-
for(const auto &param : goto_function.type.parameters())
28-
locals_map.emplace(
29-
param.get_identifier(),
30-
symbol_exprt(param.get_identifier(), param.type()));
23+
locals.insert(it->get_decl().get_identifier());
24+
}
25+
26+
locals.insert(
27+
goto_function.parameter_identifiers.begin(),
28+
goto_function.parameter_identifiers.end());
3129
}
3230

3331
void localst::output(std::ostream &out) const
3432
{
35-
for(const auto &local : locals_map)
36-
out << local.first << "\n";
33+
for(const auto &local : locals)
34+
out << local << "\n";
3735
}

src/analyses/locals.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ class localst
3131
// but including the function parameters.
3232
bool is_local(const irep_idt &identifier) const
3333
{
34-
return locals_map.find(identifier)!=locals_map.end();
34+
return locals.find(identifier) != locals.end();
3535
}
3636

37-
typedef std::map<irep_idt, symbol_exprt> locals_mapt;
38-
locals_mapt locals_map;
37+
typedef std::unordered_set<irep_idt> locals_sett;
38+
locals_sett locals;
3939

4040
protected:
4141
void build(const goto_functiont &goto_function);

src/ansi-c/ansi_c_declaration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void ansi_c_declarationt::to_symbol(
150150
symbol.is_file_local=get_is_static();
151151

152152
if(get_is_inline())
153-
symbol.type.set(ID_C_inlined, true);
153+
to_code_type(symbol.type).set_inlined(true);
154154

155155
if(
156156
config.ansi_c.mode == configt::ansi_ct::flavourt::GCC ||

src/ansi-c/c_typecheck_base.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
309309

310310
if(final_new.id()==ID_code)
311311
{
312-
bool inlined=
313-
(new_symbol.type.get_bool(ID_C_inlined) ||
314-
old_symbol.type.get_bool(ID_C_inlined));
315-
316312
if(final_old.id()!=ID_code)
317313
{
318314
error().source_location=new_symbol.location;
@@ -327,15 +323,17 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
327323
code_typet &old_ct=to_code_type(old_symbol.type);
328324
code_typet &new_ct=to_code_type(new_symbol.type);
329325

326+
const bool inlined = old_ct.get_inlined() || new_ct.get_inlined();
327+
330328
if(old_ct.has_ellipsis() && !new_ct.has_ellipsis())
331329
old_ct=new_ct;
332330
else if(!old_ct.has_ellipsis() && new_ct.has_ellipsis())
333331
new_ct=old_ct;
334332

335333
if(inlined)
336334
{
337-
old_symbol.type.set(ID_C_inlined, true);
338-
new_symbol.type.set(ID_C_inlined, true);
335+
old_ct.set_inlined(true);
336+
new_ct.set_inlined(true);
339337
}
340338

341339
// do body
@@ -348,7 +346,7 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
348346
// definition is marked as "extern inline"
349347

350348
if(
351-
old_symbol.type.get_bool(ID_C_inlined) &&
349+
old_ct.get_inlined() &&
352350
(config.ansi_c.mode == configt::ansi_ct::flavourt::GCC ||
353351
config.ansi_c.mode == configt::ansi_ct::flavourt::CLANG ||
354352
config.ansi_c.mode == configt::ansi_ct::flavourt::ARM ||

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/cpp/cpp_declarator_converter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ symbolt &cpp_declarator_convertert::convert_new_symbol(
433433
symbol.is_macro=true;
434434

435435
if(member_spec.is_inline())
436-
symbol.type.set(ID_C_inlined, true);
436+
to_code_type(symbol.type).set_inlined(true);
437437

438438
if(!symbol.is_type)
439439
{

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ void cpp_typecheckt::typecheck_member_function(
13081308
component.set(ID_prefix, id2string(identifier) + "::");
13091309

13101310
if(value.is_not_nil())
1311-
type.set(ID_C_inlined, true);
1311+
to_code_type(type).set_inlined(true);
13121312

13131313
symbol.name=identifier;
13141314
symbol.base_name=component.get_base_name();

src/goto-analyzer/unreachable_instructions.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ void unreachable_instructions(
173173

174174
// f_it->first may be a link-time renamed version, use the
175175
// base_name instead; do not list inlined functions
176-
if(called.find(decl.base_name)!=called.end() ||
177-
f_it->second.is_inlined())
176+
if(
177+
called.find(decl.base_name) != called.end() ||
178+
to_code_type(decl.type).get_inlined())
178179
unreachable_instructions(goto_program, dead_map);
179180
else
180181
all_unreachable(goto_program, dead_map);
@@ -295,9 +296,9 @@ static void list_functions(
295296

296297
// f_it->first may be a link-time renamed version, use the
297298
// base_name instead; do not list inlined functions
298-
if(unreachable ==
299-
(called.find(decl.base_name)!=called.end() ||
300-
f_it->second.is_inlined()))
299+
if(
300+
unreachable == (called.find(decl.base_name) != called.end() ||
301+
to_code_type(decl.type).get_inlined()))
301302
continue;
302303

303304
source_locationt first_location=decl.location;

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ void function_call_harness_generatort::generate(
112112

113113
symbol_table.insert(harness_function_symbol);
114114

115-
goto_model.goto_functions.function_map[harness_function_name].type =
116-
to_code_type(harness_function_symbol.type);
117115
auto &body =
118116
goto_model.goto_functions.function_map[harness_function_name].body;
119117
goto_convert(

src/goto-instrument/aggressive_slicer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ void aggressive_slicert::note_functions_to_keep(
3939

4040
void aggressive_slicert::get_all_functions_containing_properties()
4141
{
42+
const namespacet ns(goto_model.symbol_table);
43+
4244
for(const auto &fct : goto_model.goto_functions.function_map)
4345
{
44-
if(!fct.second.is_inlined())
46+
if(!to_code_type(ns.lookup(fct.first).type).get_inlined())
4547
{
4648
for(const auto &ins : fct.second.body.instructions)
4749
if(ins.is_assert())

src/goto-instrument/code_contracts.cpp

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

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

278-
const exprt &requires=
279-
static_cast<const exprt&>(gf.type.find(ID_C_spec_requires));
280-
const exprt &ensures=
281-
static_cast<const exprt&>(gf.type.find(ID_C_spec_ensures));
275+
const exprt &requires =
276+
static_cast<const exprt &>(code_type.find(ID_C_spec_requires));
277+
const exprt &ensures =
278+
static_cast<const exprt &>(code_type.find(ID_C_spec_ensures));
282279
assert(ensures.is_not_nil());
283280

284281
// build:
@@ -305,18 +302,17 @@ void code_contractst::add_contract_check(
305302
g->source_location=skip->source_location;
306303

307304
// prepare function call including all declarations
308-
const symbolt &function_symbol = ns.lookup(function);
309305
code_function_callt call(function_symbol.symbol_expr());
310306
replace_symbolt replace;
311307

312308
// decl ret
313-
if(gf.type.return_type()!=empty_typet())
309+
if(code_type.return_type() != empty_typet())
314310
{
315311
goto_programt::targett d=check.add_instruction(DECL);
316312
d->source_location=skip->source_location;
317313

318314
symbol_exprt r = new_tmp_symbol(
319-
gf.type.return_type(),
315+
code_type.return_type(),
320316
d->source_location,
321317
function,
322318
function_symbol.mode)
@@ -330,25 +326,22 @@ void code_contractst::add_contract_check(
330326
}
331327

332328
// decl parameter1 ...
333-
for(code_typet::parameterst::const_iterator
334-
p_it=gf.type.parameters().begin();
335-
p_it!=gf.type.parameters().end();
336-
++p_it)
329+
for(const auto &parameter : code_type.parameters())
337330
{
338331
goto_programt::targett d=check.add_instruction(DECL);
339332
d->source_location=skip->source_location;
340333

341334
symbol_exprt p =
342335
new_tmp_symbol(
343-
p_it->type(), d->source_location, function, function_symbol.mode)
336+
parameter.type(), d->source_location, function, function_symbol.mode)
344337
.symbol_expr();
345338
d->code=code_declt(p);
346339

347340
call.arguments().push_back(p);
348341

349-
if(!p_it->get_identifier().empty())
342+
if(!parameter.get_identifier().empty())
350343
{
351-
symbol_exprt cur_p(p_it->get_identifier(), p_it->type());
344+
symbol_exprt cur_p(parameter.get_identifier(), parameter.type());
352345
replace.insert(cur_p, p);
353346
}
354347
}

src/goto-instrument/cover.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,13 @@ std::unique_ptr<cover_configt> get_cover_config(
255255
/// \param cover_config: configuration, produced using get_cover_config
256256
/// \param function_id: function name
257257
/// \param function: function to instrument
258+
/// \param ns: namespace
258259
/// \param message_handler: log output
259260
static void instrument_cover_goals(
260261
const cover_configt &cover_config,
261262
const irep_idt &function_id,
262263
goto_functionst::goto_functiont &function,
264+
const namespacet &ns,
263265
message_handlert &message_handler)
264266
{
265267
if(!cover_config.keep_assertions)
@@ -283,7 +285,7 @@ static void instrument_cover_goals(
283285

284286
bool changed = false;
285287

286-
if(cover_config.function_filters(function_id, function))
288+
if(cover_config.function_filters(function_id, function, ns))
287289
{
288290
instrument_cover_goals(
289291
function_id,
@@ -309,16 +311,19 @@ static void instrument_cover_goals(
309311
/// Instruments a single goto program based on the given configuration
310312
/// \param cover_config: configuration, produced using get_cover_config
311313
/// \param function: goto program to instrument
314+
/// \param ns: namespace
312315
/// \param message_handler: log output
313316
void instrument_cover_goals(
314317
const cover_configt &cover_config,
315318
goto_model_functiont &function,
319+
const namespacet &ns,
316320
message_handlert &message_handler)
317321
{
318322
instrument_cover_goals(
319323
cover_config,
320324
function.get_function_id(),
321325
function.get_goto_function(),
326+
ns,
322327
message_handler);
323328

324329
function.compute_location_numbers();
@@ -353,11 +358,12 @@ bool instrument_cover_goals(
353358
return true;
354359
}
355360

361+
const namespacet ns(symbol_table);
356362
Forall_goto_functions(f_it, goto_functions)
357363
{
358364
cover_config->mode = symbol_table.lookup(f_it->first)->mode;
359365
instrument_cover_goals(
360-
*cover_config, f_it->first, f_it->second, message_handler);
366+
*cover_config, f_it->first, f_it->second, ns, message_handler);
361367
}
362368
goto_functions.compute_location_numbers();
363369

0 commit comments

Comments
 (0)