r239758 - parser: improve diagnostics for MS attributes

Saleem Abdulrasool compnerd at compnerd.org
Mon Jun 15 13:57:05 PDT 2015


Author: compnerd
Date: Mon Jun 15 15:57:04 2015
New Revision: 239758

URL: http://llvm.org/viewvc/llvm-project?rev=239758&view=rev
Log:
parser: improve diagnostics for MS attributes

Switch to using BalancedDelimiterTracker to get better diagnostics for
unbalanced delimiters.  This still does not handle any of the attributes, simply
improves the parsing.

Modified:
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp
    cfe/trunk/test/Parser/MicrosoftExtensions.c

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=239758&r1=239757&r2=239758&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Mon Jun 15 15:57:04 2015
@@ -3780,7 +3780,7 @@ SourceLocation Parser::SkipCXX11Attribut
   return EndLoc;
 }
 
-/// ParseMicrosoftAttributes - Parse a Microsoft attribute [Attr]
+/// ParseMicrosoftAttributes - Parse Microsoft attributes [Attr]
 ///
 /// [MS] ms-attribute:
 ///             '[' token-seq ']'
@@ -3792,13 +3792,15 @@ void Parser::ParseMicrosoftAttributes(Pa
                                       SourceLocation *endLoc) {
   assert(Tok.is(tok::l_square) && "Not a Microsoft attribute list");
 
-  while (Tok.is(tok::l_square)) {
+  do {
     // FIXME: If this is actually a C++11 attribute, parse it as one.
-    ConsumeBracket();
+    BalancedDelimiterTracker T(*this, tok::l_square);
+    T.consumeOpen();
     SkipUntil(tok::r_square, StopAtSemi | StopBeforeMatch);
-    if (endLoc) *endLoc = Tok.getLocation();
-    ExpectAndConsume(tok::r_square);
-  }
+    T.consumeClose();
+    if (endLoc)
+      *endLoc = T.getCloseLocation();
+  } while (Tok.is(tok::l_square));
 }
 
 void Parser::ParseMicrosoftIfExistsClassDeclaration(DeclSpec::TST TagType,

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=239758&r1=239757&r2=239758&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.c Mon Jun 15 15:57:04 2015
@@ -52,6 +52,9 @@ void deprecated_enum_test(void) {
 [returnvalue:SA_Post( attr=1)]
 int foo1([SA_Post(attr=1)] void *param);
 
+[unbalanced(attribute) /* expected-note {{to match this '['}} */
+void f(void); /* expected-error {{expected ']'}} */
+
 void ms_intrinsics(int a) {
   __noop();
   __assume(a);





More information about the cfe-commits mailing list