llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.31k stars 12.11k forks source link

clang::tooling::ClangTool segv when compiled with -D_GLIBCXX_DEBUG #61180

Open jerryc05 opened 1 year ago

jerryc05 commented 1 year ago

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());
}
jerryc05 commented 1 year ago

the git version I used is

$ git log
commit c0b4ca107a3b605f810bd60642907e6a77f7c6d3 (grafted, HEAD -> main, origin/main, origin/HEAD)
Author: Med Ismail Bennani <medismail.bennani@gmail.com>
Date:   Fri Mar 3 19:44:44 2023 -0800

    [lldb] Simplify error string in ScriptedInterface (NFC)

    Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>