[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 22 13:15:20 PDT 2021


aaron.ballman added a comment.

In D110127#3013876 <https://reviews.llvm.org/D110127#3013876>, @yonghong-song wrote:

> You can see that it doesn't matter where the attribute is placed, the attribute is always attached to the typedef.
> I think the reason is for declarations, we only allow the btf_tag attribute to be placed for record, field, var, func, typedef,
> and "unsigned *" does not qualify, so the attribute is applied to typedef.

Agreed. If this attribute appertains to the type, then it goes through SemaType.cpp and may require extra work to encode the information into the type system. If it appertains to the declaration, then what's in SemaDeclAttr.cpp is fine, but then I have questions about the use of the attribute with cast notation from D110116 <https://reviews.llvm.org/D110116> where this is being used definitely as a type attribute.

One confounding factor here is that `__attribute__` will slide around to whatever makes sense. You should try your examples with `[[]]` in C2x mode as well -- the placement of the attribute syntax is strongly tied to what the attribute applies to.

>> I'm asking because this raises other questions. For example:
>>
>>   void func(int i);
>>   void func(int __attribute__((btf_tag("__user"))) i);
>>
>> Is the second a valid redeclaration of the first? Additionally:
>
> This should be okay as btf_tag is accumulative attribute.

Okay, this is sounding more and more like a declaration attribute.

>>   __attribute__((overloadable)) void func(int i) { puts("one"); }
>>   __attribute__((overloadable)) void func(int __attribute__((btf_tag("__user"))) i) { puts("two"); }
>>
>> Is this a valid overload set because of the type attribute? Along the same lines, does adding this attribute to the type cause any ABI differences in how the type is passed?
>
> btf_tag is for C only so overload function case won't happen.

That's incorrect -- Clang supports attribute overloadable in C: https://godbolt.org/z/eThKsn3zM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110127/new/

https://reviews.llvm.org/D110127



More information about the cfe-commits mailing list