Skip to content

Commit 2542d0d

Browse files
authored
Merge pull request #2697 from diffblue/union_tag
Introduce union tag type
2 parents f3dd86d + 7f12c59 commit 2542d0d

File tree

4 files changed

+57
-11
lines changed

4 files changed

+57
-11
lines changed

src/ansi-c/c_typecheck_type.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ void c_typecheck_baset::typecheck_type(typet &type)
9393
typecheck_symbol_type(to_symbol_type(type));
9494
else if(type.id() == ID_typedef_type)
9595
typecheck_typedef_type(type);
96+
else if(type.id() == ID_struct_tag ||
97+
type.id() == ID_union_tag)
98+
{
99+
// nothing to do, these stay as is
100+
}
96101
else if(type.id()==ID_vector)
97102
typecheck_vector_type(to_vector_type(type));
98103
else if(type.id()==ID_custom_unsignedbv ||
@@ -815,11 +820,21 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
815820
}
816821
}
817822

818-
symbol_typet symbol_type(identifier);
819-
symbol_type.add_source_location()=type.source_location();
820-
821823
c_qualifierst original_qualifiers(type);
822-
type.swap(symbol_type);
824+
825+
if(type.id() == ID_union)
826+
{
827+
union_tag_typet tag_type(identifier);
828+
tag_type.add_source_location() = type.source_location();
829+
type.swap(tag_type);
830+
}
831+
else
832+
{
833+
symbol_typet symbol_type(identifier);
834+
symbol_type.add_source_location() = type.source_location();
835+
type.swap(symbol_type);
836+
}
837+
823838
original_qualifiers.write(type);
824839
}
825840

src/cpp/cpp_typecheck_compound_type.cpp

+15-4
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ void cpp_typecheckt::typecheck_compound_type(
135135
cpp_scopet *dest_scope=nullptr;
136136
bool has_body=type.find(ID_body).is_not_nil();
137137
bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);
138+
bool is_union = type.id() == ID_union;
138139

139140
if(!has_tag)
140141
{
@@ -263,10 +264,20 @@ void cpp_typecheckt::typecheck_compound_type(
263264
}
264265
}
265266

266-
// create type symbol
267-
symbol_typet symbol_type(symbol_name);
268-
qualifiers.write(symbol_type);
269-
type.swap(symbol_type);
267+
if(is_union)
268+
{
269+
// create union tag
270+
union_tag_typet tag_type(symbol_name);
271+
qualifiers.write(tag_type);
272+
type.swap(tag_type);
273+
}
274+
else
275+
{
276+
// create type symbol
277+
symbol_typet symbol_type(symbol_name);
278+
qualifiers.write(symbol_type);
279+
type.swap(symbol_type);
280+
}
270281
}
271282

272283
void cpp_typecheckt::typecheck_compound_declarator(

src/cpp/cpp_typecheck_type.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ void cpp_typecheckt::typecheck_type(typet &type)
189189
else if(type.id() == ID_symbol_type)
190190
{
191191
}
192+
else if(type.id() == ID_struct_tag)
193+
{
194+
}
195+
else if(type.id() == ID_union_tag)
196+
{
197+
}
192198
else if(type.id()==ID_constructor ||
193199
type.id()==ID_destructor)
194200
{

src/goto-symex/goto_symex_state.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,10 @@ void goto_symex_statet::rename_address(
760760

761761
// type might not have been renamed in case of nesting of
762762
// structs and pointers/arrays
763-
if(member_expr.struct_op().type().id() != ID_symbol_type)
763+
if(
764+
member_expr.struct_op().type().id() != ID_symbol_type &&
765+
member_expr.struct_op().type().id() != ID_struct_tag &&
766+
member_expr.struct_op().type().id() != ID_union_tag)
764767
{
765768
const struct_union_typet &su_type=
766769
to_struct_union_type(member_expr.struct_op().type());
@@ -845,8 +848,19 @@ void goto_symex_statet::rename(
845848
}
846849
else if(type.id() == ID_symbol_type)
847850
{
848-
const symbolt &symbol=
849-
ns.lookup(to_symbol_type(type).get_identifier());
851+
const symbolt &symbol = ns.lookup(to_symbol_type(type));
852+
type = symbol.type;
853+
rename(type, l1_identifier, ns, level);
854+
}
855+
else if(type.id() == ID_union_tag)
856+
{
857+
const symbolt &symbol = ns.lookup(to_union_tag_type(type));
858+
type = symbol.type;
859+
rename(type, l1_identifier, ns, level);
860+
}
861+
else if(type.id() == ID_struct_tag)
862+
{
863+
const symbolt &symbol = ns.lookup(to_struct_tag_type(type));
850864
type=symbol.type;
851865
rename(type, l1_identifier, ns, level);
852866
}

0 commit comments

Comments
 (0)