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

    <tr>
        <th>Summary</th>
        <td>
            clang::tooling::ClangTool segv when compiled with -D_GLIBCXX_DEBUG
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Maybe this has been reported before but I am not sure if anyone has come across this problem with `clang::tooling::ClangTool`. Is `libTooling` not compatible with `-D_GLIBCXX_DEBUG`.

The backtrace is as follows:
```
(gdb) bt
#0  0x00007ffff7d416c3 in __gnu_debug::_Safe_sequence_base::_M_detach_all() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x0000555555ae6f78 in __gnu_debug::_Safe_sequence_base::~_Safe_sequence_base (this=0x7fffffffdaa0, __in_chrg=<optimized out>)
    at /usr/include/c++/11/debug/safe_base.h:221
#2  0x0000555555ae7652 in __gnu_debug::_Safe_sequence<std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::~_Safe_sequence (this=0x7fffffffdaa0, __in_chrg=<optimized out>) 
    at /usr/include/c++/11/debug/safe_sequence.h:108
#3  0x0000555555ae7672 in __gnu_debug::_Safe_container<std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_debug::_Safe_sequence, true>::~_Safe_container (this=0x7fffffffdaa0, __in_chrg=<optimized out>)
    at /usr/include/c++/11/debug/safe_container.h:41
#4  0x0000555555ae76c2 in std::__debug::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~vector (this=0x7fffffffdaa0, __in_chrg=<optimized out>)
    at /usr/include/c++/11/debug/vector:231
#5  0x0000555555ae665a in main (argc=2, argv=0x7fffffffdd18)
    at /home/***/llvm-project/clang-tools-extra/my-clang-preprocessor/src/main.cpp:111
```

the compiler I used to compile `libTooling` is:
```
c++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

fyi, a part of the `main.cpp` looks like this:
```
int main(int argc, const char** argv) {
  std::string_view source_dir = argv[1];
  std::string errmsg;
  auto p_cd = clang::tooling::CompilationDatabase::autoDetectFromDirectory(source_dir, errmsg);
  if (!p_cd) {
    std::terminate();
  }
 clang::tooling::ClangTool ct(*p_cd, p_cd->getAllFiles());  // SEGV HERE!!!!!!!
  return ct.run(clang::tooling::newFrontendActionFactory<MyAstFrontendAction>().get());
}
```


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsV09v2zoS_zT0ZWBBomzZPvjgf-oz0LRF4izengSKGkl8lUkvScXxHvrZF6Rkx82_7qLA9h0aKLbJGXJ-M_PjaMiMEZVEnJPxkozXA9baWun5X6j1iYfjQa6K0_yGnXIEWwsDNTOQI0rQeFDaYgE5lkoj5K2FLbA9SGXBtBpBlMDkSUn0i7jaIzCulTHdTget8gb3cBS2BpKEvGGyIvGCxAurVCPOg5Wb3ynVkCQMYGucbiPyXa-ThN4iV_sDsyJv8LLhcJ19-Lhdrv78M1tvlvcf3HoSrkm46D53NULO-FerGUcQBpiBUjWNOhpnudNMwv7phnRaFTmhM8jteSYOAcLHMAzDSVmW5aQYRQmPQUjIskq2WYF527uS3bESM4P_alFyzHJmsBfcZAVaxuuMNQ2hU2eh_yq12gOhaSNyQtPHaZIlo2EjZP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