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

Aaron Ballman aaron at aaronballman.com
Sat Jan 3 08:31:41 PST 2015


On Sun, Dec 28, 2014 at 5:28 PM, David Majnemer
<david.majnemer at gmail.com> wrote:
> 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))

This change is causing regressions in code like:

#define always_inline inline
#define av_always_inline __attribute__((always_inline))

static av_always_inline float f(int i);

This code used to give a warning about __attribute__((inline)) being
an unknown attribute, but now it gives a hard parsing error. This
causes regressions in some open source packages (xine-lib, I think,
according to Joerg).

The original code was nonsense to begin with, but changing a warning
into a hard error wasn't likely the intent of this change either.

~Aaron

>          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}}
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list