[llvm-bugs] [Bug 41483] New: clang-format: /**/ before macro removes line breaks and runs 200x slower

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 12 11:30:11 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=41483

            Bug ID: 41483
           Summary: clang-format: /**/ before macro removes line breaks
                    and runs 200x slower
           Product: clang
           Version: 8.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: Formatter
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bjehlert at gmail.com
                CC: djasper at google.com, klimek at google.com,
                    llvm-bugs at lists.llvm.org

Created attachment 21770
  --> https://bugs.llvm.org/attachment.cgi?id=21770&action=edit
Code to repo the issue

Given this code (C++):

  #define FOO(a, b, c) class a { static const char* b() const { return c; } };

  /**/ FOO(a,        aa,            "aaa")
  FOO(aah,        aahed,            "aahing")
  FOO(aahs,        aal,            "aalii")

  FOO(aaliis,        aals,            "aam")
  FOO(aani,        aardvark,            "aardvarks")

The comment block /**/ before the first FOO() causes all subsequent calls to
FOO() to be merged into a single line:

  /**/ FOO(a, aa, "aaa") FOO(aah, aahed, "aahing") FOO(aahs, aal, "aalii")

      FOO(aaliis, aals, "aam") FOO(aani, aardvark, "aardvarks")

When a file contains ~1000 of these calls to FOO(), the results are completely
unreadable as it generates lines which are several thousand columns wide.
Simply removing the /**/ fixes the issue, leaving each FOO() on its own line
but removes all the extra spaces.

Additionally, when run on a file with ~1000 calls to FOO(), clang-format takes
200x longer to run when the file contains a /**/ before the first call to FOO()
(0.20 vs. 40 seconds on i7-5820K).

I've attached a file containing a repro which is the above code with 1000 calls
to FOO() each on their own line. Removing the /**/ before the first call to
FOO() on line 4 to see the behavior changes.

Repro: clang-format -style=llvm foo1000.cpp

The behavior I'd expect is each call to FOO() remain on its own line, with the
first one still containing the comment block and the performance to be
generally equivalent.

Expected:

  /**/ FOO(a, aa, "aaa")
  FOO(aah, aahed, "aahing")
  FOO(aahs, aal, "aalii")

  FOO(aaliis, aals, "aam")
  FOO(aani, aardvark, "aardvarks")

First noticed this issue on 7.0.0, still occurs on 8.0.0.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190412/fdb2fdad/attachment.html>


More information about the llvm-bugs mailing list