Skip to content

Commit f590845

Browse files
sylvestretstellar
authored andcommitted
Revert "[clang-format] Fix AlignConsecutive on PP blocks"
This reverts commit b2eb439. Caused the regression: https://bugs.llvm.org/show_bug.cgi?id=47589 Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D89464 (cherry picked from commit b9e7894)
1 parent 890fdb8 commit f590845

File tree

5 files changed

+3
-59
lines changed

5 files changed

+3
-59
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ struct FormatToken {
183183
/// before the token.
184184
bool MustBreakBefore = false;
185185

186-
/// Whether to not align across this token
187-
///
188-
/// This happens for example when a preprocessor directive ended directly
189-
/// before the token, but very rarely otherwise.
190-
bool MustBreakAlignBefore = false;
191-
192186
/// The raw text of the token.
193187
///
194188
/// Contains the raw token text without leading whitespace and without leading

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,7 +3037,6 @@ void UnwrappedLineParser::readToken(int LevelDifference) {
30373037
}
30383038
FormatTok = Tokens->getNextToken();
30393039
FormatTok->MustBreakBefore = true;
3040-
FormatTok->MustBreakAlignBefore = true;
30413040
}
30423041

30433042
if (!PPStack.empty() && (PPStack.back().Kind == PP_Unreachable) &&
@@ -3062,7 +3061,6 @@ void UnwrappedLineParser::pushToken(FormatToken *Tok) {
30623061
Line->Tokens.push_back(UnwrappedLineNode(Tok));
30633062
if (MustBreakBeforeNextToken) {
30643063
Line->Tokens.back().Tok->MustBreakBefore = true;
3065-
Line->Tokens.back().Tok->MustBreakAlignBefore = true;
30663064
MustBreakBeforeNextToken = false;
30673065
}
30683066
}

clang/lib/Format/WhitespaceManager.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,9 @@ static unsigned AlignTokens(const FormatStyle &Style, F &&Matches,
411411
if (Changes[i].NewlinesBefore != 0) {
412412
CommasBeforeMatch = 0;
413413
EndOfSequence = i;
414-
// If there is a blank line, there is a forced-align-break (eg,
415-
// preprocessor), or if the last line didn't contain any matching token,
416-
// the sequence ends here.
417-
if (Changes[i].NewlinesBefore > 1 ||
418-
Changes[i].Tok->MustBreakAlignBefore || !FoundMatchOnLine)
414+
// If there is a blank line, or if the last line didn't contain any
415+
// matching token, the sequence ends here.
416+
if (Changes[i].NewlinesBefore > 1 || !FoundMatchOnLine)
419417
AlignCurrentSequence();
420418

421419
FoundMatchOnLine = false;
@@ -726,8 +724,6 @@ void WhitespaceManager::alignTrailingComments() {
726724
if (Changes[i].StartOfBlockComment)
727725
continue;
728726
Newlines += Changes[i].NewlinesBefore;
729-
if (Changes[i].Tok->MustBreakAlignBefore)
730-
BreakBeforeNext = true;
731727
if (!Changes[i].IsTrailingComment)
732728
continue;
733729

clang/unittests/Format/FormatTest.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11968,29 +11968,6 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
1196811968
verifyFormat("int oneTwoThree = 123; // comment\n"
1196911969
"int oneTwo = 12; // comment",
1197011970
Alignment);
11971-
11972-
// Bug 25167
11973-
verifyFormat("#if A\n"
11974-
"#else\n"
11975-
"int aaaaaaaa = 12;\n"
11976-
"#endif\n"
11977-
"#if B\n"
11978-
"#else\n"
11979-
"int a = 12;\n"
11980-
"#endif\n",
11981-
Alignment);
11982-
verifyFormat("enum foo {\n"
11983-
"#if A\n"
11984-
"#else\n"
11985-
" aaaaaaaa = 12;\n"
11986-
"#endif\n"
11987-
"#if B\n"
11988-
"#else\n"
11989-
" a = 12;\n"
11990-
"#endif\n"
11991-
"};\n",
11992-
Alignment);
11993-
1199411971
EXPECT_EQ("int a = 5;\n"
1199511972
"\n"
1199611973
"int oneTwoThree = 123;",

clang/unittests/Format/FormatTestComments.cpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,27 +2780,6 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
27802780
" // line 2 about b\n"
27812781
" long b;",
27822782
getLLVMStyleWithColumns(80)));
2783-
2784-
// Checks an edge case in preprocessor handling.
2785-
// These comments should *not* be aligned
2786-
EXPECT_EQ(
2787-
"#if FOO\n"
2788-
"#else\n"
2789-
"long a; // Line about a\n"
2790-
"#endif\n"
2791-
"#if BAR\n"
2792-
"#else\n"
2793-
"long b_long_name; // Line about b\n"
2794-
"#endif\n",
2795-
format("#if FOO\n"
2796-
"#else\n"
2797-
"long a; // Line about a\n" // Previous (bad) behavior
2798-
"#endif\n"
2799-
"#if BAR\n"
2800-
"#else\n"
2801-
"long b_long_name; // Line about b\n"
2802-
"#endif\n",
2803-
getLLVMStyleWithColumns(80)));
28042783
}
28052784

28062785
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {

0 commit comments

Comments
 (0)