Skip to content

Commit 683efbc

Browse files
authored
Merge pull request #2926 from diffblue/struct-tag
Use struct tags
2 parents 83415a7 + 04c26c4 commit 683efbc

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

src/ansi-c/c_typecheck_code.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,12 @@ bool c_typecheck_baset::is_complete_type(const typet &type) const
383383
}
384384
else if(type.id()==ID_vector)
385385
return is_complete_type(type.subtype());
386-
else if(type.id() == ID_symbol_type)
386+
else if(
387+
type.id() == ID_symbol_type || type.id() == ID_struct_tag ||
388+
type.id() == ID_union_tag)
389+
{
387390
return is_complete_type(follow(type));
391+
}
388392

389393
return true;
390394
}

src/ansi-c/c_typecheck_type.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -822,18 +822,17 @@ void c_typecheck_baset::typecheck_compound_type(struct_union_typet &type)
822822

823823
c_qualifierst original_qualifiers(type);
824824

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-
}
825+
typet tag_type;
826+
827+
if(type.id() == ID_union || type.id() == ID_incomplete_union)
828+
tag_type = union_tag_typet(identifier);
829+
else if(type.id() == ID_struct || type.id() == ID_incomplete_struct)
830+
tag_type = struct_tag_typet(identifier);
831831
else
832-
{
833-
symbol_typet symbol_type(identifier);
834-
symbol_type.add_source_location() = type.source_location();
835-
type.swap(symbol_type);
836-
}
832+
UNREACHABLE;
833+
834+
tag_type.add_source_location() = type.source_location();
835+
type.swap(tag_type);
837836

838837
original_qualifiers.write(type);
839838
}

src/goto-instrument/dump_c.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,12 @@ void dump_ct::convert_compound(
322322
if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers))
323323
convert_compound(symbol.type, unresolved, recursive, os);
324324
}
325-
else if(type.id()==ID_c_enum_tag)
325+
else if(
326+
type.id() == ID_c_enum_tag || type.id() == ID_struct_tag ||
327+
type.id() == ID_union_tag)
326328
{
327-
const symbolt &symbol=
328-
ns.lookup(to_c_enum_tag_type(type).get_identifier());
329-
DATA_INVARIANT(symbol.is_type, "symbol expected to be type symbol");
329+
const symbolt &symbol = ns.lookup(to_tag_type(type));
330+
DATA_INVARIANT(symbol.is_type, "tag expected to be type symbol");
330331

331332
if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers))
332333
convert_compound(symbol.type, unresolved, recursive, os);
@@ -674,6 +675,13 @@ void dump_ct::collect_typedefs_rec(
674675
ns.lookup(to_symbol_type(type).get_identifier());
675676
collect_typedefs_rec(symbol.type, early, local_deps);
676677
}
678+
else if(
679+
type.id() == ID_c_enum_tag || type.id() == ID_struct_tag ||
680+
type.id() == ID_union_tag)
681+
{
682+
const symbolt &symbol = ns.lookup(to_tag_type(type));
683+
collect_typedefs_rec(symbol.type, early, local_deps);
684+
}
677685

678686
const irep_idt &typedef_str=type.get(ID_C_typedef);
679687

src/util/expr_initializer.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,23 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
291291
}
292292
else if(type_id==ID_struct_tag)
293293
{
294-
return
295-
expr_initializer_rec(
296-
ns.follow_tag(to_struct_tag_type(type)),
297-
source_location);
294+
exprt result = expr_initializer_rec(
295+
ns.follow_tag(to_struct_tag_type(type)), source_location);
296+
297+
// use the tag type
298+
result.type() = type;
299+
300+
return result;
298301
}
299302
else if(type_id==ID_union_tag)
300303
{
301-
return
302-
expr_initializer_rec(
303-
ns.follow_tag(to_union_tag_type(type)),
304-
source_location);
304+
exprt result = expr_initializer_rec(
305+
ns.follow_tag(to_union_tag_type(type)), source_location);
306+
307+
// use the tag type
308+
result.type() = type;
309+
310+
return result;
305311
}
306312
else if(type_id==ID_string)
307313
{

src/util/std_types.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ bool is_constant_or_has_constant_components(
234234
// we have to use the namespace to resolve to its definition:
235235
// struct t { const int a; };
236236
// struct t t1;
237-
if(type.id() == ID_symbol_type)
237+
if(type.id() == ID_symbol_type ||
238+
type.id() == ID_struct_tag ||
239+
type.id() == ID_union_tag)
238240
{
239241
const auto &resolved_type = ns.follow(type);
240242
return has_constant_components(resolved_type);

0 commit comments

Comments
 (0)