Skip to content

Commit 45a841b

Browse files
committed
goto-instrument: use new symbolt constructors
To the extent possible, apply resource-acquisition-is-initialisation. The constructors ensure that at least the most essential fields (name, type, mode) are set.
1 parent 80d667a commit 45a841b

File tree

9 files changed

+23
-28
lines changed

9 files changed

+23
-28
lines changed

regression/goto-instrument/dump-type-header-exclude-non-module-var/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ struct B
88

99
#define temperature(x) x.t
1010

11+
int __VERIFIER_nondet_int();
12+
1113
int main()
1214
{
1315
struct B aStruct = {3, 8};
1416
__CPROVER_assert(my_config.a == 7, "Should be valid");
15-
my_config.a = nondet_int();
17+
my_config.a = __VERIFIER_nondet_int();
1618

1719
__CPROVER_assert(!(my_config.a == 4), "Should be nondet now");
1820
__CPROVER_assert(aStruct.t, "Should not be null");

src/goto-instrument/accelerate/accelerate.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,10 @@ bool acceleratet::is_underapproximate(path_acceleratort &accelerator)
435435

436436
symbolt acceleratet::make_symbol(std::string name, typet type)
437437
{
438-
symbolt ret;
438+
symbolt ret{name, std::move(type), irep_idt{}};
439439
ret.module="accelerate";
440-
ret.name=name;
441440
ret.base_name=name;
442441
ret.pretty_name=name;
443-
ret.type=type;
444442

445443
symbol_table.add(ret);
446444

src/goto-instrument/accelerate/acceleration_utils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,10 @@ symbolt acceleration_utilst::fresh_symbol(std::string base, typet type)
12481248
static int num_symbols=0;
12491249

12501250
std::string name=base + "_" + std::to_string(num_symbols++);
1251-
symbolt ret;
1251+
symbolt ret{name, std::move(type), irep_idt{}};
12521252
ret.module="scratch";
1253-
ret.name=name;
12541253
ret.base_name=name;
12551254
ret.pretty_name=name;
1256-
ret.type=type;
12571255

12581256
symbol_table.add(ret);
12591257

src/goto-instrument/contracts/contracts.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,14 @@ void code_contractst::enforce_contract(const irep_idt &function)
11591159
goto_functions.function_map.erase(old_function);
11601160

11611161
// Place a new symbol with the mangled name into the symbol table
1162-
symbolt mangled_sym;
1162+
source_locationt sl;
1163+
sl.set_file("instrumented for code contracts");
1164+
sl.set_line("0");
11631165
const symbolt *original_sym = symbol_table.lookup(original);
1164-
mangled_sym = *original_sym;
1166+
symbolt mangled_sym = *original_sym;
11651167
mangled_sym.name = mangled;
11661168
mangled_sym.base_name = mangled;
1167-
mangled_sym.location = original_sym->location;
1169+
mangled_sym.location = sl;
11681170
const auto mangled_found = symbol_table.insert(std::move(mangled_sym));
11691171
INVARIANT(
11701172
mangled_found.second,

src/goto-instrument/function.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,25 @@ code_function_callt function_to_call(
3232

3333
if(s_it==symbol_table.symbols.end())
3434
{
35+
// This has to be dead code: a symbol table must contain all functions that
36+
// appear in goto_functions.
37+
UNREACHABLE;
38+
#if 0
39+
3540
// not there
3641
auto p = pointer_type(char_type());
3742
p.base_type().set(ID_C_constant, true);
3843

3944
const code_typet function_type({code_typet::parametert(p)}, empty_typet());
4045

41-
symbolt new_symbol;
42-
new_symbol.name=id;
46+
symbolt new_symbol{id, function_type, irep_idt{}};
4347
new_symbol.base_name=id;
44-
new_symbol.type=function_type;
4548

4649
symbol_table.insert(std::move(new_symbol));
4750

4851
s_it=symbol_table.symbols.find(id);
4952
assert(s_it!=symbol_table.symbols.end());
53+
#endif
5054
}
5155

5256
// signature is expected to be

src/goto-instrument/goto_program2code.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,10 +1868,8 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
18681868
base_name="nondet_"+std::to_string(count);
18691869
}
18701870

1871-
symbolt symbol;
1871+
symbolt symbol{base_name, code_typet({}, expr.type()), ID_C};
18721872
symbol.base_name=base_name;
1873-
symbol.name=base_name;
1874-
symbol.type = code_typet({}, expr.type());
18751873
id=symbol.name;
18761874

18771875
symbol_table.insert(std::move(symbol));

src/goto-instrument/race_check.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ const symbolt &w_guardst::get_guard_symbol(const irep_idt &object)
7676

7777
w_guards.push_back(identifier);
7878

79-
symbolt new_symbol;
80-
new_symbol.name=identifier;
79+
symbolt new_symbol{
80+
identifier, bool_typet(), symbol_table.lookup_ref(object).mode};
8181
new_symbol.base_name=identifier;
82-
new_symbol.type=bool_typet();
8382
new_symbol.is_static_lifetime=true;
8483
new_symbol.value=false_exprt();
8584

src/goto-instrument/stack_depth.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ static symbol_exprt add_stack_depth_symbol(
2929
const irep_idt identifier="$stack_depth";
3030
typet type = size_type();
3131

32-
symbolt new_symbol;
33-
new_symbol.name=identifier;
32+
symbolt new_symbol{identifier, type, ID_C};
3433
new_symbol.base_name=identifier;
3534
new_symbol.pretty_name=identifier;
36-
new_symbol.type=type;
3735
new_symbol.is_static_lifetime=true;
3836
new_symbol.value=from_integer(0, type);
39-
new_symbol.mode=ID_C;
4037
new_symbol.is_thread_local=true;
4138
new_symbol.is_lvalue=true;
4239

src/goto-instrument/uninitialized.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,12 @@ void uninitializedt::add_assertions(
8080
{
8181
const symbolt &symbol=ns.lookup(*it);
8282

83-
symbolt new_symbol;
84-
new_symbol.name=id2string(symbol.name)+"#initialized";
85-
new_symbol.type=bool_typet();
83+
symbolt new_symbol{
84+
id2string(symbol.name) + "#initialized", bool_typet(), symbol.mode};
8685
new_symbol.base_name=id2string(symbol.base_name)+"#initialized";
8786
new_symbol.location=symbol.location;
88-
new_symbol.mode=symbol.mode;
8987
new_symbol.module=symbol.module;
9088
new_symbol.is_thread_local=true;
91-
new_symbol.is_static_lifetime=false;
9289
new_symbol.is_file_local=true;
9390
new_symbol.is_lvalue=true;
9491

0 commit comments

Comments
 (0)