[PATCH] D143632: [clang] Handle __declspec() attributes in using

Tobias Hieta via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 9 02:01:16 PST 2023


thieta created this revision.
thieta added reviewers: aaron.ballman, rsmith, tbaeder, saudi.
Herald added a project: All.
thieta requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes so that declspec attributes are forwarded
to the alias declaration.

Before this patch this would assert:

class Test { int a; };
using AlignedTest = __declspec(align(16)) const Test;
static_assert(alignof(AlignedTest) == 16, "error");

But afterwards it behaves the same as MSVC does and doesn't
assert.

Fixes: llvm/llvm-project#60513


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143632

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/SemaCXX/using-declspec.cpp


Index: clang/test/SemaCXX/using-declspec.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/using-declspec.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fms-compatibility -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+struct Test { int a; };
+using AlignedTest = __declspec(align(16)) const Test;
+static_assert(alignof(AlignedTest) == 16, "error");
\ No newline at end of file
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -56,6 +56,15 @@
   if (OwnedType)
     *OwnedType = DS.isTypeSpecOwned() ? DS.getRepAsDecl() : nullptr;
 
+  // Move declspec attributes to ParsedAttributes
+  llvm::SmallVector<ParsedAttr *, 1> ToBeMoved;
+  for (ParsedAttr &AL : DS.getAttributes())
+    if (AL.isDeclspecAttribute())
+      ToBeMoved.push_back(&AL);
+
+  for (ParsedAttr *AL : ToBeMoved)
+    Attrs->takeOneFrom(DS.getAttributes(), AL);
+
   // Parse the abstract-declarator, if present.
   Declarator DeclaratorInfo(DS, ParsedAttributesView::none(), Context);
   ParseDeclarator(DeclaratorInfo);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143632.496051.patch
Type: text/x-patch
Size: 1182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230209/4015f000/attachment.bin>


More information about the cfe-commits mailing list