Skip to content

Commit 5c0a922

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 b9ce2d4 commit 5c0a922

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
@@ -1250,12 +1250,10 @@ symbolt acceleration_utilst::fresh_symbol(std::string base, typet type)
12501250
static int num_symbols=0;
12511251

12521252
std::string name=base + "_" + std::to_string(num_symbols++);
1253-
symbolt ret;
1253+
symbolt ret{name, std::move(type), irep_idt{}};
12541254
ret.module="scratch";
1255-
ret.name=name;
12561255
ret.base_name=name;
12571256
ret.pretty_name=name;
1258-
ret.type=type;
12591257

12601258
symbol_table.add(ret);
12611259

src/goto-instrument/contracts/contracts.cpp

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

13131313
// Place a new symbol with the mangled name into the symbol table
1314-
symbolt mangled_sym;
1314+
source_locationt sl;
1315+
sl.set_file("instrumented for code contracts");
1316+
sl.set_line("0");
13151317
const symbolt *original_sym = symbol_table.lookup(original);
1316-
mangled_sym = *original_sym;
1318+
symbolt mangled_sym = *original_sym;
13171319
mangled_sym.name = mangled;
13181320
mangled_sym.base_name = mangled;
1319-
mangled_sym.location = original_sym->location;
1321+
mangled_sym.location = sl;
13201322
const auto mangled_found = symbol_table.insert(std::move(mangled_sym));
13211323
INVARIANT(
13221324
mangled_found.second,

src/goto-instrument/function.cpp

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

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

4146
const code_typet function_type({code_typet::parametert(p)}, empty_typet());
4247

43-
symbolt new_symbol;
44-
new_symbol.name=id;
48+
symbolt new_symbol{id, function_type, irep_idt{}};
4549
new_symbol.base_name=id;
46-
new_symbol.type=function_type;
4750

4851
symbol_table.insert(std::move(new_symbol));
4952

5053
s_it=symbol_table.symbols.find(id);
5154
assert(s_it!=symbol_table.symbols.end());
55+
#endif
5256
}
5357

5458
// 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
@@ -1867,10 +1867,8 @@ void goto_program2codet::cleanup_expr(exprt &expr, bool no_typecast)
18671867
base_name="nondet_"+std::to_string(count);
18681868
}
18691869

1870-
symbolt symbol;
1870+
symbolt symbol{base_name, code_typet({}, expr.type()), ID_C};
18711871
symbol.base_name=base_name;
1872-
symbol.name=base_name;
1873-
symbol.type = code_typet({}, expr.type());
18741872
id=symbol.name;
18751873

18761874
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
@@ -75,10 +75,9 @@ const symbolt &w_guardst::get_guard_symbol(const irep_idt &object)
7575

7676
w_guards.push_back(identifier);
7777

78-
symbolt new_symbol;
79-
new_symbol.name=identifier;
78+
symbolt new_symbol{
79+
identifier, bool_typet(), symbol_table.lookup_ref(object).mode};
8080
new_symbol.base_name=identifier;
81-
new_symbol.type=bool_typet();
8281
new_symbol.is_static_lifetime=true;
8382
new_symbol.value=false_exprt();
8483

src/goto-instrument/stack_depth.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ static symbol_exprt add_stack_depth_symbol(
2828
const irep_idt identifier="$stack_depth";
2929
unsignedbv_typet type(sizeof(std::size_t)*8);
3030

31-
symbolt new_symbol;
32-
new_symbol.name=identifier;
31+
symbolt new_symbol{identifier, type, ID_C};
3332
new_symbol.base_name=identifier;
3433
new_symbol.pretty_name=identifier;
35-
new_symbol.type=type;
3634
new_symbol.is_static_lifetime=true;
3735
new_symbol.value=from_integer(0, type);
38-
new_symbol.mode=ID_C;
3936
new_symbol.is_thread_local=true;
4037
new_symbol.is_lvalue=true;
4138

src/goto-instrument/uninitialized.cpp

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

87-
symbolt new_symbol;
88-
new_symbol.name=id2string(symbol.name)+"#initialized";
89-
new_symbol.type=bool_typet();
87+
symbolt new_symbol{
88+
id2string(symbol.name) + "#initialized", bool_typet(), symbol.mode};
9089
new_symbol.base_name=id2string(symbol.base_name)+"#initialized";
9190
new_symbol.location=symbol.location;
92-
new_symbol.mode=symbol.mode;
9391
new_symbol.module=symbol.module;
9492
new_symbol.is_thread_local=true;
95-
new_symbol.is_static_lifetime=false;
9693
new_symbol.is_file_local=true;
9794
new_symbol.is_lvalue=true;
9895

0 commit comments

Comments
 (0)