Skip to content

Commit 7f12c59

Browse files
author
Daniel Kroening
committed
introduce union_tag type instead of symbol_type
1 parent ae328f3 commit 7f12c59

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

src/ansi-c/c_typecheck_type.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,11 +820,21 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
820820
}
821821
}
822822

823-
symbol_typet symbol_type(identifier);
824-
symbol_type.add_source_location()=type.source_location();
825-
826823
c_qualifierst original_qualifiers(type);
827-
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+
828838
original_qualifiers.write(type);
829839
}
830840

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 15 additions & 4 deletions
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(

0 commit comments

Comments
 (0)