From d7dfc21c20f55b705e3e749c2c7b31f9a4611c39 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 12 Feb 2019 11:49:23 +0100 Subject: Distinguish object-related and name-related attributes This is a second step towards mimicking GCC/Clang's handling of attributes. This commit introduces a distinction between - Object-related attributes, such as "section", which apply to the object (function, variable) being defined; - Name-related attributes, such as "aligned", which apply to the name (object, struct/union member, struct/union/enum tag) being defined. In particular, "aligned" is now attached to "struct" and "union" definitions, while it used to be "floated up" before. The C11 _Alignas modifier is treated like an object-related attribute, so that ``` struct s { ... }; _Alignas(64) struct s x; ``` correctly associates the alignment with "x" and not with "struct s", where it would be ignored because it was not part of the original definition of s. --- cparser/Cutil.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cparser/Cutil.ml') diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index b926e84a..25329694 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -95,7 +95,10 @@ let rec remove_custom_attributes (names: string list) (al: attributes) = (* Classification of attributes *) type attribute_class = - | Attr_name (* Attribute applies to the names being declared *) + | Attr_object (* Attribute applies to the object being declared + (function, global variable, local variable) *) + | Attr_name (* Attribute applies to the name being declared + (object, struct/union member, struct/union/enum tag *) | Attr_type (* Attribute applies to types *) | Attr_struct (* Attribute applies to struct, union and enum *) | Attr_function (* Attribute applies to function types and decls *) @@ -111,7 +114,7 @@ let declare_attributes l = let class_of_attribute = function | AConst | AVolatile | ARestrict -> Attr_type - | AAlignas _ -> Attr_name + | AAlignas _ -> Attr_object | Attr(name, args) -> try Hashtbl.find attr_class (normalize_attrname name) with Not_found -> Attr_unknown -- cgit