Skip to content

Commit 7a1b567

Browse files
committed
Use get_fresh_aux_symbol
Re-use common code rather than repeatedly implementing the same logic.
1 parent 8c1ae4c commit 7a1b567

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/goto-instrument/wmm/shared_buffers.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
99
#include "shared_buffers.h"
1010

1111
#include <util/c_types.h>
12+
#include <util/fresh_symbol.h>
1213

1314
#include <linking/static_lifetime_init.h>
1415

@@ -88,21 +89,22 @@ irep_idt shared_bufferst::add(
8889
const typet &type,
8990
bool instrument)
9091
{
91-
const irep_idt identifier=id2string(object)+suffix;
92+
const namespacet ns(symbol_table);
9293

93-
symbolt new_symbol;
94-
new_symbol.name=identifier;
95-
new_symbol.base_name=id2string(base_name)+suffix;
96-
new_symbol.type=type;
94+
symbolt &new_symbol = get_fresh_aux_symbol(
95+
type,
96+
id2string(object) + suffix,
97+
id2string(base_name) + suffix,
98+
ns.lookup(object).location,
99+
ns.lookup(object).mode,
100+
symbol_table);
97101
new_symbol.is_static_lifetime=true;
98102
new_symbol.value.make_nil();
99103

100104
if(instrument)
101-
instrumentations.insert(identifier);
105+
instrumentations.insert(new_symbol.name);
102106

103-
symbolt *symbol_ptr;
104-
symbol_table.move(new_symbol, symbol_ptr);
105-
return identifier;
107+
return new_symbol.name;
106108
}
107109

108110
void shared_bufferst::add_initialization(goto_programt &goto_program)

src/goto-instrument/wmm/weak_memory.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Date: September 2011
2323

2424
#include <set>
2525

26+
#include <util/fresh_symbol.h>
27+
2628
#include <goto-programs/remove_skip.h>
2729

2830
#include <linking/static_lifetime_init.h>
@@ -44,7 +46,6 @@ void introduce_temporaries(
4446
messaget &message)
4547
{
4648
namespacet ns(symbol_table);
47-
unsigned tmp_counter=0;
4849

4950
#ifdef LOCAL_MAY
5051
local_may_aliast local_may(goto_function);
@@ -73,20 +74,19 @@ void introduce_temporaries(
7374
if(rw_set.empty())
7475
continue;
7576

76-
symbolt new_symbol;
77-
new_symbol.base_name="$tmp_guard";
78-
new_symbol.name =
79-
id2string(function_id) + "$tmp_guard" + std::to_string(tmp_counter++);
80-
new_symbol.type=bool_typet();
77+
symbolt &new_symbol = get_fresh_aux_symbol(
78+
bool_typet(),
79+
id2string(function_id),
80+
"$tmp_guard",
81+
instruction.source_location,
82+
ns.lookup(function_id).mode,
83+
symbol_table);
8184
new_symbol.is_static_lifetime=true;
8285
new_symbol.is_thread_local=true;
8386
new_symbol.value.make_nil();
8487

8588
symbol_exprt symbol_expr=new_symbol.symbol_expr();
8689

87-
symbolt *symbol_ptr;
88-
symbol_table.move(new_symbol, symbol_ptr);
89-
9090
goto_programt::instructiont new_i;
9191
new_i.make_assignment();
9292
new_i.code=code_assignt(symbol_expr, instruction.guard);

0 commit comments

Comments
 (0)