Skip to content

Follow tag types #2692

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

Merged
merged 2 commits into from
Aug 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/ansi-c/c_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,21 +252,24 @@ bool check_c_implicit_typecast(

typet c_typecastt::follow_with_qualifiers(const typet &src_type)
{
if(src_type.id()!=ID_symbol)
if(
src_type.id() != ID_symbol && src_type.id() != ID_struct_tag &&
src_type.id() != ID_union_tag)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit pick: add braces below for readability.

{
return src_type;
}

typet result_type=src_type;

// collect qualifiers
c_qualifierst qualifiers(src_type);

while(result_type.id()==ID_symbol)
while(result_type.id() == ID_symbol || result_type.id() == ID_struct_tag ||
result_type.id() == ID_union_tag)
{
const symbolt &followed_type_symbol =
ns.lookup(to_symbol_type(result_type));

result_type=followed_type_symbol.type;
qualifiers+=c_qualifierst(followed_type_symbol.type);
const typet &followed_type = ns.follow(result_type);
result_type = followed_type;
qualifiers += c_qualifierst(followed_type);
}

qualifiers.write(result_type);
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)

forall_operands(m_it, member)
{
if(type.id()==ID_symbol)
type=follow(type);
type = follow(type);

if(m_it->id()==ID_member)
{
Expand Down
4 changes: 4 additions & 0 deletions src/ansi-c/padding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ mp_integer alignment(const typet &type, const namespacet &ns)
result=alignment(type.subtype(), ns);
else if(type.id()==ID_c_enum_tag)
result=alignment(ns.follow_tag(to_c_enum_tag_type(type)), ns);
else if(type.id() == ID_struct_tag)
result = alignment(ns.follow_tag(to_struct_tag_type(type)), ns);
else if(type.id() == ID_union_tag)
result = alignment(ns.follow_tag(to_union_tag_type(type)), ns);
else if(type.id()==ID_symbol)
result=alignment(ns.follow(type), ns);
else if(type.id()==ID_c_bit_field)
Expand Down
6 changes: 6 additions & 0 deletions src/util/namespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ const symbolt &namespace_baset::lookup(const tag_typet &type) const

const typet &namespace_baset::follow(const typet &src) const
{
if(src.id() == ID_union_tag)
return follow_tag(to_union_tag_type(src));

if(src.id() == ID_struct_tag)
return follow_tag(to_struct_tag_type(src));

if(src.id()!=ID_symbol)
return src;

Expand Down
16 changes: 16 additions & 0 deletions src/util/pointer_offset_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ mp_integer pointer_offset_bits(
{
return pointer_offset_bits(ns.follow(type), ns);
}
else if(type.id() == ID_union_tag)
{
return pointer_offset_bits(ns.follow_tag(to_union_tag_type(type)), ns);
}
else if(type.id() == ID_struct_tag)
{
return pointer_offset_bits(ns.follow_tag(to_struct_tag_type(type)), ns);
}
else if(type.id()==ID_code)
{
return 0;
Expand Down Expand Up @@ -506,6 +514,14 @@ exprt size_of_expr(
{
return size_of_expr(ns.follow(type), ns);
}
else if(type.id() == ID_union_tag)
{
return size_of_expr(ns.follow_tag(to_union_tag_type(type)), ns);
}
else if(type.id() == ID_struct_tag)
{
return size_of_expr(ns.follow_tag(to_struct_tag_type(type)), ns);
}
else if(type.id()==ID_code)
{
return from_integer(0, size_type());
Expand Down
6 changes: 3 additions & 3 deletions src/util/std_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,13 +553,13 @@ class struct_tag_typet:public tag_typet
}
};

/*! \brief Cast a generic typet to a \ref union_tag_typet
/*! \brief Cast a generic typet to a \ref struct_tag_typet
*
* This is an unchecked conversion. \a type must be known to be \ref
* union_tag_typet.
* struct_tag_typet.
*
* \param type Source type
* \return Object of type \ref union_tag_typet
* \return Object of type \ref struct_tag_typet
*
* \ingroup gr_std_types
*/
Expand Down