Skip to content

Add CoW base to value-set #3053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/pointer-analysis/value_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ bool value_sett::field_sensitive(
return ns.follow(type).id()==ID_struct;
}

const value_sett::entryt *value_sett::find_entry(const value_sett::idt &id)
const
{
auto found = values.find(id);
return found == values.end() ? nullptr : &found->second;
}

value_sett::entryt &value_sett::get_entry(
const entryt &e,
const typet &type,
Expand Down Expand Up @@ -429,31 +436,29 @@ void value_sett::get_value_set_rec(
expr_type.id()==ID_array)
{
// look it up
valuest::const_iterator v_it=
values.find(id2string(identifier)+suffix);
const entryt *entry =
find_entry(id2string(identifier) + suffix);

// try first component name as suffix if not yet found
if(v_it==values.end() &&
(expr_type.id()==ID_struct ||
expr_type.id()==ID_union))
if(!entry && (expr_type.id() == ID_struct || expr_type.id() == ID_union))
{
const struct_union_typet &struct_union_type=
to_struct_union_type(expr_type);

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

v_it = values.find(
entry = find_entry(
id2string(identifier) + "." + id2string(first_component_name) +
suffix);
}

// not found? try without suffix
if(v_it==values.end())
v_it=values.find(identifier);
if(!entry)
entry = find_entry(identifier);

if(v_it!=values.end())
make_union(dest, v_it->second.object_map);
if(entry)
make_union(dest, entry->object_map);
else
insert(dest, exprt(ID_unknown, original_type));
}
Expand Down Expand Up @@ -857,16 +862,16 @@ void value_sett::get_value_set_rec(
const std::string full_name=prefix+suffix;

// look it up
valuest::const_iterator v_it=values.find(full_name);
const entryt *entry = find_entry(full_name);

// not found? try without suffix
if(v_it==values.end())
v_it=values.find(prefix);
if(!entry)
entry = find_entry(prefix);

if(v_it==values.end())
if(!entry)
insert(dest, exprt(ID_unknown, original_type));
else
make_union(dest, v_it->second.object_map);
make_union(dest, entry->object_map);
}
else if(expr.id()==ID_byte_extract_little_endian ||
expr.id()==ID_byte_extract_big_endian)
Expand Down
9 changes: 9 additions & 0 deletions src/pointer-analysis/value_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ class value_sett
values.clear();
}

/// Finds an entry in this value-set. The interface differs from get_entry
/// because get_value_set_rec wants to check for a struct's first component
/// before stripping the suffix as is done in get_entry.
/// \param id: identifier to find.
/// \return a constant pointer to an entry if found, or null otherwise.
/// Note the pointer may be invalidated by insert operations, including
/// get_entry.
const entryt *find_entry(const idt &id) const;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would optionalt be a possibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference: T * not optionalt<reference_wrapper<T>>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about optionalt<T *>? It would more clearly express the intent and remove the role of nullptr as a sentinel value that can accidentally be dereferenced.


/// Gets or inserts an entry in this value-set.
/// \param e: entry to find. Its `id` and `suffix` fields will be used
/// to find a corresponding entry; if a fresh entry is created its
Expand Down