From 0616171c89d3db651b6842338fdf2da9da885aa1 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 12 Feb 2019 11:25:22 +0100 Subject: Do not expand type names when floating attributes "up" a declaration During elaboration of type declarators, non-type-related attributes such as "aligned" or "section" are "floated up" so that they apply to the thing being declared. For example, consider: ``` __attribute((aligned(16))) int * p; ``` The attribute is first attached to type `int`, then floated up to type `int *`, so that it finally applies to `p`, giving a 16-aligned pointer to int, and not a naturally-aligned pointer to 16-aligned int. What happens when the non-type-related attribute comes from a typedef? ``` typedef __attribute((aligned(16))) int i16; i16 * p; ``` CompCert used to expand the typedef then float up the attribute, resulting in `p` being a 16-aligned pointer to int. GCC and Clang produce a naturally-aligned pointer, so they do not expand the typedef before floating. The old CompCert behavior is somewhat surprising, and potentially less useful than the GCC/Clang behavior. This commit changes the floating up of non-type-related attributes so that typedefs and struct/union/enum definitions are not expanded when determining which attributes to float up. This is a first step towards mimicking the GCC/Clang behavior. --- cparser/Cutil.mli | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cparser/Cutil.mli') diff --git a/cparser/Cutil.mli b/cparser/Cutil.mli index dc9dc0cc..a99bf3af 100644 --- a/cparser/Cutil.mli +++ b/cparser/Cutil.mli @@ -50,6 +50,8 @@ val remove_custom_attributes : string list -> attributes -> attributes in the given list of names. *) val attributes_of_type : Env.t -> typ -> attributes (* Return the attributes of the given type, expanding typedefs if needed. *) +val attributes_of_type_no_expand : typ -> attributes + (* Return the attributes of the given type, without expanding typedefs. *) val add_attributes_type : attributes -> typ -> typ (* Add the given set of attributes to those of the given type. *) val remove_attributes_type : Env.t -> attributes -> typ -> typ -- cgit