Author: Alex Richardson Date: 2020-09-04T16:56:21+01:00 New Revision: 8c810acc94ed462238242c04c75ab33fc96da6e8
URL: https://github.com/llvm/llvm-project/commit/8c810acc94ed462238242c04c75ab33fc96da6e8 DIFF: https://github.com/llvm/llvm-project/commit/8c810acc94ed462238242c04c75ab33fc96da6e8.diff LOG: [clang-format] Parse __ptr32/__ptr64 as a pointer qualifier Before: x = (foo *__ptr32) * v; MACRO(A * __ptr32 a); x = (foo *__ptr64) * v; MACRO(A * __ptr64 a); After: x = (foo *__ptr32)*v; MACRO(A *__ptr32 a); x = (foo *__ptr64)*v; MACRO(A *__ptr64 a); Depends on D86721 (to apply cleanly) Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D86775 Added: Modified: clang/lib/Format/FormatToken.h clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index a54600a478a4..ad72a95062ab 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -442,7 +442,7 @@ struct FormatToken { bool canBePointerOrReferenceQualifier() const { return isOneOf(tok::kw_const, tok::kw_restrict, tok::kw_volatile, tok::kw___attribute, tok::kw__Nonnull, tok::kw__Nullable, - tok::kw__Null_unspecified); + tok::kw__Null_unspecified, tok::kw___ptr32, tok::kw___ptr64); } /// Determine whether the token is a simple-type-specifier. diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 14c97784b738..716fe2bf50ae 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8028,6 +8028,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("vector<a *_Nonnull> v;"); verifyFormat("vector<a *_Nullable> v;"); verifyFormat("vector<a *_Null_unspecified> v;"); + verifyFormat("vector<a *__ptr32> v;"); + verifyFormat("vector<a *__ptr64> v;"); verifyFormat("vector<a * _NotAQualifier> v;"); verifyFormat("vector<a * b> v;"); verifyFormat("foo<b && false>();"); @@ -8070,6 +8072,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);"); verifyIndependentOfContext("MACRO(A *[[clang::attr]] a);"); verifyIndependentOfContext("MACRO(A *[[clang::attr(\"foo\")]] a);"); + verifyIndependentOfContext("MACRO(A *__ptr32 a);"); + verifyIndependentOfContext("MACRO(A *__ptr64 a);"); verifyIndependentOfContext("MACRO('0' <= c && c <= '9');"); verifyFormat("void f() { f(float{1}, a * a); }"); // FIXME: Is there a way to make this work? @@ -8141,6 +8145,8 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) { verifyFormat("x = (foo *_Nonnull)*v;"); verifyFormat("x = (foo *[[clang::attr]])*v;"); verifyFormat("x = (foo *[[clang::attr(\"foo\")]])*v;"); + verifyFormat("x = (foo *__ptr32)*v;"); + verifyFormat("x = (foo *__ptr64)*v;"); // Check that we handle multiple trailing qualifiers and skip them all to // determine that the expression is a cast to a pointer type. @@ -8149,7 +8155,7 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) { LongPointerLeft.PointerAlignment = FormatStyle::PAS_Left; StringRef AllQualifiers = "const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified " - "_Nonnull [[clang::attr]]"; + "_Nonnull [[clang::attr]] __ptr32 __ptr64"; verifyFormat(("x = (foo *" + AllQualifiers + ")*v;").str(), LongPointerRight); verifyFormat(("x = (foo* " + AllQualifiers + ")*v;").str(), LongPointerLeft); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits