[PATCH] D86710: [clang-format] Parse restrict as a pointer qualifier
Alexander Richardson via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 06:47:03 PDT 2020
arichardson created this revision.
arichardson added reviewers: MyDeveloperDay, JakeMerdichAMD, sammccall, curdeius.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
arichardson requested review of this revision.
Before: void f() { MACRO(A * restrict a); }
After: void f() { MACRO(A *restrict a); }
Also check that the __restrict and __restrict__ aliases are handled.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D86710
Files:
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8053,6 +8053,9 @@
verifyIndependentOfContext("MACRO(auto *a);");
verifyIndependentOfContext("MACRO(const A *a);");
verifyIndependentOfContext("MACRO(A *const a);");
+ verifyIndependentOfContext("MACRO(A *restrict a);");
+ verifyIndependentOfContext("MACRO(A *__restrict__ a);");
+ verifyIndependentOfContext("MACRO(A *__restrict a);");
verifyIndependentOfContext("MACRO(A *volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile a);");
verifyIndependentOfContext("MACRO(A *__volatile__ a);");
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1891,7 +1891,8 @@
const FormatToken *NextToken = Tok.getNextNonComment();
if (!NextToken ||
NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const,
- tok::kw_volatile, tok::kw_noexcept) ||
+ tok::kw_restrict, tok::kw_volatile,
+ tok::kw_noexcept) ||
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
return TT_PointerOrReference;
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2739,6 +2739,7 @@
LangOpts.ObjC = 1;
LangOpts.MicrosoftExt = 1; // To get kw___try, kw___finally.
LangOpts.DeclSpecKeyword = 1; // To get __declspec.
+ LangOpts.C99 = 1; // To get kw_restrict for non-underscore-prefixed restrict.
return LangOpts;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86710.288313.patch
Type: text/x-patch
Size: 1820 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200827/5cbd1932/attachment.bin>
More information about the cfe-commits
mailing list