Skip to content

Commit 82a82f2

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
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. Part 2: Wherever we generate fresh symbols or function-specific objects we should use the actual function name to ensure fewer name collisions (for fresh symbols) or actually unique objects.
1 parent 4c5c3e1 commit 82a82f2

10 files changed

+164
-71
lines changed

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ 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(
210+
symbol_table,
211+
loc,
212+
goto_functionst::entry_point(),
213+
object_factory_parameters,
214+
lifetime);
210215

211216
code_blockt assignments;
212217
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/goto-instrument/code_contracts.cpp

Lines changed: 20 additions & 11 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
@@ -310,9 +315,12 @@ void code_contractst::add_contract_check(
310315
goto_programt::targett d=check.add_instruction(DECL);
311316
d->source_location=skip->source_location;
312317

313-
symbol_exprt r=
314-
new_tmp_symbol(gf.type.return_type(),
315-
d->source_location).symbol_expr();
318+
symbol_exprt r = new_tmp_symbol(
319+
gf.type.return_type(),
320+
d->source_location,
321+
function,
322+
function_symbol.mode)
323+
.symbol_expr();
316324
d->code=code_declt(r);
317325

318326
call.lhs()=r;
@@ -330,9 +338,10 @@ void code_contractst::add_contract_check(
330338
goto_programt::targett d=check.add_instruction(DECL);
331339
d->source_location=skip->source_location;
332340

333-
symbol_exprt p=
334-
new_tmp_symbol(p_it->type(),
335-
d->source_location).symbol_expr();
341+
symbol_exprt p =
342+
new_tmp_symbol(
343+
p_it->type(), d->source_location, function, function_symbol.mode)
344+
.symbol_expr();
336345
d->code=code_declt(p);
337346

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

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/wmm/abstract_event.h

Lines changed: 32 additions & 18 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
@@ -61,10 +62,20 @@ class abstract_eventt:public graph_nodet<empty_edget>
6162
}
6263

6364
abstract_eventt(
64-
operationt _op, unsigned _th, irep_idt _var,
65-
unsigned _id, source_locationt _loc, bool _local)
66-
:operation(_op), thread(_th), variable(_var), id(_id),
67-
source_location(_loc), local(_local)
65+
operationt _op,
66+
unsigned _th,
67+
irep_idt _var,
68+
unsigned _id,
69+
source_locationt _loc,
70+
irep_idt _function_id,
71+
bool _local)
72+
: operation(_op),
73+
thread(_th),
74+
variable(_var),
75+
id(_id),
76+
source_location(_loc),
77+
function_id(_function_id),
78+
local(_local)
6879
{
6980
}
7081

@@ -74,27 +85,29 @@ class abstract_eventt:public graph_nodet<empty_edget>
7485
irep_idt _var,
7586
unsigned _id,
7687
source_locationt _loc,
88+
irep_idt _function_id,
7789
bool _local,
7890
bool WRf,
7991
bool WWf,
8092
bool RRf,
8193
bool RWf,
8294
bool WWc,
8395
bool RWc,
84-
bool RRc):
85-
operation(_op),
86-
thread(_th),
87-
variable(_var),
88-
id(_id),
89-
source_location(_loc),
90-
local(_local),
91-
WRfence(RWf),
92-
WWfence(WWf),
93-
RRfence(RRf),
94-
RWfence(WRf),
95-
WWcumul(WWc),
96-
RWcumul(RWc),
97-
RRcumul(RRc)
96+
bool RRc)
97+
: operation(_op),
98+
thread(_th),
99+
variable(_var),
100+
id(_id),
101+
source_location(_loc),
102+
function_id(_function_id),
103+
local(_local),
104+
WRfence(RWf),
105+
WWfence(WWf),
106+
RRfence(RRf),
107+
RWfence(WRf),
108+
WWcumul(WWc),
109+
RWcumul(RWc),
110+
RRcumul(RRc)
98111
{
99112
}
100113

@@ -106,6 +119,7 @@ class abstract_eventt:public graph_nodet<empty_edget>
106119
variable=other.variable;
107120
id=other.id;
108121
source_location=other.source_location;
122+
function_id = other.function_id;
109123
local=other.local;
110124
}
111125

src/goto-instrument/wmm/event_graph.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ event_idt event_grapht::copy_segment(event_idt begin, event_idt end)
9494
const abstract_eventt &end_event=operator[](end);
9595

9696
/* not sure -- we should allow cross function cycles */
97-
if(begin_event.source_location.get_file()!=end_event.source_location
98-
.get_file()
99-
|| begin_event.source_location.get_function()!=end_event.source_location
100-
.get_function())
97+
if(
98+
begin_event.source_location.get_file() !=
99+
end_event.source_location.get_file() ||
100+
begin_event.function_id != end_event.function_id)
101101
return end;
102102

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

0 commit comments

Comments
 (0)