[PATCH] D143533: [clang] Allow gnu::aligned attribute to work with templated type alias declarations

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 7 16:00:07 PST 2023


leonardchan created this revision.
leonardchan added reviewers: rsmith, rnk, echristo.
leonardchan added a project: clang.
Herald added a subscriber: jeroen.dobbelaere.
Herald added a project: All.
leonardchan requested review of this revision.

Prior to this, the following would fail:

  template <typename T>
  using NaturallyAligned [[gnu::aligned(sizeof(T))]] = T;
  
  struct S { char x[2]; };
  using AlignedS = NaturallyAligned<S>;
  static_assert(alignof(AlignedS) == 2);  // alignof(AlignedS) == 1

This is because clang ignores attributes on type aliases when evaluating type info and instead resolves to alignment of the replacement type `T`.

This patch attempts to check if the associated type declaration is an alias that contains an attribute and return whatever the value is indicated by the alignment expression.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143533

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/SemaTemplate/type-alias-aligned.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143533.495670.patch
Type: text/x-patch
Size: 7586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230208/5ad3a097/attachment.bin>


More information about the cfe-commits mailing list