Author: Alex Richardson Date: 2020-08-28T11:31:47+01:00 New Revision: 4f103695646bb9e16609a276072781f5a933570d
URL: https://github.com/llvm/llvm-project/commit/4f103695646bb9e16609a276072781f5a933570d DIFF: https://github.com/llvm/llvm-project/commit/4f103695646bb9e16609a276072781f5a933570d.diff LOG: [clang-format] Parse restrict as a pointer qualifier Before: void f() { MACRO(A * restrict a); } After: void f() { MACRO(A *restrict a); } Also check that the __restrict and __restrict__ aliases are handled. Reviewed By: JakeMerdichAMD Differential Revision: https://reviews.llvm.org/D86710 Added: Modified: clang/lib/Format/Format.cpp clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 8c1d7c90e02a..fe11cba9bfdf 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2739,6 +2739,7 @@ LangOptions getFormattingLangOpts(const FormatStyle &Style) { 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; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bcd0bf913ecb..dfcd92dcd3e0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1891,7 +1891,8 @@ class AnnotatingParser { 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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 7ea00ff33ca0..95fdbec4b97b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8053,6 +8053,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { 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);"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits