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

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Clang format takes way too long to format some preproc macros
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang,
            clang-format
      </td>
    </tr>

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

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

<pre>
    I have been playing around with the preproc macros, and I created a binary counter with the macros. A curious thing I noticed, is that clang-format quickly runs out of memory formatting this file.

I've simplified the file, to the minimum laggy example, let's call it example.h,
```c
#if b0 == 1
# if b1 == 1
#    if b2 == 1
#      if b3 == 1
#        if b4 == 1
# if b5 == 1
#            if b6 == 1
#              if b7 == 1
# if b8 == 1
#                  if b9 == 1
#                    if b10 == 1
#                      if b11 == 1
#                        if b12 == 1
#                          if b13 == 1
#                            if b14 == 1
#                              if b15 == 1
# else
#                              endif
# else
#                            endif
# else
#                          endif
#                        else
# endif
#                      else
# endif
#                    else
#                    endif
# else
#                  endif
#                else
# endif
#              else
#              endif
#            else
# endif
#          else
#          endif
#        else
# endif
#      else
#      endif
#    else
#    endif
#  else
# endif
#endif
```
calling `clang-format example.h` takes ~10s on my computer, adding one more bit ~20s
It seams like clang-format is checking every combination of possibilities of the preprocessor macros, and I don't understand why.

I've also attached the original counter.h example, here is how to use it:
```c
#define VALUE 0
#include "counter.h"
// now the VALUE is 1
#include "counter.h"
// now the VALUE is 2
```
[counter.txt](https://github.com/user-attachments/files/20555612/counter.txt)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVk1zozgQ_TXi0hWXLD5sHzh44nVVtuY6exeiMdoIidVHEl_mt28JzMR2sJNQqSJ0v_fUavBrcefkQSOWJP9B8l3Cg2-NLf8Ozv-UOrz9cmiTytTH8gla_oJQIWroFT9KfQBuTdA1vErfgm8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