[cfe-dev] Inline attribute
Richard Smith
richard at metafoo.co.uk
Sun Mar 23 10:42:15 PDT 2014
On Sat, Mar 22, 2014 at 10:37 AM, Renato Golin <renato.golin at linaro.org>wrote:
> Folks,
>
> Behan sent me a piece of code in the kernel with a parsing issue in
> Clang related to attributes:
>
> This works on GCC, but not on Clang:
> typedef unsigned char u8;
> int func(int len, int mask) {
> return len + (mask & ~(__alignof__(u8 __attribute__ ((aligned))) - 1));
> }
>
> Clang's warning on the first is:
> * 'aligned' attribute ignored when parsing type
>
> This fixes on Clang, too:
> typedef unsigned char u8;
> int func(int len, int mask) {
> typedef u8 __attribute__ ((aligned)) u8_aligned;
> return len + (mask & ~(__alignof__(u8_aligned) - 1));
> }
>
> I'm guessing Clang doesn't like inlined attributes. Is there a reason
> why this is not implemented, or is this just a case that nobody has
> seen before?
>
> If the former, what reason? If the latter, how simple would it be to
> implement it?
This essentially is a design difference. Clang does not really have an
'aligned' attribute on types, it has an 'aligned' attribute on declarations
(including typedef declarations). Adding support for this is possible, but
it's a poorly-designed feature, especially when it interacts with C++ (the
attribute is *not* part of the canonical type, and GCC silently ignores it
in lots of places), so I'd be somewhat hesitant. We could probably support
it in the operand of __alignof__ as a special case.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140323/95cd93d0/attachment.html>
More information about the cfe-dev
mailing list