From 1df588e253f5150edaad138bd887975c58ed1728 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Sun, 28 Dec 2014 22:28:32 +0000 Subject: [PATCH] Parse: Don't crash when 'typename' shows up in an attribute isDeclarationSpecifier performs error recovers which jostles the token stream. Specifically, TryAnnotateTypeOrScopeToken will end up consuming a typename token which will confuse the attribute parsing machinery as we no-longer have something identifier-like. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224903 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseDecl.cpp | 3 ++- test/Parser/cxx-attributes.cpp | 2 ++ test/Parser/namespace-alias-attr.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 64665fc287..c0c0d59c7c 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -143,7 +143,8 @@ void Parser::ParseGNUAttributes(ParsedAttributes &attrs, continue; // Expect an identifier or declaration specifier (const, int, etc.) - if (Tok.isNot(tok::identifier) && !isDeclarationSpecifier()) + if (Tok.isNot(tok::identifier) && !isTypeQualifier() && + !isKnownToBeTypeSpecifier(Tok)) break; IdentifierInfo *AttrName = Tok.getIdentifierInfo(); diff --git a/test/Parser/cxx-attributes.cpp b/test/Parser/cxx-attributes.cpp index 6fd7f4f68a..8cba5bc2a1 100644 --- a/test/Parser/cxx-attributes.cpp +++ b/test/Parser/cxx-attributes.cpp @@ -20,3 +20,5 @@ namespace PR17666 { typedef int __attribute__((aligned(int(1)))) T1; typedef int __attribute__((aligned(int))) T2; // expected-error {{expected '(' for function-style cast}} } + +__attribute((typename)) int x; // expected-error {{expected ')'}} diff --git a/test/Parser/namespace-alias-attr.cpp b/test/Parser/namespace-alias-attr.cpp index 0baba8493d..141a96c5eb 100644 --- a/test/Parser/namespace-alias-attr.cpp +++ b/test/Parser/namespace-alias-attr.cpp @@ -4,5 +4,5 @@ namespace A { } -namespace B __attribute__ (( static )) = A; // expected-error{{attributes cannot be specified on namespace alias}} +namespace B __attribute__ (( const )) = A; // expected-error{{attributes cannot be specified on namespace alias}} -- 2.40.0