[clang] [CLANG] Enable alignas after GNU attributes (PR #133107)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 28 03:17:34 PDT 2025


DenisGZM wrote:

> At a glance this _does_ seem like the right place to do this, but this is still missing a release note.
> 
> It seems like GCC allows e.g. `__attribute__(()) alignas(16) int x` in any case, so I don’t see why we shouldn’t allow this too. Can you also add some tests that use `__attribute__(())` directly and which aren’t CUDA-specific?
> 
> Oh, and can you add solmething like this as a test as well:
> 
> ```c++
> struct S { __attribute__((deprecated)) alignas(16) int x; };
> ```

Actually this test doesn't work with this patch...

In this case all attributes are processed in `ParseDeclarationSpecifiers`, which in my first view was the right place to fix, but has way more complicated logic and easy to break diagnostics.

In `ParseDeclarationSpecifiers` we parse kw__attributes and other CXX11 Attributes and set bool AttrsLastTime = true to check that last parsed piece was attr. Later this block prohibit attributes with AttrsLastTime = false,
```
    DoneWithDeclSpec:
      if (!AttrsLastTime)
        ProhibitAttributes(attrs);
```
And AttrsLastTime is always false in declarations of the form: <attributes> <type> <identifier>

Another approach i tried is to add processing alignas-cxx11 just like it is done for C: kw__Alignas and kw_alignas (c23).
Well, it do the parsing but later it skips CXX11 attributes when correcting declaration type (assumed that attributes must have been processed before)






https://github.com/llvm/llvm-project/pull/133107


More information about the cfe-commits mailing list