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);
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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits