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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits