Skip to content

[clang-format] Clang format takes way too long to format some preproc macros #142426

Open
@JustLinuxUser

Description

@JustLinuxUser

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,

#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:

#define VALUE 0
#include "counter.h"
// now the VALUE is 1
#include "counter.h"
// now the VALUE is 2

counter.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions