r239846 - parser: diagnose empty attribute blocks

Aaron Ballman aaron at aaronballman.com
Tue Jun 16 13:12:37 PDT 2015


On Tue, Jun 16, 2015 at 4:03 PM, Saleem Abdulrasool
<compnerd at compnerd.org> wrote:
> Author: compnerd
> Date: Tue Jun 16 15:03:47 2015
> New Revision: 239846
>
> URL: http://llvm.org/viewvc/llvm-project?rev=239846&view=rev
> Log:
> parser: diagnose empty attribute blocks
>
> MS attributes do not permit empty attribute blocks.  Correctly diagnose those.
> We continue to parse to ensure that we recover correctly.  Because the block is
> empty, we do not need to skip any tokens.
>
> Bonus: tweak the comment that I updated but forgot to remove the function name
> in a previous commit.
>
> Modified:
>     cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>     cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>     cfe/trunk/test/Parser/MicrosoftExtensions.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=239846&r1=239845&r2=239846&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Tue Jun 16 15:03:47 2015
> @@ -1000,6 +1000,9 @@ def err_pragma_invalid_keyword : Error<
>  def warn_pragma_unroll_cuda_value_in_parens : Warning<
>    "argument to '#pragma unroll' should not be in parentheses in CUDA C/C++">,
>    InGroup<CudaCompat>;
> +
> +def err_empty_attribute_block : Error<"empty attribute block is not allowed">;

I would prefer this to be worded differently. It's specific to
Microsoft's attributes, and "attribute block" isn't a term of art I'm
used to. How about:

def err_empty_ms_attribute : Error<"Microsoft attribute specifier
cannot be empty">;

> +
>  } // end of Parse Issue category.
>
>  let CategoryName = "Modules Issue" in {
>
> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=239846&r1=239845&r2=239846&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Jun 16 15:03:47 2015
> @@ -3780,7 +3780,7 @@ SourceLocation Parser::SkipCXX11Attribut
>    return EndLoc;
>  }
>
> -/// ParseMicrosoftAttributes - Parse Microsoft attributes [Attr]
> +/// Parse one or more Microsoft-style attributes [Attr]

Thank you for this! :-)

~Aaron

>  ///
>  /// [MS] ms-attribute:
>  ///             '[' token-seq ']'
> @@ -3796,6 +3796,8 @@ void Parser::ParseMicrosoftAttributes(Pa
>      // FIXME: If this is actually a C++11 attribute, parse it as one.
>      BalancedDelimiterTracker T(*this, tok::l_square);
>      T.consumeOpen();
> +    if (Tok.is(tok::r_square))
> +      Diag(T.getOpenLocation(), diag::err_empty_attribute_block);
>      SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
>      T.consumeClose();
>      if (endLoc)
>
> Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=239846&r1=239845&r2=239846&view=diff
> ==============================================================================
> --- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
> +++ cfe/trunk/test/Parser/MicrosoftExtensions.c Tue Jun 16 15:03:47 2015
> @@ -55,6 +55,8 @@ int foo1([SA_Post(attr=1)] void *param);
>  [unbalanced(attribute) /* expected-note {{to match this '['}} */
>  void f(void); /* expected-error {{expected ']'}} */
>
> +[] __interface I {}; /* expected-error {{empty attribute block is not allowed}} */
> +
>  void ms_intrinsics(int a) {
>    __noop();
>    __assume(a);
>
>
> _______________________________________________
> 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