<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/208266>208266</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-format] AlignTrailingComments with OverEmptyLines misaligns previously stable file after #206393
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-format
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
earnol
</td>
</tr>
</table>
<pre>
After bae9ddca423145baf0c35e31898b723aa273f85c (#206393), a previously stable file gets reformatted, because a trailing comment in an enum is shifted to align with trailing comments in a subsequent message block, even though they are separated by a non-trailing block comment.
**Configuration (.clang-format):**
```
---
Language: Proto
BasedOnStyle: Google
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 4
ColumnLimit: 0
```
**Input (stable before bae9ddca4231, unstable after)**:
```
enum E {
OK = 0; /* Operation completed successfully. */
}
/* comment */
message M {
optional uint32 field_a = 1; /* Short description of field_a */
repeated uint32 field_b_long_name_for_align = 2; /* Multi-line
description */
}
```
**Expected behavior**:
No change — the file is already correctly formatted.
**Actual**:
The trailing comment in the enum is shifted to align with the trailing comments in the message below, despite a non-trailing /* comment */ block separating them.
**Analysis**:
The new condition added in WhitespaceManager::calculateLineBreakInformation():
```
(P.NewlinesBefore == 0 || !PP || PP->IsTrailingComment)
```
changes how IsTrailingComment propagates. The non-trailing block comment (/* comment */ on its own line) is now incorrectly treated in a way that allows the AlignTrailingComments logic with OverEmptyLines: 4 to "see through" it and align comments across unrelated blocks.
Before the patch, the block comment acted as a barrier preventing cross-block trailing comment alignment. After the patch, it no longer does.
**Verified**:
Reverting bae9ddca4231 on current HEAD restores idempotency.
Simplification done with: kiro-cli.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVluP4jgT_TXmpQQKDrc88JCG7u8bza21M9p9bFWcSuIdx87aDmz-_cpOmmloRistioQIrl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