[clang] 37cdabd - [clang-format] Parse __attribute((foo)) as a pointer qualifier

Alex Richardson via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 28 03:32:10 PDT 2020


Author: Alex Richardson
Date: 2020-08-28T11:31:47+01:00
New Revision: 37cdabdb82e33e0d659c92a6cbb7049c31e0acbc

URL: https://github.com/llvm/llvm-project/commit/37cdabdb82e33e0d659c92a6cbb7049c31e0acbc
DIFF: https://github.com/llvm/llvm-project/commit/37cdabdb82e33e0d659c92a6cbb7049c31e0acbc.diff

LOG: [clang-format] Parse __attribute((foo)) as a pointer qualifier

Before: void f() { MACRO(A * __attribute((foo)) a); }
After:  void f() { MACRO(A *__attribute((foo)) a); }

Also check that the __attribute__ alias is handled.

Reviewed By: MyDeveloperDay

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

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index dfcd92dcd3e0..e5c0a7cb033c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1892,7 +1892,7 @@ class AnnotatingParser {
     if (!NextToken ||
         NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
                            tok::kw_restrict, tok::kw_volatile,
-                           tok::kw_noexcept) ||
+                           tok::kw___attribute, tok::kw_noexcept) ||
         (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
       return TT_PointerOrReference;
 

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 95fdbec4b97b..1234462a47ec 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8059,6 +8059,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(A *volatile a);");
   verifyIndependentOfContext("MACRO(A *__volatile a);");
   verifyIndependentOfContext("MACRO(A *__volatile__ a);");
+  verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
+  verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   // FIXME: Is there a way to make this work?


        


More information about the cfe-commits mailing list