aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorEric Li <li.zhe.hua@gmail.com>2025-07-05 17:06:59 -0400
committerGitHub <noreply@github.com>2025-07-05 17:06:59 -0400
commit878ce210e30f8ebcb4b73d834f91229a403e2376 (patch)
tree38f9f79f0015592c683251ed6b9add7781000eaf /clang/lib/Format
parentc43efcb039dde82ab0e0ead7df3aa266bc2d1cca (diff)
downloadllvm-878ce210e30f8ebcb4b73d834f91229a403e2376.zip
llvm-878ce210e30f8ebcb4b73d834f91229a403e2376.tar.gz
llvm-878ce210e30f8ebcb4b73d834f91229a403e2376.tar.bz2
[clang-format] Propagate `LeadingEmptyLinesAffected` when joining lines (#146761)
Before this commit, when `LineJoiner` joins a line with affected leading whitespace, it would drop the knowledge of this entirely. However, when the `AffectedRangeManager` is computing the affected lines, the leading empty whitespace lines are potentially considered for non-first tokens in the `AnnotatedLine`. This causes a discrepancy in behavior when an `AnnotatedLine` is put together from joining multiple lines versus when it is not. We change `LineJoiner::join` to follow `AffectedRangeManager`'s logic, considering the leading whitespace when determining `Affected` for a token. https://github.com/llvm/llvm-project/blob/a63f57262898588b576d66e5fd79c0aa64b35f2d/clang/lib/Format/AffectedRangeManager.cpp#L111-L130 Fixes #138942.
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index f2ed027..ac8c0c8 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -986,8 +986,10 @@ private:
void join(AnnotatedLine &A, const AnnotatedLine &B) {
assert(!A.Last->Next);
assert(!B.First->Previous);
- if (B.Affected)
+ if (B.Affected || B.LeadingEmptyLinesAffected) {
+ assert(B.Affected || A.Last->Children.empty());
A.Affected = true;
+ }
A.Last->Next = B.First;
B.First->Previous = A.Last;
B.First->CanBreakBefore = true;