[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

Jerin Philip via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 22 11:44:15 PDT 2023


jerinphilip wrote:

I have rebased the PR with main (which appears to fix the formatting workflow). For the time being, I have left the C23 test using `alignas` in with the active error message and a `FIXME`.

I've altered the state of this PR to be close to [D141177](https://reviews.llvm.org/D141177), using the existing attribute warning for reduced complexity (happy to provide attribution). Key difference `isAlignas` instead of `isC23AlignasAttribute()`, thinking the former should be more future-proof. In the current state, `isCXX11Attribute()` and `isStandardAttributeSyntax()` is not modified, and the net improvement (in diagnostics) in changes here should be useful when C23 `alignas` comes in, I hope.

The following routes were also considered:

1. Store `tok::TokenKind` to resolve `_Alignas` vs `alignas`. This requires adding one more field to `Form` and `AttributeCommonInfo`, while the information is already present via (`IsAlignas`, `SpellingIndex`) tuple (This approach is in [jerinphilip/llvm-project#1](https://github.com/jerinphilip/llvm-project/pull/1) mixed with other things). 
2. Use `calculateAttributeSpellingIndex` (also discussed in meeting). This suffers from inability to use `AlignedAttr::Keyword_Alignas` (`clang/AST/Attrs.h`) - See [#65638 (comment)](https://github.com/llvm/llvm-project/pull/65638#discussion_r1367880789). Absent this, the `SpellingIndex` value `5` (`Keyword_Alignas`) will have to be maintained separately here to resolve `_Alignas`. Looking at the source requires string operations, which are inefficient.

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


More information about the cfe-commits mailing list