Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,10 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
// Abseil aliases to clang's `_Nonnull`, `_Nullable` and `_Null_unspecified`.
LLVMStyle.AttributeMacros.push_back("absl_nonnull");
LLVMStyle.AttributeMacros.push_back("absl_nullable");
LLVMStyle.AttributeMacros.push_back("absl_nullability_unknown");
LLVMStyle.BinPackArguments = true;
LLVMStyle.BinPackLongBracedList = true;
LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
Expand Down
7 changes: 5 additions & 2 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,11 @@ TEST(ConfigParseTest, ParsesConfiguration) {
CHECK_PARSE("IfMacros: [MYIF]", IfMacros, CustomIfs);

Style.AttributeMacros.clear();
CHECK_PARSE("BasedOnStyle: LLVM", AttributeMacros,
std::vector<std::string>{"__capability"});
CHECK_PARSE(
"BasedOnStyle: LLVM", AttributeMacros,
std::vector<std::string>({"__capability", "absl_nonnull", "absl_nullable",
"absl_nullability_unknown"}));
Style.AttributeMacros.clear();
CHECK_PARSE("AttributeMacros: [attr1, attr2]", AttributeMacros,
std::vector<std::string>({"attr1", "attr2"}));

Expand Down
19 changes: 17 additions & 2 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12375,6 +12375,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("vector<a *_Nonnull> v;");
verifyFormat("vector<a *_Nullable> v;");
verifyFormat("vector<a *_Null_unspecified> v;");
verifyFormat("vector<a *absl_nonnull> v;");
verifyFormat("vector<a *absl_nullable> v;");
verifyFormat("vector<a *absl_nullability_unknown> v;");
verifyFormat("vector<a *__ptr32> v;");
verifyFormat("vector<a *__ptr64> v;");
verifyFormat("vector<a *__capability> v;");
Expand Down Expand Up @@ -12518,6 +12521,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("MACRO(A *_Nonnull a);");
verifyIndependentOfContext("MACRO(A *_Nullable a);");
verifyIndependentOfContext("MACRO(A *_Null_unspecified a);");
verifyIndependentOfContext("MACRO(A *absl_nonnull a);");
verifyIndependentOfContext("MACRO(A *absl_nullable a);");
verifyIndependentOfContext("MACRO(A *absl_nullability_unknown a);");
verifyIndependentOfContext("MACRO(A *__attribute__((foo)) a);");
verifyIndependentOfContext("MACRO(A *__attribute((foo)) a);");
verifyIndependentOfContext("MACRO(A *[[clang::attr]] a);");
Expand Down Expand Up @@ -12674,6 +12680,12 @@ TEST_F(FormatTest, UnderstandsAttributes) {
verifyFormat("SomeType *__unused s{InitValue};", CustomAttrs);
verifyFormat("SomeType s __unused(InitValue);", CustomAttrs);
verifyFormat("SomeType s __unused{InitValue};", CustomAttrs);
verifyFormat("SomeType *absl_nonnull s(InitValue);", CustomAttrs);
verifyFormat("SomeType *absl_nonnull s{InitValue};", CustomAttrs);
verifyFormat("SomeType *absl_nullable s(InitValue);", CustomAttrs);
verifyFormat("SomeType *absl_nullable s{InitValue};", CustomAttrs);
verifyFormat("SomeType *absl_nullability_unknown s(InitValue);", CustomAttrs);
verifyFormat("SomeType *absl_nullability_unknown s{InitValue};", CustomAttrs);
verifyFormat("SomeType *__capability s(InitValue);", CustomAttrs);
verifyFormat("SomeType *__capability s{InitValue};", CustomAttrs);
}
Expand All @@ -12687,7 +12699,9 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {
verifyFormat("x = (foo *_Nonnull)*v;");
verifyFormat("x = (foo *_Nullable)*v;");
verifyFormat("x = (foo *_Null_unspecified)*v;");
verifyFormat("x = (foo *_Nonnull)*v;");
verifyFormat("x = (foo *absl_nonnull)*v;");
verifyFormat("x = (foo *absl_nullable)*v;");
verifyFormat("x = (foo *absl_nullability_unknown)*v;");
verifyFormat("x = (foo *[[clang::attr]])*v;");
verifyFormat("x = (foo *[[clang::attr(\"foo\")]])*v;");
verifyFormat("x = (foo *__ptr32)*v;");
Expand All @@ -12701,7 +12715,8 @@ TEST_F(FormatTest, UnderstandsPointerQualifiersInCast) {
LongPointerLeft.PointerAlignment = FormatStyle::PAS_Left;
StringRef AllQualifiers =
"const volatile restrict __attribute__((foo)) _Nonnull _Null_unspecified "
"_Nonnull [[clang::attr]] __ptr32 __ptr64 __capability";
"_Nullable absl_nonnull absl_nullable absl_nullability_unknown "
"[[clang::attr]] __ptr32 __ptr64 __capability";
verifyFormat(("x = (foo *" + AllQualifiers + ")*v;").str(), LongPointerRight);
verifyFormat(("x = (foo* " + AllQualifiers + ")*v;").str(), LongPointerLeft);

Expand Down