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
This commit is contained in:
Richard Smith 2013-01-29 01:48:07 +00:00
Родитель cda7968b38
Коммит 33f04a208a
4 изменённых файлов: 14 добавлений и 12 удалений

Просмотреть файл

@ -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">];
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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}}

Просмотреть файл

@ -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));