[PATCH] D150528: [Clang] Fix the diagnoses when the argument to alignas is an incomplete type

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 15 10:48:42 PDT 2023


aaron.ballman added a subscriber: erichkeane.
aaron.ballman added a comment.

In D150528#4342646 <https://reviews.llvm.org/D150528#4342646>, @yronglin wrote:

> In D150528#4342600 <https://reviews.llvm.org/D150528#4342600>, @aaron.ballman wrote:
>
>> In D150528#4342535 <https://reviews.llvm.org/D150528#4342535>, @yronglin wrote:
>>
>>> Thanks a lot for your review @aaron.ballman ! BTW, does the most good approach is that we just add a new `ParsedAttribute` with `TypeSourceInfo` but not an `UnaryExprOrTypeTraitExpr`, and only do a sema check same as `alignof(type-id)`?
>>
>> Because you've already got a `ParsedAttr`, I think you'd use this constructor: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Sema/ParsedAttr.h#L274 and move the call to `GetTypeFromParser()` until later, but it should still be modelled as a `UnaryExprOrTypeTraitExpr`.
>
> Many thanks for the tips, I think the next step is to build `UnaryExprOrTypeTraitExpr ` in this place (https://github.com/llvm/llvm-project/blob/9715af434579022b5ef31781be40b722d7e63bee/clang/lib/Sema/SemaDeclAttr.cpp#L4335-L4358) and then calculate the alignment? If this approach is correct, I'm glad to investigate it.

Hmm, not quite. Roping in @erichkeane in case he's got other ideas, but I think this will be more involved. What I think needs to happen is:

- We need to add another argument to `Aligned` in Attr.td so that the attribute takes either an expression argument or a type argument.
- We need to update SemaDeclAttr.cpp and other places accordingly
- We need to add an overload of `Sema::AddAlignedAttr()` that takes a `ParsedType` and call this overload when given `alignas(type)`
- We need to add code to TreeTransform.h to instantiate a dependent type so we can support `template <typename Ty> alignas(Ty) int foo = 12;`

Your approach of creating a `UnaryExprOrTypeTraitExpr` would still end up having us model as `alignas(alignof(type))` because the argument to the `alignas` attribute would be the type trait.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150528



More information about the cfe-commits mailing list