On Mon, 2 May 2022, David Faust via Gcc-patches wrote: > Consider the following example: > > #define __typetag1 __attribute__((btf_type_tag("tag1"))) > #define __typetag2 __attribute__((btf_type_tag("tag2"))) > #define __typetag3 __attribute__((btf_type_tag("tag3"))) > > int __typetag1 * __typetag2 __typetag3 * g; > > The expected behavior is that 'g' is "a pointer with tags 'tag2' and 'tag3', > to a pointer with tag 'tag1' to an int". i.e.:
That's not a correct expectation for either GNU __attribute__ or C2x [[]] attribute syntax. In either syntax, __typetag2 __typetag3 should apply to the type to which g points, not to g or its type, just as if you had a type qualifier there. You'd need to put the attributes (or qualifier) after the *, not before, to make them apply to the pointer type. See "Attribute Syntax" in the GCC manual for how the syntax is defined for GNU attributes and deduce in turn, for each subsequence of the tokens matching the syntax for some kind of declarator, what the type for "T D1" would be as defined there and in the C standard, as deduced from the type for "T D" for a sub-declarator D. > But GCC's attribute parsing produces a variable 'g' which is "a pointer with > tag 'tag1' to a pointer with tags 'tag2' and 'tag3' to an int", i.e. In GNU syntax, __typetag1 applies to the declaration, whereas in C2x syntax it applies to int. Again, if you wanted it to apply to the pointer type it would need to go after the * not before. If you are concerned with the fine details of what construct an attribute appertains to, I recommend using C2x syntax not GNU syntax. -- Joseph S. Myers jos...@codesourcery.com