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

    <tr>
        <th>Summary</th>
        <td>
            Include Regrouping May Break If Macros Inserted Between Groups
        </td>
    </tr>

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

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

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

<pre>
    I have configured clang-format:

```yaml
IncludeBlocks: Regroup
IncludeCategories:
  - Regex: '^["<]config.h[">]$'
    Priority:        -1
    CaseSensitive: true
  - Regex:           '^<ext/.*\.h>$'
    Priority:        2
 CaseSensitive:   false
  - Regex:           '^<.*'
    Priority: 2
    CaseSensitive:   false
  - Regex:           '.*'
 Priority:        10
    CaseSensitive:   false
```

And my C code `a.c`:

```c
#include "config.h"

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include "a.h"

#include <stdio.h>
#include <stdlib.h>

#include "b.h"
```

However, clang-format (version 17.0.6) may not treat `a.h` as the main header but match `a.h` to regex `'.*'`:

```c
#include "config.h"

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <stdio.h>
#include <stdlib.h>

#include "a.h"
#include "b.h"
```

Meanwhile, if I remove the `#ifndef` block, everything works fine.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVctu2zoQ_RpqM7BAUw9LCy1sOc71IvdeJMiiq4CSRhIbiQxIyo7_vqAtv1qnTYEuShh-8JyZMy-PuDGikYgZiRYkWnp8sK3S2b1GlF8G6RWq2mVraPkGoVSyFs2gsYKy47KZ1Er33JJgTuiS0ON7TA-vHe-7w9Valt1Q4aJT5ashwRwesdFqeLtCc26xUVqgOTkEmDgqvjsbwmYkunNhMkaCnETLQzx-e7y7I9GSsNARR3OA_7VQWtid8zCeyfQM59zgE0ojrNig41g94A3x8xnDCHJ8t4StfMLmJMr91sn_WpuN6A-6ADXvzCel96IfKbGfZPdJlWv_N9KY0s-KnKbhckTmsoJ-BzmUqkIgMeV-6SgfDFI5_maBOIwKEMZOzWfsyogFopYV1vBy_-_zy9N_z4_53QmqsBYSb0IoK1F_7-ksx28qHfEgN7YS6jAFt9FOFJfwDYniUuJW2f5RW9ygJiy_-v8BYckGtRFKwnTmUz8mLIWe70AqC1ajo7gatySmwA3YFqHnQkKLvEINxWCh57ZsL2hWgXaz4a4uJuJvbtIfacJVn3-vPQ_I5bYVHboGiRrWoLFXG9zXe1_GMWtX38LtQkd0Hd3ZVsgGtkq_GnDJ-wePXpUFVRqk3MNsOqNxEiRRQL02q8MoZUkaprzgcRVN0zRMeOK-UE6nceSJjFEWUkYZnYZJRH0ezaJZiFVcJoiMJiSk2HPR-V236X2lG08YM2CW0GAWeh0vsDPZYbFK3MIedOlHS09nzmZSDI0hIe2EsebsxQrbYTau9OOed8k98B0sNPJXWNfwwEutDKylQW2xggXaLaKEe8c23qC7rLX2bf8kYCvCVo2w7VD4peoJWzmx8WPyptVXLN0m3odoCFvtU_gWAAD__2bf6NY">