cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
949 stars 104 forks source link

cmake-format hangs for particular input #291

Open lxbrz opened 2 years ago

lxbrz commented 2 years ago

Hi,

when running cmake-format -i /tmp/test.cmake

on

test.cmake:

if(((NOT (IMAGE_NAME STREQUAL "foo1")) OR FOO)
        AND (NOT (BOARD MATCHES "foo2" AND (

            IMAGE_NAME STREQUAL "foo3"
        OR IMAGE_NAME STREQUAL "foo4"
        OR IMAGE_NAME STREQUAL "foo5")
    )))
    message(VERBOSE "foo6")
endif()

the formatting seems to hang, the CPU usage of one core is a 100%, whereas a slightly altered (foo4 removed) input test.cmake finishes:

if(((NOT (IMAGE_NAME STREQUAL "foo1")) OR FOO)
        AND (NOT (BOARD MATCHES "foo2" AND (

            IMAGE_NAME STREQUAL "foo3"
        OR IMAGE_NAME STREQUAL "foo5")
    )))
    message(VERBOSE "foo6")
endif()

becomes

if(((NOT (IMAGE_NAME STREQUAL "foo1")) OR FOO)
   AND (NOT (BOARD MATCHES "foo2" AND (IMAGE_NAME STREQUAL "foo3"
                                       OR IMAGE_NAME STREQUAL "foo5"))))
  message(VERBOSE "foo6")
endif()

in:

real    0m0,157s
user    0m0,132s
sys     0m0,024s

while the problematic input doesn't finish within a couple minutes.

cmake-format version is 0.6.13 on Ubuntu 22.04