Skip to content

Commit 46cbe9e

Browse files
author
Daniel Kroening
committed
follow union, struct and enum tags
1 parent 99e33bd commit 46cbe9e

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

src/ansi-c/c_typecast.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -252,21 +252,22 @@ bool check_c_implicit_typecast(
252252

253253
typet c_typecastt::follow_with_qualifiers(const typet &src_type)
254254
{
255-
if(src_type.id()!=ID_symbol)
255+
if(
256+
src_type.id() != ID_symbol && src_type.id() != ID_struct_tag &&
257+
src_type.id() != ID_union_tag)
256258
return src_type;
257259

258260
typet result_type=src_type;
259261

260262
// collect qualifiers
261263
c_qualifierst qualifiers(src_type);
262264

263-
while(result_type.id()==ID_symbol)
265+
while(result_type.id() == ID_symbol || result_type.id() == ID_struct_tag ||
266+
result_type.id() == ID_union_tag)
264267
{
265-
const symbolt &followed_type_symbol =
266-
ns.lookup(to_symbol_type(result_type));
267-
268-
result_type=followed_type_symbol.type;
269-
qualifiers+=c_qualifierst(followed_type_symbol.type);
268+
const typet &followed_type = ns.follow(result_type);
269+
result_type = followed_type;
270+
qualifiers += c_qualifierst(followed_type);
270271
}
271272

272273
qualifiers.write(result_type);

src/ansi-c/c_typecheck_expr.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ void c_typecheck_baset::typecheck_expr_builtin_offsetof(exprt &expr)
524524

525525
forall_operands(m_it, member)
526526
{
527-
if(type.id()==ID_symbol)
528-
type=follow(type);
527+
type = follow(type);
529528

530529
if(m_it->id()==ID_member)
531530
{

src/ansi-c/padding.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ mp_integer alignment(const typet &type, const namespacet &ns)
8282
result=alignment(type.subtype(), ns);
8383
else if(type.id()==ID_c_enum_tag)
8484
result=alignment(ns.follow_tag(to_c_enum_tag_type(type)), ns);
85+
else if(type.id() == ID_struct_tag)
86+
result = alignment(ns.follow_tag(to_struct_tag_type(type)), ns);
87+
else if(type.id() == ID_union_tag)
88+
result = alignment(ns.follow_tag(to_union_tag_type(type)), ns);
8589
else if(type.id()==ID_symbol)
8690
result=alignment(ns.follow(type), ns);
8791
else if(type.id()==ID_c_bit_field)

src/util/namespace.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ const symbolt &namespace_baset::lookup(const tag_typet &type) const
5454

5555
const typet &namespace_baset::follow(const typet &src) const
5656
{
57+
if(src.id() == ID_union_tag)
58+
return follow_tag(to_union_tag_type(src));
59+
60+
if(src.id() == ID_struct_tag)
61+
return follow_tag(to_struct_tag_type(src));
62+
5763
if(src.id()!=ID_symbol)
5864
return src;
5965

src/util/pointer_offset_size.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,14 @@ mp_integer pointer_offset_bits(
238238
{
239239
return pointer_offset_bits(ns.follow(type), ns);
240240
}
241+
else if(type.id() == ID_union_tag)
242+
{
243+
return pointer_offset_bits(ns.follow_tag(to_union_tag_type(type)), ns);
244+
}
245+
else if(type.id() == ID_struct_tag)
246+
{
247+
return pointer_offset_bits(ns.follow_tag(to_struct_tag_type(type)), ns);
248+
}
241249
else if(type.id()==ID_code)
242250
{
243251
return 0;
@@ -506,6 +514,14 @@ exprt size_of_expr(
506514
{
507515
return size_of_expr(ns.follow(type), ns);
508516
}
517+
else if(type.id() == ID_union_tag)
518+
{
519+
return size_of_expr(ns.follow_tag(to_union_tag_type(type)), ns);
520+
}
521+
else if(type.id() == ID_struct_tag)
522+
{
523+
return size_of_expr(ns.follow_tag(to_struct_tag_type(type)), ns);
524+
}
509525
else if(type.id()==ID_code)
510526
{
511527
return from_integer(0, size_type());

0 commit comments

Comments
 (0)