Skip to content

Commit 81320e1

Browse files
committed
Reverse to global_state being optional, local_state being required
1 parent 7f7b2f7 commit 81320e1

File tree

3 files changed

+37
-38
lines changed

3 files changed

+37
-38
lines changed

src/goto-symex/path_storage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class path_storaget
9090
/// Counter for nondet objects, which require unique names
9191
symex_nondet_generatort build_symex_nondet;
9292

93+
/// Storage for overall level two names across an entire symex run. This will
94+
/// be shared across all states to allocate unique generations.
95+
symex_renaming_levelt::current_namest level2_names;
96+
9397
private:
9498
// Derived classes should override these methods, allowing the base class to
9599
// enforce preconditions.

src/goto-symex/renaming_level.h

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Author: Romain Brenguier, [email protected]
1414

1515
#include <map>
1616
#include <unordered_set>
17-
#include <memory>
1817

1918
#include <util/irep.h>
2019
#include <util/ssa_expr.h>
@@ -87,29 +86,12 @@ struct symex_level2t : public symex_renaming_levelt
8786
symex_level2t() = default;
8887
~symex_level2t() override = default;
8988

90-
/// In the case of a state split, we want to keep track of the overall
91-
/// name generation across all states for identifier creation.
92-
optionalt<current_namest> local_generations;
89+
optionalt<current_namest> global_names;
9390

9491
void erase(const irep_idt &identifier)
9592
{
93+
// We don't want to erase anything from the global scope if it exists.
9694
current_names->erase(identifier);
97-
if (local_generations)
98-
local_generations->erase(identifier);
99-
}
100-
101-
/// If we have a local counter, use that instead of our global.
102-
unsigned current_count(const irep_idt &identifier) const override
103-
{
104-
if(local_generations)
105-
{
106-
const auto it = local_generations->find(identifier);
107-
return it == local_generations->end() ? 0 : it->second.second;
108-
}
109-
else
110-
{
111-
return symex_renaming_levelt::current_count(identifier);
112-
}
11395
}
11496

11597
/// Ages the generation of an ssa expression by one.
@@ -118,8 +100,8 @@ struct symex_level2t : public symex_renaming_levelt
118100
const ssa_exprt &lhs)
119101
{
120102
current_names->emplace(l1_identifier, std::make_pair(lhs, 0));
121-
if (local_generations)
122-
local_generations->emplace(l1_identifier, std::make_pair(lhs, 0));
103+
if (global_names)
104+
global_names->emplace(l1_identifier, std::make_pair(lhs, 0));
123105

124106
increase_generation(l1_identifier);
125107
}
@@ -129,35 +111,47 @@ struct symex_level2t : public symex_renaming_levelt
129111
void increase_generation(
130112
const irep_idt identifier)
131113
{
114+
// If we can't find the name in the local scope, don't increase the global
115+
// even if it exists there.
132116
auto current_names_iter = current_names->find(identifier);
133117
if (current_names_iter == current_names->end())
134118
return;
135119

136-
current_names_iter->second.second++;
137-
if(local_generations)
120+
// If we have a global store, increment its generation count, then assign
121+
// that new value to our local scope.
122+
if (global_names)
138123
{
139-
auto local_iter = local_generations->find(identifier);
140-
if (local_iter != local_generations->end())
141-
local_iter->second.second = current_names_iter->second.second;
124+
auto global_names_iter = global_names->find(identifier);
125+
if (global_names_iter == global_names->end())
126+
global_names_iter->second.second++,
127+
current_names_iter->second.second = global_names_iter->second.second;
128+
}
129+
else
130+
{
131+
// Otherwise simply increase our local scope.
132+
current_names_iter->second.second++;
142133
}
143134
}
144135

145-
current_namest get_current_names()
146-
{
147-
return local_generations ? *local_generations : *current_names;
148-
}
149-
136+
/// Prints the differences between the global and local naming maps (if they
137+
/// exist)
150138
void print_differences(const std::string &differences)
151139
{
152-
if (!local_generations)
140+
if (!global_names)
153141
return;
154142

155-
for(const auto &local_gen : *local_generations)
143+
std::cout << "Printing differences between local and global generations." << '\n';
144+
145+
for(const auto &local : *current_names)
156146
{
157-
auto local = local_gen.second.second;
158-
auto global = current_names->find(local_gen.first)->second.second;
159-
if (local != global)
160-
std::cout << differences << "ID: " << id2string(local_gen.first) << ", local: " << local << " global: " << global << '\n';
147+
auto global_iter = global_names->find(local.first);
148+
if (global_iter == global_names->end())
149+
continue;
150+
151+
auto global_count = global_iter->second.second;
152+
auto local_count = local.second.second;
153+
if (global_count != local_count)
154+
std::cout << differences << "ID: " << id2string(local.first) << ", local: " << local_count << " global: " << global_count << '\n';
161155
}
162156
}
163157
};

src/goto-symex/symex_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ std::unique_ptr<goto_symext::statet> goto_symext::initialize_entry_point_state(
315315
emplace_safe_pointers_result.first->second(start_function->body);
316316

317317
state->dirty.populate_dirty_for_function(entry_point_id, *start_function);
318+
state->level2.global_names = this->path_storage.level2_names;
318319

319320
// make the first step onto the instruction pointed to by the initial program
320321
// counter

0 commit comments

Comments
 (0)