Skip to content

Commit f68080d

Browse files
committed
Only use source_locationt's get_function() for user output
A source location is a place in a text file, and the function information stored in there need not coincide with the name we use in the goto model.
1 parent 2dc0863 commit f68080d

30 files changed

+118
-102
lines changed

jbmc/src/jbmc/jbmc_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ void jbmc_parse_optionst::process_goto_function(
869869
if(using_symex_driven_loading)
870870
{
871871
// label the assertions
872-
label_properties(goto_function.body);
872+
label_properties(goto_function.body, function.get_function_id());
873873

874874
goto_function.body.update();
875875
function.compute_location_numbers();

src/analyses/constant_propagator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ void constant_propagator_domaint::valuest::set_dirty_to_top(
478478

479479
const symbolt &symbol=ns.lookup(id);
480480

481-
if((!symbol.is_procedure_local() || dirty(id)) &&
481+
if((symbol.is_static_lifetime || dirty(id)) &&
482482
!symbol.type.get_bool(ID_C_constant))
483483
{
484484
it = replace_const.erase(it);

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ symbol_exprt c_nondet_symbol_factory(
206206
bool moving_symbol_failed=symbol_table.move(main_symbol, main_symbol_ptr);
207207
CHECK_RETURN(!moving_symbol_failed);
208208

209-
symbol_factoryt state(symbol_table, loc, object_factory_parameters, lifetime);
209+
symbol_factoryt state(symbol_table, loc, goto_functionst::entry_point(), object_factory_parameters, lifetime);
210210

211211
code_blockt assignments;
212212
state.gen_nondet_init(assignments, main_symbol_expr);

src/ansi-c/c_nondet_symbol_factory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ class symbol_factoryt
3838
symbol_factoryt(
3939
symbol_tablet &_symbol_table,
4040
const source_locationt &loc,
41+
const irep_idt &name_prefix,
4142
const c_object_factory_parameterst &object_factory_params,
4243
const lifetimet lifetime)
4344
: symbol_table(_symbol_table),
4445
loc(loc),
4546
ns(_symbol_table),
4647
object_factory_params(object_factory_params),
47-
allocate_objects(ID_C, loc, loc.get_function(), symbol_table),
48+
allocate_objects(ID_C, loc, name_prefix, symbol_table),
4849
lifetime(lifetime)
4950
{
5051
}

src/ansi-c/expr2c.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ void expr2ct::get_shorthands(const exprt &expr)
160160
irep_idt func;
161161

162162
const symbolt *symbol;
163+
// we use the source-level function name as a means to detect collisions,
164+
// which is ok, because this is about generating user-visible output
163165
if(!ns.lookup(symbol_id, symbol))
164166
func=symbol->location.get_function();
165167

src/ansi-c/type2name.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,26 @@ static std::string type2name_tag(
3838
if(ns.lookup(identifier, symbol))
3939
return "SYM#"+id2string(identifier)+"#";
4040

41+
std::string result;
42+
43+
// this isn't really a qualifier, but the linker needs to
44+
// distinguish these - should likely be fixed in the linker instead
45+
if(!symbol->is_static_lifetime)
46+
result+='l';
47+
4148
assert(symbol && symbol->is_type);
4249

4350
if(symbol->type.id()!=ID_struct &&
4451
symbol->type.id()!=ID_union)
45-
return type2name(symbol->type, ns, symbol_number);
52+
return result + type2name(symbol->type, ns, symbol_number);
4653

4754
// assign each symbol a number when seen for the first time
4855
std::pair<symbol_numbert::iterator, bool> entry=
4956
symbol_number.insert(std::make_pair(
5057
identifier,
5158
std::make_pair(symbol_number.size(), true)));
5259

53-
std::string result = "SYM" +
60+
result += "SYM" +
5461
id2string(to_struct_union_type(symbol->type).get_tag()) +
5562
'#' + std::to_string(entry.first->second.first);
5663

@@ -99,11 +106,6 @@ static std::string type2name(
99106
if(type.get_bool(ID_C_noreturn))
100107
result+='n';
101108

102-
// this isn't really a qualifier, but the linker needs to
103-
// distinguish these - should likely be fixed in the linker instead
104-
if(!type.source_location().get_function().empty())
105-
result+='l';
106-
107109
if(type.id().empty())
108110
throw "empty type encountered";
109111
else if(type.id()==ID_empty)

src/goto-instrument/aggressive_slicer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void aggressive_slicert::doit()
9292
auto property_loc = find_property(p, goto_model.goto_functions);
9393
if(!property_loc.has_value())
9494
throw "unable to find property in call graph";
95-
note_functions_to_keep(property_loc.value().get_function());
95+
note_functions_to_keep(property_loc->first);
9696
}
9797

9898
// Add functions within distance of shortest path functions

src/goto-instrument/code_contracts.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class code_contractst
6161

6262
const symbolt &new_tmp_symbol(
6363
const typet &type,
64-
const source_locationt &source_location);
64+
const source_locationt &source_location,
65+
const irep_idt &function_id,
66+
const irep_idt &mode);
6567
};
6668

6769
static void check_apply_invariants(
@@ -248,14 +250,16 @@ void code_contractst::code_contracts(
248250

249251
const symbolt &code_contractst::new_tmp_symbol(
250252
const typet &type,
251-
const source_locationt &source_location)
253+
const source_locationt &source_location,
254+
const irep_idt &function_id,
255+
const irep_idt &mode)
252256
{
253257
return get_fresh_aux_symbol(
254258
type,
255-
id2string(source_location.get_function()),
259+
id2string(function_id) + "::tmp_cc",
256260
"tmp_cc",
257261
source_location,
258-
irep_idt(),
262+
mode,
259263
symbol_table);
260264
}
261265

@@ -301,7 +305,8 @@ void code_contractst::add_contract_check(
301305
g->source_location=skip->source_location;
302306

303307
// prepare function call including all declarations
304-
code_function_callt call(ns.lookup(function).symbol_expr());
308+
const symbolt &function_symbol = ns.lookup(function);
309+
code_function_callt call(function_symbol.symbol_expr());
305310
replace_symbolt replace;
306311

307312
// decl ret
@@ -312,7 +317,7 @@ void code_contractst::add_contract_check(
312317

313318
symbol_exprt r=
314319
new_tmp_symbol(gf.type.return_type(),
315-
d->source_location).symbol_expr();
320+
d->source_location, function, function_symbol.mode).symbol_expr();
316321
d->code=code_declt(r);
317322

318323
call.lhs()=r;
@@ -332,7 +337,7 @@ void code_contractst::add_contract_check(
332337

333338
symbol_exprt p=
334339
new_tmp_symbol(p_it->type(),
335-
d->source_location).symbol_expr();
340+
d->source_location, function, function_symbol.mode).symbol_expr();
336341
d->code=code_declt(p);
337342

338343
call.arguments().push_back(p);

src/goto-instrument/dump_c.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void dump_ct::operator()(std::ostream &os)
169169
const irep_idt &type_id=symbol.type.id();
170170

171171
if(symbol.is_type &&
172-
symbol.location.get_function().empty() &&
172+
!symbol.is_static_lifetime &&
173173
(type_id==ID_struct ||
174174
type_id==ID_union ||
175175
type_id==ID_c_enum))
@@ -293,7 +293,7 @@ void dump_ct::convert_compound_declaration(
293293
const symbolt &symbol,
294294
std::ostream &os_body)
295295
{
296-
if(!symbol.location.get_function().empty())
296+
if(!symbol.is_static_lifetime)
297297
return;
298298

299299
// do compound type body
@@ -738,7 +738,7 @@ void dump_ct::gather_global_typedefs()
738738
const symbolt &symbol=symbol_entry.second;
739739

740740
if(symbol.is_macro && symbol.is_type &&
741-
symbol.location.get_function().empty())
741+
!symbol.is_static_lifetime)
742742
{
743743
const irep_idt &typedef_str=symbol.type.get(ID_C_typedef);
744744
PRECONDITION(!typedef_str.empty());
@@ -843,8 +843,8 @@ void dump_ct::convert_global_variable(
843843
std::ostream &os,
844844
local_static_declst &local_static_decls)
845845
{
846-
const irep_idt &func=symbol.location.get_function();
847-
if((func.empty() || symbol.is_extern || symbol.value.is_not_nil()) &&
846+
const bool global = symbol.is_static_lifetime;
847+
if((global || symbol.is_extern || symbol.value.is_not_nil()) &&
848848
!converted_global.insert(symbol.name).second)
849849
return;
850850

@@ -856,7 +856,7 @@ void dump_ct::convert_global_variable(
856856

857857
// add a tentative declaration to cater for symbols in the initializer
858858
// relying on it this symbol
859-
if((func.empty() || symbol.is_extern) &&
859+
if((global || symbol.is_extern) &&
860860
(symbol.value.is_nil() || !syms.empty()))
861861
{
862862
os << "// " << symbol.name << '\n';
@@ -889,7 +889,7 @@ void dump_ct::convert_global_variable(
889889
d.copy_to_operands(symbol.value);
890890
}
891891

892-
if(!func.empty() && !symbol.is_extern)
892+
if(!global && !symbol.is_extern)
893893
{
894894
local_static_decls.emplace(symbol.name, d);
895895
}

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
169169
const exprt &lhs,
170170
const std::size_t initial_depth,
171171
const source_locationt &source_location,
172+
const irep_idt &function_id,
172173
symbol_tablet &symbol_table,
173174
goto_programt &dest) const
174175
{
175176
symbol_factoryt symbol_factory(
176177
symbol_table,
177178
source_location,
179+
function_id,
178180
object_factory_parameters,
179181
lifetimet::DYNAMIC);
180182

@@ -235,6 +237,7 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
235237
dereference_expr,
236238
1, // depth 1 since we pass the dereferenced pointer
237239
function_symbol.location,
240+
function_name,
238241
symbol_table,
239242
dest);
240243

@@ -260,6 +263,7 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
260263
symbol_exprt(global_sym.name, global_sym.type),
261264
0,
262265
function_symbol.location,
266+
irep_idt(),
263267
symbol_table,
264268
dest);
265269

@@ -291,6 +295,7 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
291295
aux_symbol.symbol_expr(),
292296
0,
293297
function_symbol.location,
298+
function_name,
294299
symbol_table,
295300
dest);
296301

src/goto-instrument/goto_program2code.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ void goto_program2codet::add_local_types(const typet &type)
14161416
const irep_idt &identifier=to_symbol_type(type).get_identifier();
14171417
const symbolt &symbol=ns.lookup(identifier);
14181418

1419-
if(symbol.location.get_function().empty() ||
1419+
if(!symbol.is_static_lifetime ||
14201420
!type_names_set.insert(identifier).second)
14211421
return;
14221422

@@ -1432,7 +1432,7 @@ void goto_program2codet::add_local_types(const typet &type)
14321432
const irep_idt &identifier=to_c_enum_tag_type(type).get_identifier();
14331433
const symbolt &symbol=ns.lookup(identifier);
14341434

1435-
if(symbol.location.get_function().empty() ||
1435+
if(!symbol.is_static_lifetime ||
14361436
!type_names_set.insert(identifier).second)
14371437
return;
14381438

@@ -1982,7 +1982,7 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
19821982
if(symbol.is_static_lifetime &&
19831983
symbol.type.id()!=ID_code &&
19841984
!symbol.is_extern &&
1985-
!symbol.location.get_function().empty() &&
1985+
!symbol.is_static_lifetime &&
19861986
local_static_set.insert(identifier).second)
19871987
{
19881988
if(symbol.value.is_not_nil())

src/goto-instrument/wmm/abstract_event.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class abstract_eventt:public graph_nodet<empty_edget>
3434
irep_idt variable;
3535
unsigned id;
3636
source_locationt source_location;
37+
irep_idt function_id;
3738
bool local;
3839

3940
// for ASMfence
@@ -62,9 +63,9 @@ class abstract_eventt:public graph_nodet<empty_edget>
6263

6364
abstract_eventt(
6465
operationt _op, unsigned _th, irep_idt _var,
65-
unsigned _id, source_locationt _loc, bool _local)
66+
unsigned _id, source_locationt _loc, irep_idt _function_id, bool _local)
6667
:operation(_op), thread(_th), variable(_var), id(_id),
67-
source_location(_loc), local(_local)
68+
source_location(_loc), function_id(_function_id), local(_local)
6869
{
6970
}
7071

@@ -74,6 +75,7 @@ class abstract_eventt:public graph_nodet<empty_edget>
7475
irep_idt _var,
7576
unsigned _id,
7677
source_locationt _loc,
78+
irep_idt _function_id,
7779
bool _local,
7880
bool WRf,
7981
bool WWf,
@@ -87,6 +89,7 @@ class abstract_eventt:public graph_nodet<empty_edget>
8789
variable(_var),
8890
id(_id),
8991
source_location(_loc),
92+
function_id(_function_id),
9093
local(_local),
9194
WRfence(RWf),
9295
WWfence(WWf),
@@ -106,6 +109,7 @@ class abstract_eventt:public graph_nodet<empty_edget>
106109
variable=other.variable;
107110
id=other.id;
108111
source_location=other.source_location;
112+
function_id=other.function_id;
109113
local=other.local;
110114
}
111115

src/goto-instrument/wmm/event_graph.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end)
9696
/* not sure -- we should allow cross function cycles */
9797
if(begin_event.source_location.get_file()!=end_event.source_location
9898
.get_file()
99-
|| begin_event.source_location.get_function()!=end_event.source_location
100-
.get_function())
99+
|| begin_event.function_id!=end_event.function_id)
101100
return end;
102101

103102
if(duplicated_bodies.find(std::make_pair(begin_event, end_event))

0 commit comments

Comments
 (0)