[clang] 0869204 - [clang-format] Fix buildbot failures
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sat May 11 15:23:43 PDT 2024
Author: Owen Pan
Date: 2024-05-11T15:23:35-07:00
New Revision: 0869204cff22831d0bb19a82c99bf85e4deb4ae3
URL: https://github.com/llvm/llvm-project/commit/0869204cff22831d0bb19a82c99bf85e4deb4ae3
DIFF: https://github.com/llvm/llvm-project/commit/0869204cff22831d0bb19a82c99bf85e4deb4ae3.diff
LOG: [clang-format] Fix buildbot failures
This effectively reverts 5cd280433e8e and changes to QualifierFixerTest.cpp
from e62ce1f8842c.
Failed buidbots:
https://lab.llvm.org/buildbot/#/builders/236/builds/11223
https://lab.llvm.org/buildbot/#/builders/239/builds/6968
Added:
Modified:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/QualifierAlignmentFixer.h
clang/unittests/Format/QualifierFixerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index a904f0b773c6d..077ce5e597a22 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -281,7 +281,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
const FormatToken *LastSimpleTypeSpecifier = TypeToken;
while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
- LangOpts)) {
+ &LangOpts)) {
LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
}
@@ -414,7 +414,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
const FormatToken *LastSimpleTypeSpecifier = TypeToken;
while (isConfiguredQualifierOrType(
LastSimpleTypeSpecifier->getPreviousNonComment(),
- ConfiguredQualifierTokens, LangOpts)) {
+ ConfiguredQualifierTokens, &LangOpts)) {
LastSimpleTypeSpecifier =
LastSimpleTypeSpecifier->getPreviousNonComment();
}
@@ -613,16 +613,18 @@ void prepareLeftRightOrderingForQualifierAlignmentFixer(
}
bool LeftRightQualifierAlignmentFixer::isQualifierOrType(
- const FormatToken *Tok, const LangOptions &LangOpts) {
- return Tok && (Tok->isTypeName(LangOpts) || Tok->is(tok::kw_auto) ||
- isQualifier(Tok));
+ const FormatToken *Tok, const LangOptions *LangOpts) {
+ return Tok &&
+ (Tok->isTypeName(LangOpts ? *LangOpts : getFormattingLangOpts()) ||
+ Tok->is(tok::kw_auto) || isQualifier(Tok));
}
bool LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
const FormatToken *Tok, const std::vector<tok::TokenKind> &Qualifiers,
- const LangOptions &LangOpts) {
- return Tok && (Tok->isTypeName(LangOpts) || Tok->is(tok::kw_auto) ||
- isConfiguredQualifier(Tok, Qualifiers));
+ const LangOptions *LangOpts) {
+ return Tok &&
+ (Tok->isTypeName(LangOpts ? *LangOpts : getFormattingLangOpts()) ||
+ Tok->is(tok::kw_auto) || isConfiguredQualifier(Tok, Qualifiers));
}
// If a token is an identifier and it's upper case, it could
diff --git a/clang/lib/Format/QualifierAlignmentFixer.h b/clang/lib/Format/QualifierAlignmentFixer.h
index 710fa2dc00309..97fcb42e4b2e5 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.h
+++ b/clang/lib/Format/QualifierAlignmentFixer.h
@@ -72,11 +72,11 @@ class LeftRightQualifierAlignmentFixer : public TokenAnalyzer {
// Is the Token a simple or qualifier type
static bool isQualifierOrType(const FormatToken *Tok,
- const LangOptions &LangOpts);
+ const LangOptions *LangOpts = nullptr);
static bool
isConfiguredQualifierOrType(const FormatToken *Tok,
const std::vector<tok::TokenKind> &Qualifiers,
- const LangOptions &LangOpts);
+ const LangOptions *LangOpts = nullptr);
// Is the Token likely a Macro
static bool isPossibleMacro(const FormatToken *Tok);
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp
index 5463bfbb65ca6..792d8f3c3a982 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -1055,82 +1055,70 @@ TEST_F(QualifierFixerTest, IsQualifierType) {
ConfiguredTokens.push_back(tok::kw_constexpr);
ConfiguredTokens.push_back(tok::kw_friend);
- LangOptions LangOpts{getFormattingLangOpts()};
-
auto Tokens = annotate(
"const static inline auto restrict int double long constexpr friend");
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[0], ConfiguredTokens, LangOpts));
+ Tokens[0], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[1], ConfiguredTokens, LangOpts));
+ Tokens[1], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[2], ConfiguredTokens, LangOpts));
+ Tokens[2], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[3], ConfiguredTokens, LangOpts));
+ Tokens[3], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[4], ConfiguredTokens, LangOpts));
+ Tokens[4], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[5], ConfiguredTokens, LangOpts));
+ Tokens[5], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[6], ConfiguredTokens, LangOpts));
+ Tokens[6], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[7], ConfiguredTokens, LangOpts));
+ Tokens[7], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[8], ConfiguredTokens, LangOpts));
+ Tokens[8], ConfiguredTokens));
EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- Tokens[9], ConfiguredTokens, LangOpts));
-
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[0], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[1], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[2], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[3], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[4], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[5], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[6], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[7], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[8], LangOpts));
- EXPECT_TRUE(
- LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[9], LangOpts));
+ Tokens[9], ConfiguredTokens));
+
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[0]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[1]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[2]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[3]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[4]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[5]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[6]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[7]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[8]));
+ EXPECT_TRUE(LeftRightQualifierAlignmentFixer::isQualifierOrType(Tokens[9]));
auto NotTokens = annotate("for while do Foo Bar ");
ASSERT_EQ(NotTokens.size(), 6u) << Tokens;
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[0], ConfiguredTokens, LangOpts));
+ NotTokens[0], ConfiguredTokens));
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[1], ConfiguredTokens, LangOpts));
+ NotTokens[1], ConfiguredTokens));
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[2], ConfiguredTokens, LangOpts));
+ NotTokens[2], ConfiguredTokens));
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[3], ConfiguredTokens, LangOpts));
+ NotTokens[3], ConfiguredTokens));
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[4], ConfiguredTokens, LangOpts));
+ NotTokens[4], ConfiguredTokens));
EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isConfiguredQualifierOrType(
- NotTokens[5], ConfiguredTokens, LangOpts));
-
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[0],
- LangOpts));
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[1],
- LangOpts));
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[2],
- LangOpts));
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[3],
- LangOpts));
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[4],
- LangOpts));
- EXPECT_FALSE(LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[5],
- LangOpts));
+ NotTokens[5], ConfiguredTokens));
+
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[0]));
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[1]));
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[2]));
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[3]));
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[4]));
+ EXPECT_FALSE(
+ LeftRightQualifierAlignmentFixer::isQualifierOrType(NotTokens[5]));
}
TEST_F(QualifierFixerTest, IsMacro) {
More information about the cfe-commits
mailing list