<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clangd + clang-tidy + modernize-loop-convert = crash"
   href="https://bugs.llvm.org/show_bug.cgi?id=46961">46961</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clangd + clang-tidy + modernize-loop-convert = crash
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang-tools-extra
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>clangd
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>marzojr@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23808" name="attach_23808" title="game.cc and game.hh, the minimal testcase">attachment 23808</a> <a href="attachment.cgi?id=23808&action=edit" title="game.cc and game.hh, the minimal testcase">[details]</a></span>
game.cc and game.hh, the minimal testcase

This was tested on latest version available for Windows 10 x64. For some
reason, the version field only allowed me to select "unspecified".

The attached files (game.cc and game.hh), along with the following .clang-tidy,
form a minimal case that reproduces the crash:

    Checks: "-*,modernize-loop-convert"

A compilation database makes no difference; the crash happens with or without
it. clangd is started, in my case, by VSCode using the official llvm clangd
extension with the following option active:

    --clang-tidy

Other options can be added at will, but they make no difference. Options I have
tried:

    --background-index
    --header-insertion=iwyu
    --header-insertion-decorators
    --suggest-missing-includes
    -j=1
    --log=verbose

When checking the file with these (rather broad) settings, the attached code
causes a crash in clangd with the following stack trace:

 #0 0x000000000076f51c (C:\msys64\mingw64\bin\clangd.exe+0x36f51c)
     #1 0x000000000076f59c (C:\msys64\mingw64\bin\clangd.exe+0x36f59c)
     #2 0x000000000076a39b (C:\msys64\mingw64\bin\clangd.exe+0x36a39b)
     #3 0x0000000000c8fd10 (C:\msys64\mingw64\bin\clangd.exe+0x88fd10)
     #4 0x0000000000c91c03 (C:\msys64\mingw64\bin\clangd.exe+0x891c03)
     #5 0x0000000001bd4c1d (C:\msys64\mingw64\bin\clangd.exe+0x17d4c1d)
     #6 0x0000000001bfd5df (C:\msys64\mingw64\bin\clangd.exe+0x17fd5df)
     #7 0x0000000001bd618f (C:\msys64\mingw64\bin\clangd.exe+0x17d618f)
     #8 0x0000000001bf4f74 (C:\msys64\mingw64\bin\clangd.exe+0x17f4f74)
     #9 0x0000000001bf5b70 (C:\msys64\mingw64\bin\clangd.exe+0x17f5b70)
    #10 0x0000000001bf5017 (C:\msys64\mingw64\bin\clangd.exe+0x17f5017)
    #11 0x0000000001beca28 (C:\msys64\mingw64\bin\clangd.exe+0x17eca28)
    #12 0x0000000001bed50d (C:\msys64\mingw64\bin\clangd.exe+0x17ed50d)
    #13 0x0000000000956418 (C:\msys64\mingw64\bin\clangd.exe+0x556418)
    #14 0x0000000000957f78 (C:\msys64\mingw64\bin\clangd.exe+0x557f78)
    #15 0x000000000099a7e4 (C:\msys64\mingw64\bin\clangd.exe+0x59a7e4)
    #16 0x000000000099777f (C:\msys64\mingw64\bin\clangd.exe+0x59777f)
    #17 0x000000000098a49c (C:\msys64\mingw64\bin\clangd.exe+0x58a49c)
    #18 0x000000006fd40541 atomic_flag_test_and_set_explicit
(C:\msys64\mingw64\bin\libstdc++-6.dll+0x100541)
    #19 0x0000000064944f2e pthread_create_wrapper
(C:\msys64\mingw64\bin\libwinpthread-1.dll+0x4f2e)
    #20 0x00007fff0230b04a (C:\WINDOWS\System32\msvcrt.dll+0x3b04a)
    #21 0x00007fff0230b11c (C:\WINDOWS\System32\msvcrt.dll+

I tried to compile a debug version to get a more usable stack trace, but I gave
up after two days of linking. This stack trace was obtained with the "official"
msys2 package, but the crash also happens with the official LLVM version.

Running clang-tidy on its own does not reproduce the crash. If the checks are
inverted (Checks: "*,-modernize-loop-convert"), there is no crash in clangd.
Any of the following changes to the test case make the crash go away:

    - putting everything in only one file;
    - changing the map's key type to std::string;
    - manually converting the loop to a range-based for;
    - using a set instead of a map.

Other changes proved to be more irrelevant, and still led to the crash.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>