fix: do not ignore struct/union/enum type attributes
commitc61fdb6906ad145f5eac7d11422cd0916fbe7767
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Sat, 20 Jan 2018 11:11:14 +0000 (20 12:11 +0100)
committerDan Carpenter <dan.carpenter@oracle.com>
Mon, 5 Mar 2018 12:20:30 +0000 (5 15:20 +0300)
tree788e7cfd7573199b67308cb0b3659fe8add9af1e
parent0d14eb0357fd38d2f640afbcea9d1f55de59cb13
fix: do not ignore struct/union/enum type attributes

GCC's syntax for type attributes is specified as:
    An attribute specifier list may appear as part of a struct,
    union or enum specifier. It may go either immediately after
    the struct, union or enum keyword, or after the closing brace.
    The former syntax is preferred. Where attribute specifiers
    follow the closing brace, they are considered to relate to
    the structure, union or enumerated type defined, not to any
    enclosing declaration the type specifier appears in, and the type
    defined is not complete until after the attribute specifiers.
In the section about type attributes, it's also said:
    You may specify type attributes in an enum, struct or union type
    declaration or definition by placing them immediately after the
    struct, union or enum keyword. A less preferred syntax is to
    place them just past the closing curly brace of the definition.

So, while placing the attribute after the closing curly is not
preferred, it is cleary legal (and it seems to be much more popular
than placing them just after the struct, union or enum keyword).

However, currently sparse doesn't handle this correctly:
- these attributes are parsed in declaration_specifiers() and
  added to the current decl_state
- when the ';' ending the type declaration is reached, the plain
  struct/union/enum is used and the content of the decl_state is
  simply ignored.
- if the declaration is for a variable, then those attributes
  are assigned to the variable (but not to the type).

Fix this by calling handle_attribute() once we have reached the
closing '}' of a struct/union/enum definition and applying these
attributes, if any, directly to the current base type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
parse.c
validation/type-attribute-align.c
validation/type-attribute-as.c
validation/type-attribute-mod.c