[clang] 320311a - [clang][parser] Unify rejecting (non) decl stmts with gnu attributes

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 19 03:44:21 PDT 2021


Author: Timm Bäder
Date: 2021-04-19T12:43:55+02:00
New Revision: 320311a01b4938fca8f5127193167d367d1a9f87

URL: https://github.com/llvm/llvm-project/commit/320311a01b4938fca8f5127193167d367d1a9f87
DIFF: https://github.com/llvm/llvm-project/commit/320311a01b4938fca8f5127193167d367d1a9f87.diff

LOG: [clang][parser] Unify rejecting (non) decl stmts with gnu attributes

The comment here was introduced in
a3e01cf822f7415337e5424af3c6f4c94a12c1b9 and suggests that we should
handle declaration statements and non-declaration statements the same,
but don't because ProhibitAttributes() can't handle GNU attributes. That
has recently changed, so remove the comment and handle all statements
the same.

Differential Revision: https://reviews.llvm.org/D99936

Added: 
    

Modified: 
    clang/lib/Parse/ParseStmt.cpp
    clang/test/SemaCXX/warn-unused-label-error.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index d4863d1e3abd5..7dd8dd1ff3b71 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -648,18 +648,12 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributesWithRange &attrs,
     // attributes as part of a statement in that case). That looks like a bug.
     if (!getLangOpts().CPlusPlus || Tok.is(tok::semi))
       attrs.takeAllFrom(TempAttrs);
-    else if (isDeclarationStatement()) {
+    else {
       StmtVector Stmts;
-      // FIXME: We should do this whether or not we have a declaration
-      // statement, but that doesn't work correctly (because ProhibitAttributes
-      // can't handle GNU attributes), so only call it in the one case where
-      // GNU attributes are allowed.
       SubStmt = ParseStatementOrDeclarationAfterAttributes(Stmts, StmtCtx,
                                                            nullptr, TempAttrs);
       if (!TempAttrs.empty() && !SubStmt.isInvalid())
         SubStmt = Actions.ActOnAttributedStmt(TempAttrs, SubStmt.get());
-    } else {
-      Diag(Tok, diag::err_expected_after) << "__attribute__" << tok::semi;
     }
   }
 

diff  --git a/clang/test/SemaCXX/warn-unused-label-error.cpp b/clang/test/SemaCXX/warn-unused-label-error.cpp
index 461b1e8b963e3..ceef8894768e0 100644
--- a/clang/test/SemaCXX/warn-unused-label-error.cpp
+++ b/clang/test/SemaCXX/warn-unused-label-error.cpp
@@ -12,8 +12,8 @@ namespace PR8455 {
 
   void g() {
     C: // unused label 'C' will not appear here because an error has occurred
-      __attribute__((unused))
-      #pragma weak unused_local_static  // expected-error {{expected ';' after __attribute__}}
+      __attribute__((unused)) // expected-error {{an attribute list cannot appear here}}
+      #pragma weak unused_local_static
       ;
   }
 


        


More information about the cfe-commits mailing list