<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60721>60721</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format alignment malfunctions near preprocessor ifdef blocks
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mbeall-cricut
</td>
</tr>
</table>
<pre>
# Clang-format alignment near preprocessor ifdef blocks
When using ifdef blocks for hardware configurations, clang-format assignment and comment alignment seem to misbehave.
Using `clang-format` version 15.0.6
Issue arises when using the following `.clang-format` style file:
```
BasedOnStyle: LLVM
BreakBeforeBraces: Allman
ColumnLimit: 180
IndentWidth: 2
IndentPPDirectives: BeforeHash
TabWidth: 2
UseTab: Never
BreakBeforeBraces: Allman
InsertBraces: true
BreakBeforeBinaryOperators: None
KeepEmptyLinesAtTheStartOfBlocks: false
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
AlignTrailingComments: true
AlignConsecutiveMacros: Consecutive
SpacesBeforeTrailingComments: 1
AllowShortFunctionsOnASingleLine: Empty
PointerAlignment: Left
SortIncludes: Never
```
The resulting formatting looks like this:
```
void myFunction()
{
#ifdef CONFIG_OPTION_1
const uint8_t My_Big_Long_Variable_Divisor = 0x2;
#else
const uint8_t My_Big_Long_Variable_Divisor = 0x3;
#endif
// Comment
BITREGISTER.REGBITS1 = 1; // same line comment
BITREGISTER.REGBITS2 = My_Big_Long_Variable_Divisor; // same line comment
#ifdef CONFIG_OPTION_2
BITREGISTER.BITS3 = 0; // same line comment
#else
BITREGISTER.BITS3 = 1; // same line comment
#endif
}
```
## Expected behavior
I would expect adjacent assignments across preprocessor directives to be aligned as if they are actually adjacent. In the example above, I would expect this result:
```
void myFunction()
{
#ifdef CONFIG_OPTION_1
const uint8_t My_Big_Long_Variable_Divisor = 0x2;
#else
const uint8_t My_Big_Long_Variable_Divisor = 0x3;
#endif
// Comment
BITREGISTER.REGBITS1 = 1; // same line comment
BITREGISTER.REGBITS2 = My_Big_Long_Variable_Divisor; // same line comment
#ifdef CONFIG_OPTION_2
BITREGISTER.BITS3 = 0; // same line comment
#else
BITREGISTER.BITS3 = 1; // same line comment
#endif
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVl9v4jgQ_zTmZVQUHKDwkAf-lD10bakKu_uIHGeSeOvYyHagfPuTndBStu2uTndPdwiF4Bn_5o9_M2NmrSgUYkIGUzKYd1jtSm2SKkUm5RU3gteuk-rsmBAaw0wyVVzl2lTMAZOiUBUqBwqZgZ3BndEcrdUGRJ5hDqnU_MmSaE6iyfcSFdRWqOKNEHJtoGQmOzCDwLXKRVEb5oRWltAZ8DcWg7PBJFMZcF017y-OWMQKnIZK2BRLtsduY7x5fg3WyTA6ByXDCPZorNAKeoNu1B2eb2meS2trBGaERQuH10BciZBrKfWhBe5eIlt3lAi5kEjiE-Qwar_h75RZzFZq7RVJPIHb2293rcQge5pirg1ODeNovXgiZcVUozDTsq7UraiE86LeqIVcqgyV-y4yV_p1er768DAXBrkT-wavwf-D2bLR2rD0cuNXixuW-oV73KP5TeeWyqJxrzJnavx5q1DMHFc7NMxpE_TutWr1_kTc3VQ7d7wVCu3EbUpcO2bcKp82vIonkDNpW_WJZ8FMK4u89uFNXsgSNM8k7-vPkUt2Yt6HGzaGCSlUMWu4dxHaJeYd40a_j7be-cw0aXgPtHdClPqwLrVxi1rx4NxKTdZCFRJ9XrxqSFKj_qCFcmgmp4oIjMLctTa1cUvFZZ01Z3J2nhesbMlQIhi0tXSe3w2rw6vU-smCFE8IrhT2I27vtcigOp48J3RE6LjVvJ62LzRu-sFsdb9YftmuHjbL1f22DR98S7AOaqHcaOvg7ridimJ7q1Wx_caMYKnE7VzshW86JJ5D9ExJ_AqNL_T4G0jxGySVifw8OQCELghdQHtq7ep0uXm8-bJcb24eu483X6bLzboX8HoknsInnxbNsgpBCoWn9vY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