r224903 - Parse: Don't crash when 'typename' shows up in an attribute

David Majnemer david.majnemer at gmail.com
Sun Dec 28 14:28:32 PST 2014


Author: majnemer
Date: Sun Dec 28 16:28:32 2014
New Revision: 224903

URL: http://llvm.org/viewvc/llvm-project?rev=224903&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Parser/cxx-attributes.cpp
    cfe/trunk/test/Parser/namespace-alias-attr.cpp

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=224903&r1=224902&r2=224903&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sun Dec 28 16:28:32 2014
@@ -143,7 +143,8 @@ void Parser::ParseGNUAttributes(ParsedAt
         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();

Modified: cfe/trunk/test/Parser/cxx-attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx-attributes.cpp?rev=224903&r1=224902&r2=224903&view=diff
==============================================================================
--- cfe/trunk/test/Parser/cxx-attributes.cpp (original)
+++ cfe/trunk/test/Parser/cxx-attributes.cpp Sun Dec 28 16:28:32 2014
@@ -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 ')'}}

Modified: cfe/trunk/test/Parser/namespace-alias-attr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/namespace-alias-attr.cpp?rev=224903&r1=224902&r2=224903&view=diff
==============================================================================
--- cfe/trunk/test/Parser/namespace-alias-attr.cpp (original)
+++ cfe/trunk/test/Parser/namespace-alias-attr.cpp Sun Dec 28 16:28:32 2014
@@ -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}}
 





More information about the cfe-commits mailing list