From: Richard Smith Date: Tue, 29 Jan 2013 01:48:07 +0000 (+0000) Subject: Treat alignas and _Alignas as keyword attributes. This allows us to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=33f04a208a1a6e73da73460142327ff05e8c391b;p=clang Treat alignas and _Alignas as keyword attributes. This allows us to pretty-print them properly (modulo the more general badness in alignment attribute printing). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173752 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index a65ffa4319..786b43a77b 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -150,7 +150,7 @@ def Alias : InheritableAttr { def Aligned : InheritableAttr { let Spellings = [GNU<"aligned">, Declspec<"align">, CXX11<"gnu", "aligned">, - Keyword<"alignas">]; + Keyword<"alignas">, Keyword<"_Alignas">]; let Subjects = [NonBitField, NormalVar, Tag]; let Args = [AlignedArgument<"Alignment">, BoolArgument<"IsMSDeclSpec">]; } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index e6e010bd9c..438c6f8cf5 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2074,15 +2074,15 @@ ExprResult Parser::ParseAlignArgument(SourceLocation Start, /// alignment-specifier: /// [C11] '_Alignas' '(' type-id ')' /// [C11] '_Alignas' '(' constant-expression ')' -/// [C++0x] 'alignas' '(' type-id ...[opt] ')' -/// [C++0x] 'alignas' '(' assignment-expression ...[opt] ')' +/// [C++11] 'alignas' '(' type-id ...[opt] ')' +/// [C++11] 'alignas' '(' assignment-expression ...[opt] ')' void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, SourceLocation *endLoc) { assert((Tok.is(tok::kw_alignas) || Tok.is(tok::kw__Alignas)) && "Not an alignment-specifier!"); - SourceLocation KWLoc = Tok.getLocation(); - ConsumeToken(); + IdentifierInfo *KWName = Tok.getIdentifierInfo(); + SourceLocation KWLoc = ConsumeToken(); BalancedDelimiterTracker T(*this, tok::l_paren); if (T.expectAndConsume(diag::err_expected_lparen)) @@ -2107,12 +2107,8 @@ void Parser::ParseAlignmentSpecifier(ParsedAttributes &Attrs, ExprVector ArgExprs; ArgExprs.push_back(ArgExpr.release()); - // FIXME: This should not be GNU, but we since the attribute used is - // based on the spelling, and there is no true spelling for - // C++11 attributes, this isn't accepted. - Attrs.addNew(PP.getIdentifierInfo("aligned"), KWLoc, 0, KWLoc, - 0, T.getOpenLocation(), ArgExprs.data(), 1, - AttributeList::AS_GNU); + Attrs.addNew(KWName, KWLoc, 0, KWLoc, 0, T.getOpenLocation(), + ArgExprs.data(), 1, AttributeList::AS_Keyword); } /// ParseDeclarationSpecifiers diff --git a/test/Parser/cxx11-stmt-attributes.cpp b/test/Parser/cxx11-stmt-attributes.cpp index f26db7989f..a9958471d6 100644 --- a/test/Parser/cxx11-stmt-attributes.cpp +++ b/test/Parser/cxx11-stmt-attributes.cpp @@ -27,7 +27,7 @@ void foo(int i) { [[unknown_attribute]] return; // expected-warning {{unknown attribute 'unknown_attribute' ignored}} - alignas(8) ; // expected-warning {{attribute aligned cannot be specified on a statement}} + alignas(8) ; // expected-warning {{attribute alignas cannot be specified on a statement}} [[noreturn]] { } // expected-warning {{attribute noreturn cannot be specified on a statement}} [[noreturn]] if (0) { } // expected-warning {{attribute noreturn cannot be specified on a statement}} [[noreturn]] for (;;); // expected-warning {{attribute noreturn cannot be specified on a statement}} diff --git a/test/SemaCXX/cxx11-attr-print.cpp b/test/SemaCXX/cxx11-attr-print.cpp index 3cc6d00f08..77df65a45c 100644 --- a/test/SemaCXX/cxx11-attr-print.cpp +++ b/test/SemaCXX/cxx11-attr-print.cpp @@ -17,6 +17,12 @@ int a __attribute__((deprecated("warning"))); // CHECK: gnu::deprecated("warning")]]; int b [[gnu::deprecated("warning")]]; +// CHECK: int cxx11_alignas alignas(4, 0); +alignas(4) int cxx11_alignas; + +// CHECK: int c11_alignas _Alignas(alignof(int), 0); +_Alignas(int) int c11_alignas; + // CHECK: void foo() __attribute__((const)); void foo() __attribute__((const));