Revert "[clang][parser] Set source ranges for GNU-style attributes"
authorTimm Bäder <tbaeder@redhat.com>
Thu, 1 Apr 2021 15:32:40 +0000 (17:32 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 1 Apr 2021 15:32:40 +0000 (17:32 +0200)
This reverts commit 1ea9fa8c507ec360cf43faf46d13b149e37c950d.

clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/Parse/ParseDecl.cpp
clang/test/AST/sourceranges.cpp
clang/test/SemaCXX/switch-implicit-fallthrough.cpp

index 6f6d469..b67e541 100644 (file)
@@ -1572,6 +1572,27 @@ private:
 
   //===--------------------------------------------------------------------===//
   // C99 6.9: External Definitions.
+  struct ParsedAttributesWithRange : ParsedAttributes {
+    ParsedAttributesWithRange(AttributeFactory &factory)
+      : ParsedAttributes(factory) {}
+
+    void clear() {
+      ParsedAttributes::clear();
+      Range = SourceRange();
+    }
+
+    SourceRange Range;
+  };
+  struct ParsedAttributesViewWithRange : ParsedAttributesView {
+    ParsedAttributesViewWithRange() : ParsedAttributesView() {}
+    void clearListOnly() {
+      ParsedAttributesView::clearListOnly();
+      Range = SourceRange();
+    }
+
+    SourceRange Range;
+  };
+
   DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributesWithRange &attrs,
                                           ParsingDeclSpec *DS = nullptr);
   bool isDeclarationAfterDeclarator();
@@ -2704,50 +2725,17 @@ private:
       D.takeAttributes(attrs, endLoc);
     }
   }
-
-  /// Parses GNU-style attributes and returns them without source range
-  /// information.
-  ///
-  /// This API is discouraged. Use the version that takes a
-  /// ParsedAttributesWithRange instead.
-  bool MaybeParseGNUAttributes(ParsedAttributes &Attrs,
-                               SourceLocation *EndLoc = nullptr,
+  bool MaybeParseGNUAttributes(ParsedAttributes &attrs,
+                               SourceLocation *endLoc = nullptr,
                                LateParsedAttrList *LateAttrs = nullptr) {
     if (Tok.is(tok::kw___attribute)) {
-      ParsedAttributesWithRange AttrsWithRange(AttrFactory);
-      ParseGNUAttributes(Attrs, EndLoc, LateAttrs);
-      Attrs.takeAllFrom(AttrsWithRange);
+      ParseGNUAttributes(attrs, endLoc, LateAttrs);
       return true;
     }
     return false;
   }
-
-  bool MaybeParseGNUAttributes(ParsedAttributesWithRange &Attrs,
-                               SourceLocation *EndLoc = nullptr,
-                               LateParsedAttrList *LateAttrs = nullptr) {
-    if (Tok.is(tok::kw___attribute)) {
-      ParseGNUAttributes(Attrs, EndLoc, LateAttrs);
-      return true;
-    }
-    return false;
-  }
-
-  /// Parses GNU-style attributes and returns them without source range
-  /// information.
-  ///
-  /// This API is discouraged. Use the version that takes a
-  /// ParsedAttributesWithRange instead.
-  void ParseGNUAttributes(ParsedAttributes &Attrs,
-                          SourceLocation *EndLoc = nullptr,
-                          LateParsedAttrList *LateAttrs = nullptr,
-                          Declarator *D = nullptr) {
-    ParsedAttributesWithRange AttrsWithRange(AttrFactory);
-    ParseGNUAttributes(AttrsWithRange, EndLoc, LateAttrs, D);
-    Attrs.takeAllFrom(AttrsWithRange);
-  }
-
-  void ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
-                          SourceLocation *EndLoc = nullptr,
+  void ParseGNUAttributes(ParsedAttributes &attrs,
+                          SourceLocation *endLoc = nullptr,
                           LateParsedAttrList *LateAttrs = nullptr,
                           Declarator *D = nullptr);
   void ParseGNUAttributeArgs(IdentifierInfo *AttrName,
index fb086e3..a3d82fc 100644 (file)
@@ -1034,27 +1034,6 @@ private:
   mutable AttributePool pool;
 };
 
-struct ParsedAttributesWithRange : ParsedAttributes {
-  ParsedAttributesWithRange(AttributeFactory &factory)
-      : ParsedAttributes(factory) {}
-
-  void clear() {
-    ParsedAttributes::clear();
-    Range = SourceRange();
-  }
-
-  SourceRange Range;
-};
-struct ParsedAttributesViewWithRange : ParsedAttributesView {
-  ParsedAttributesViewWithRange() : ParsedAttributesView() {}
-  void clearListOnly() {
-    ParsedAttributesView::clearListOnly();
-    Range = SourceRange();
-  }
-
-  SourceRange Range;
-};
-
 /// These constants match the enumerated choices of
 /// err_attribute_argument_n_type and err_attribute_argument_type.
 enum AttributeArgumentNType {
index eb567f5..104b1b5 100644 (file)
@@ -162,19 +162,15 @@ void Parser::ParseAttributes(unsigned WhichAttrKinds,
 ///    ',' or ')' are ignored, otherwise they produce a parse error.
 ///
 /// We follow the C++ model, but don't allow junk after the identifier.
-void Parser::ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
-                                SourceLocation *EndLoc,
-                                LateParsedAttrList *LateAttrs, Declarator *D) {
+void Parser::ParseGNUAttributes(ParsedAttributes &attrs,
+                                SourceLocation *endLoc,
+                                LateParsedAttrList *LateAttrs,
+                                Declarator *D) {
   assert(Tok.is(tok::kw___attribute) && "Not a GNU attribute list!");
 
-  SourceLocation StartLoc = Tok.getLocation(), Loc;
-
-  if (!EndLoc)
-    EndLoc = &Loc;
-
   while (Tok.is(tok::kw___attribute)) {
     SourceLocation AttrTokLoc = ConsumeToken();
-    unsigned OldNumAttrs = Attrs.size();
+    unsigned OldNumAttrs = attrs.size();
     unsigned OldNumLateAttrs = LateAttrs ? LateAttrs->size() : 0;
 
     if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
@@ -202,14 +198,14 @@ void Parser::ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
       SourceLocation AttrNameLoc = ConsumeToken();
 
       if (Tok.isNot(tok::l_paren)) {
-        Attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
+        attrs.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
                      ParsedAttr::AS_GNU);
         continue;
       }
 
       // Handle "parameterized" attributes
       if (!LateAttrs || !isAttributeLateParsed(*AttrName)) {
-        ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs, EndLoc, nullptr,
+        ParseGNUAttributeArgs(AttrName, AttrNameLoc, attrs, endLoc, nullptr,
                               SourceLocation(), ParsedAttr::AS_GNU, D);
         continue;
       }
@@ -242,8 +238,8 @@ void Parser::ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
     SourceLocation Loc = Tok.getLocation();
     if (ExpectAndConsume(tok::r_paren))
       SkipUntil(tok::r_paren, StopAtSemi);
-    if (EndLoc)
-      *EndLoc = Loc;
+    if (endLoc)
+      *endLoc = Loc;
 
     // If this was declared in a macro, attach the macro IdentifierInfo to the
     // parsed attribute.
@@ -255,8 +251,8 @@ void Parser::ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
           Lexer::getSourceText(ExpansionRange, SM, PP.getLangOpts());
       IdentifierInfo *MacroII = PP.getIdentifierInfo(FoundName);
 
-      for (unsigned i = OldNumAttrs; i < Attrs.size(); ++i)
-        Attrs[i].setMacroIdentifier(MacroII, ExpansionRange.getBegin());
+      for (unsigned i = OldNumAttrs; i < attrs.size(); ++i)
+        attrs[i].setMacroIdentifier(MacroII, ExpansionRange.getBegin());
 
       if (LateAttrs) {
         for (unsigned i = OldNumLateAttrs; i < LateAttrs->size(); ++i)
@@ -264,8 +260,6 @@ void Parser::ParseGNUAttributes(ParsedAttributesWithRange &Attrs,
       }
     }
   }
-
-  Attrs.Range = SourceRange(StartLoc, *EndLoc);
 }
 
 /// Determine whether the given attribute has an identifier argument.
index cd1095c..a38ec32 100644 (file)
@@ -108,24 +108,6 @@ namespace attributed_decl {
   }\r
 }\r
 \r
-// CHECK-1Z: NamespaceDecl {{.*}} attributed_case\r
-namespace attributed_case {\r
-void f(int n) {\r
-  switch (n) {\r
-  case 0:\r
-    n--;\r
-    // CHECK: AttributedStmt {{.*}} <line:[[@LINE+2]]:5, line:[[@LINE+4]]:35>\r
-    // CHECK: FallThroughAttr {{.*}} <line:[[@LINE+1]]:20>\r
-    __attribute__((fallthrough))\r
-    // CHECK: FallThroughAttr {{.*}} <line:[[@LINE+1]]:22>\r
-      __attribute__((fallthrough));\r
-  case 1:\r
-    n++;\r
-    break;\r
-  }\r
-}\r
-} // namespace attributed_case\r
-\r
 // CHECK: NamespaceDecl {{.*}} attributed_stmt\r
 namespace attributed_stmt {\r
   // In DO_PRAGMA and _Pragma cases, `LoopHintAttr` comes from <scratch space>\r
index 9676664..e6ae0d5 100644 (file)
@@ -185,12 +185,9 @@ int fallthrough_position(int n) {
       return 1;
       [[clang::fallthrough]];  // expected-warning{{fallthrough annotation in unreachable code}}
     case 222:
-      return 2;
-      __attribute__((fallthrough)); // expected-warning{{fallthrough annotation in unreachable code}}
-    case 223:
       n += 400;
-    case 224: // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
-        ;
+    case 223:          // expected-warning{{unannotated fall-through between switch labels}} expected-note{{insert '[[clang::fallthrough]];' to silence this warning}} expected-note{{insert 'break;' to avoid fall-through}}
+      ;
   }
 
   long p = static_cast<long>(n) * n;