Skip to content

Commit

Permalink
Check that only unnamed structs and unions are allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
cadmic committed Dec 30, 2024
1 parent 2f3fb59 commit 0df6d3d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gcc/c-decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5690,6 +5690,21 @@ grokfield (filename, line, declarator, declspecs, width)
{
tree value;

if (declarator == NULL_TREE && width == NULL_TREE)
{
/* This is an unnamed decl. We only support unnamed
structs/unions, so check for other things and refuse them. */
tree type = TREE_VALUE (declspecs);

if (TREE_CODE (type) == TYPE_DECL)
type = TREE_TYPE (type);
if (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE)
{
error ("unnamed fields of type other than struct or union are not allowed");
return NULL_TREE;
}
}

/* The corresponding pop_obstacks is in finish_decl. */
push_obstacks_nochange ();

Expand Down

0 comments on commit 0df6d3d

Please sign in to comment.