Skip to content

Commit 48e1e6c

Browse files
committed
Value set: indirect values.find operations via a helper function
This means when the underlying datastructure changes we don't have to update several users.
1 parent 03126ae commit 48e1e6c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/pointer-analysis/value_set.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ bool value_sett::field_sensitive(
5151
return ns.follow(type).id()==ID_struct;
5252
}
5353

54+
const value_sett::entryt *value_sett::find_entry(const value_sett::idt &id)
55+
const
56+
{
57+
auto found = values.find(id);
58+
return found == values.end() ? nullptr : &found->second;
59+
}
60+
5461
value_sett::entryt &value_sett::get_entry(
5562
const entryt &e,
5663
const typet &type,
@@ -429,31 +436,29 @@ void value_sett::get_value_set_rec(
429436
expr_type.id()==ID_array)
430437
{
431438
// look it up
432-
valuest::const_iterator v_it=
433-
values.find(id2string(identifier)+suffix);
439+
const entryt *entry =
440+
find_entry(id2string(identifier) + suffix);
434441

435442
// try first component name as suffix if not yet found
436-
if(v_it==values.end() &&
437-
(expr_type.id()==ID_struct ||
438-
expr_type.id()==ID_union))
443+
if(!entry && (expr_type.id() == ID_struct || expr_type.id() == ID_union))
439444
{
440445
const struct_union_typet &struct_union_type=
441446
to_struct_union_type(expr_type);
442447

443448
const irep_idt &first_component_name =
444449
struct_union_type.components().front().get_name();
445450

446-
v_it = values.find(
451+
entry = find_entry(
447452
id2string(identifier) + "." + id2string(first_component_name) +
448453
suffix);
449454
}
450455

451456
// not found? try without suffix
452-
if(v_it==values.end())
453-
v_it=values.find(identifier);
457+
if(!entry)
458+
entry = find_entry(identifier);
454459

455-
if(v_it!=values.end())
456-
make_union(dest, v_it->second.object_map);
460+
if(entry)
461+
make_union(dest, entry->object_map);
457462
else
458463
insert(dest, exprt(ID_unknown, original_type));
459464
}
@@ -857,16 +862,16 @@ void value_sett::get_value_set_rec(
857862
const std::string full_name=prefix+suffix;
858863

859864
// look it up
860-
valuest::const_iterator v_it=values.find(full_name);
865+
const entryt *entry = find_entry(full_name);
861866

862867
// not found? try without suffix
863-
if(v_it==values.end())
864-
v_it=values.find(prefix);
868+
if(!entry)
869+
entry = find_entry(prefix);
865870

866-
if(v_it==values.end())
871+
if(!entry)
867872
insert(dest, exprt(ID_unknown, original_type));
868873
else
869-
make_union(dest, v_it->second.object_map);
874+
make_union(dest, entry->object_map);
870875
}
871876
else if(expr.id()==ID_byte_extract_little_endian ||
872877
expr.id()==ID_byte_extract_big_endian)

src/pointer-analysis/value_set.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ class value_sett
317317
values.clear();
318318
}
319319

320+
/// Finds an entry in this value-set. The interface differs from get_entry
321+
/// because get_value_set_rec wants to check for a struct's first component
322+
/// before stripping the suffix as is done in get_entry.
323+
/// \param id: identifier to find.
324+
/// \return a constant pointer to an entry if found, or null otherwise.
325+
/// Note the pointer may be invalidated by insert operations, including
326+
/// get_entry.
327+
const entryt *find_entry(const idt &id) const;
328+
320329
/// Gets or inserts an entry in this value-set.
321330
/// \param e: entry to find. Its `id` and `suffix` fields will be used
322331
/// to find a corresponding entry; if a fresh entry is created its

0 commit comments

Comments
 (0)