Skip to content

Commit 875a634

Browse files
committed
Store inlined/hidden attributes of code-typed symbols in the symbol table
There should only be a single place to hold type information, including attributes, to ensure consistency.
1 parent 6513a78 commit 875a634

23 files changed

+85
-55
lines changed

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/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-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/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)
@@ -284,7 +286,7 @@ static void instrument_cover_goals(
284286

285287
bool changed = false;
286288

287-
if(cover_config.function_filters(function_id, function))
289+
if(cover_config.function_filters(function_id, function, ns))
288290
{
289291
instrument_cover_goals(
290292
function_id,
@@ -310,16 +312,19 @@ static void instrument_cover_goals(
310312
/// Instruments a single goto program based on the given configuration
311313
/// \param cover_config: configuration, produced using get_cover_config
312314
/// \param function: goto program to instrument
315+
/// \param ns: namespace
313316
/// \param message_handler: log output
314317
void instrument_cover_goals(
315318
const cover_configt &cover_config,
316319
goto_model_functiont &function,
320+
const namespacet &ns,
317321
message_handlert &message_handler)
318322
{
319323
instrument_cover_goals(
320324
cover_config,
321325
function.get_function_id(),
322326
function.get_goto_function(),
327+
ns,
323328
message_handler);
324329

325330
function.compute_location_numbers();
@@ -354,11 +359,12 @@ bool instrument_cover_goals(
354359
return true;
355360
}
356361

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

src/goto-instrument/cover.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ std::unique_ptr<cover_configt> get_cover_config(
6262
void instrument_cover_goals(
6363
const cover_configt &,
6464
goto_model_functiont &,
65+
const namespacet &ns,
6566
message_handlert &);
6667

6768
void parse_cover_options(const cmdlinet &, optionst &);

src/goto-instrument/cover_filter.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,20 @@ Author: Peter Schrammel
1616
/// Filter out functions that are not considered provided by the user
1717
/// \param function_id: a function name
1818
/// \param goto_function: a goto function
19+
/// \param ns: a namespace
1920
/// \return returns true if function is considered user-provided
2021
bool internal_functions_filtert::operator()(
2122
const irep_idt &function_id,
22-
const goto_functionst::goto_functiont &goto_function) const
23+
const goto_functionst::goto_functiont &goto_function,
24+
const namespacet &ns) const
2325
{
2426
if(function_id == goto_functionst::entry_point())
2527
return false;
2628

2729
if(function_id == INITIALIZE_FUNCTION)
2830
return false;
2931

30-
if(goto_function.is_hidden())
32+
if(to_code_type(ns.lookup(function_id).type).is_hidden())
3133
return false;
3234

3335
// ignore Java built-ins (synthetic functions)
@@ -46,12 +48,15 @@ bool internal_functions_filtert::operator()(
4648
/// Filter functions whose name match the regex
4749
/// \param function_id: a function name
4850
/// \param goto_function: a goto function
51+
/// \param ns: a namespace
4952
/// \return returns true if the function name matches
5053
bool include_pattern_filtert::operator()(
5154
const irep_idt &function_id,
52-
const goto_functionst::goto_functiont &goto_function) const
55+
const goto_functionst::goto_functiont &goto_function,
56+
const namespacet &ns) const
5357
{
5458
(void)goto_function; // unused parameter
59+
(void)ns; // unused parameter
5560
std::smatch string_matcher;
5661
return std::regex_match(
5762
id2string(function_id), string_matcher, regex_matcher);
@@ -64,12 +69,15 @@ bool include_pattern_filtert::operator()(
6469
/// These criteria are arbitrarily chosen.
6570
/// \param function_id: name of \p goto_function
6671
/// \param goto_function: a goto function
72+
/// \param ns: a namespace
6773
/// \return returns true if non-trivial
6874
bool trivial_functions_filtert::operator()(
6975
const irep_idt &function_id,
70-
const goto_functionst::goto_functiont &goto_function) const
76+
const goto_functionst::goto_functiont &goto_function,
77+
const namespacet &ns) const
7178
{
7279
(void)function_id; // unused parameter
80+
(void)ns; // unused parameter
7381
unsigned long count_assignments = 0, count_goto = 0;
7482
forall_goto_program_instructions(i_it, goto_function.body)
7583
{

src/goto-instrument/cover_filter.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class function_filter_baset : public messaget
3636
/// Returns true if the function passes the filter criteria
3737
virtual bool operator()(
3838
const irep_idt &identifier,
39-
const goto_functionst::goto_functiont &goto_function) const = 0;
39+
const goto_functionst::goto_functiont &goto_function,
40+
const namespacet &) const = 0;
4041

4142
/// Can be called after final filter application to report
4243
/// on unexpected situations encountered
@@ -84,12 +85,14 @@ class function_filterst
8485
/// Applies the filters to the given function
8586
/// \param identifier: function name
8687
/// \param goto_function: goto function
88+
/// \param ns: a namespace
8789
bool operator()(
8890
const irep_idt &identifier,
89-
const goto_functionst::goto_functiont &goto_function) const
91+
const goto_functionst::goto_functiont &goto_function,
92+
const namespacet &ns) const
9093
{
9194
for(const auto &filter : filters)
92-
if(!(*filter)(identifier, goto_function))
95+
if(!(*filter)(identifier, goto_function, ns))
9396
return false;
9497

9598
return true;
@@ -152,7 +155,8 @@ class internal_functions_filtert : public function_filter_baset
152155

153156
bool operator()(
154157
const irep_idt &identifier,
155-
const goto_functionst::goto_functiont &goto_function) const override;
158+
const goto_functionst::goto_functiont &goto_function,
159+
const namespacet &ns) const override;
156160
};
157161

158162
/// Filters functions that match the provided pattern
@@ -169,7 +173,8 @@ class include_pattern_filtert : public function_filter_baset
169173

170174
bool operator()(
171175
const irep_idt &identifier,
172-
const goto_functionst::goto_functiont &goto_function) const override;
176+
const goto_functionst::goto_functiont &goto_function,
177+
const namespacet &) const override;
173178

174179
private:
175180
std::regex regex_matcher;
@@ -186,7 +191,8 @@ class trivial_functions_filtert : public function_filter_baset
186191

187192
bool operator()(
188193
const irep_idt &identifier,
189-
const goto_functionst::goto_functiont &goto_function) const override;
194+
const goto_functionst::goto_functiont &goto_function,
195+
const namespacet &) const override;
190196
};
191197

192198
/// Filters out goals with source locations considered internal

src/goto-instrument/remove_function.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void remove_function(
3939
<< " in goto program" << messaget::eom;
4040
return;
4141
}
42-
else if(entry->second.is_inlined())
42+
else if(to_code_type(goto_model.symbol_table.lookup_ref(identifier).type)
43+
.get_inlined())
4344
{
4445
message.warning() << "Function " << identifier << " is inlined, "
4546
<< "instantiations will not be removed"

src/goto-programs/goto_convert_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void goto_convert_functionst::convert_function(
219219
f.body.update();
220220

221221
if(hide(f.body))
222-
f.make_hidden();
222+
to_code_type(symbol_table.get_writeable_ref(identifier).type).make_hidden();
223223

224224
lifetime = parent_lifetime;
225225
}

src/goto-programs/goto_inline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void goto_partial_inline(
195195
continue;
196196

197197
if(
198-
called_function.is_inlined() ||
198+
to_code_type(ns.lookup(id).type).get_inlined() ||
199199
called_function.body.instructions.size() <= smallfunc_limit)
200200
{
201201
PRECONDITION(i_it->is_function_call());

src/goto-programs/goto_inline_class.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ void goto_inlinet::insert_function_body(
267267
"final instruction of a function must be an END_FUNCTION");
268268
end.type=LOCATION;
269269

270+
const symbolt &function_symbol = ns.lookup(identifier);
270271
// make sure the inlined function does not introduce hiding
271-
if(goto_function.is_hidden())
272+
if(to_code_type(function_symbol.type).is_hidden())
272273
{
273274
for(auto &instruction : body.instructions)
274275
instruction.labels.remove(CPROVER_PREFIX "HIDE");

src/goto-programs/link_goto_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static bool link_functions(
104104
{
105105
// just keep the old one in dest
106106
}
107-
else if(in_dest_symbol_table.type.get_bool(ID_C_inlined))
107+
else if(to_code_type(ns.lookup(final_id).type).get_inlined())
108108
{
109109
// ok, we silently ignore
110110
}

src/goto-programs/property_checker.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ property_checkert::property_checkert(
3030
{
3131
}
3232

33-
void property_checkert::initialize_property_map(
34-
const goto_functionst &goto_functions)
33+
void property_checkert::initialize_property_map(const goto_modelt &goto_model)
3534
{
36-
forall_goto_functions(it, goto_functions)
37-
if(!it->second.is_inlined() ||
38-
it->first==goto_functions.entry_point())
35+
const namespacet ns(goto_model.symbol_table);
36+
37+
forall_goto_functions(it, goto_model.goto_functions)
38+
if(
39+
!to_code_type(ns.lookup(it->first).type).get_inlined() ||
40+
it->first == goto_functionst::entry_point())
3941
{
4042
const goto_programt &goto_program=it->second.body;
4143

src/goto-programs/property_checker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class property_checkert:public messaget
4949
property_mapt property_map;
5050

5151
protected:
52-
void initialize_property_map(const goto_functionst &);
52+
void initialize_property_map(const goto_modelt &);
5353
};
5454

5555
#endif // CPROVER_GOTO_PROGRAMS_PROPERTY_CHECKER_H

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static bool read_bin_goto_object(
164164
f.body.update();
165165

166166
if(hidden)
167-
f.make_hidden();
167+
to_code_type(symbol_table.get_writeable_ref(fname).type).make_hidden();
168168
}
169169

170170
functions.compute_location_numbers();

src/goto-programs/set_properties.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,14 @@ void set_properties(
9797
goto_modelt &goto_model,
9898
const std::list<std::string> &properties)
9999
{
100-
set_properties(goto_model.goto_functions, properties);
101-
}
100+
const namespacet ns(goto_model.symbol_table);
102101

103-
void set_properties(
104-
goto_functionst &goto_functions,
105-
const std::list<std::string> &properties)
106-
{
107102
std::unordered_set<irep_idt> property_set;
108103

109104
property_set.insert(properties.begin(), properties.end());
110105

111-
Forall_goto_functions(it, goto_functions)
112-
if(!it->second.is_inlined())
106+
Forall_goto_functions(it, goto_model.goto_functions)
107+
if(!to_code_type(ns.lookup(it->first).type).get_inlined())
113108
set_properties(it->second.body, property_set);
114109

115110
if(!property_set.empty())

0 commit comments

Comments
 (0)