<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60357>60357</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] wrong formatting when using the `--lines=` option
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kleisauke
      </td>
    </tr>
</table>

<pre>
    For example:
```c
#include <stdio.h>

int main(void) {
#ifdef _WIN32
  printf("Hello Windows!\n");
#else  /*!_WIN32*/
  printf("Hello World!\n");
#endif /*_WIN32*/

#ifdef DEBUG
  printf("Debug enabled!\n");
#endif /*DEBUG*/

  return 0;
}
```

```console
$ clang-format --lines=6:7 test.c > test-lines-6-7.out
$ clang-format test.c > test-all.out
$ diff test-lines-6-7.out test-all.out
6c6
< #else /*!_WIN32*/
---
> #else  /*!_WIN32*/
$ echo $?
1
```

Removing the `DEBUG` preprocessor block fixes this, for example:
```diff
@@ -7,9 +7,5 @@ int main(void) {
   printf("Hello World!\n");
 #endif /*_WIN32*/
 
-#ifdef DEBUG
-  printf("Debug enabled!\n");
-#endif /*DEBUG*/
-
   return 0;
 }
```

```console
$ clang-format --lines=6:7 test.c > test-lines-6-7.out
$ clang-format test.c > test-all.out
$ diff test-lines-6-7.out test-all.out
$ echo $?
0
```

So, it looks like it's trying to incorrectly align the `/*!_WIN32*/` comment to the `DEBUG` preprocessor block.

Tested with the latest revision (commit df34581d2b004e20fda85b4c8617bf436e826f6c at the time of writing):
```console
$ clang-format --version
clang-format version 17.0.0 (https://github.com/llvm/llvm-project.git df34581d2b004e20fda85b4c8617bf436e826f6c)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVkuT4jgM_jXKRZWU4zw55NANze5e9rCPmuNWHkrixdiU7cDMv99yCEM_GHq4bhUFjmR9-iR9AmprxaCIKsieIdsE9eRGbaqdJGHraUdBo7tv1VYbpK_1_iAJkidgG2BPkLPzq12eeSJUK6eOEJK1dZ3Q0QjJy-Kd34VyuK-FAl4eteiArxCK52t831GP_3z57feEn42IByOU64GXwPmvJKXGL0J1-mSBx5CtFXAOfAXJFYWkJUTgW-BPwOMFzp-3d0C1kd2PIVUn-gXyI947_puX579_uZVpQ800IKm6kfRzuc5QH1IhGnKTUciugcXm3VjecPs-K62slnRJlmIrazWEvTb72mEYSqHIQrLJIXkq0JF1UYuQvMzHszfMwyLSk_sBxvuYWsq3tzvR9zfgbtzO23wJS9Z4GeyduYZheLn_gj8jBE-H2lEj8BSSxRjf6eMftNdHoQZ0IyHk7DyfnOHB0MHolqzVBhup2x324itZdKOwwNfY39sg35LFlDJIGYYF8PUKgT_7Q4aL-d764IOqxk9ljUtXbwk7fFjZ4WfSDr_X8UHc-H9U903xsTtl_qm9kIRDqfXOohQ7QuGAFxad-TarUqNQrTaGWie_YS3FoC5Svb0GOcNW7_eknA_-XNXRa0J_kXXU4Um4cQ6Vta8SDR2FFVoh8NKDC4ddn6RZGXe8YSwlzvquLrMmbcs8Lpo-TXIqed7nLfoWj4RO7Al1jycjnFDDrKNHh30k41mc_W98iwfjImIR8zRH5w7Wp_BN2g7CjVMTtXoPfCvl8fIRHoz-l1oXDQ-U5Lm_JR50VdKtklUdUBXnRbpKspRnwVgVMcvKtuR1ylZNnua8S3veU5FmGTVpywJRccYTFvMyXmWMZxF5Z1EmvM2yrChrSBntayEjTzfSZgiEtRNVOUuyIpB1Q9LOv_ScKzrh7PR7mm0CU80lNtNgIWVSWGevKE44Of9FeN1HyDZ4MloNeH72k8LTSAon--o78rp2XlL64IRWwWRk9VjTgW9nuhb4di7nvwAAAP__54F1eQ">