Open nickhuang99 opened 4 months ago
Does the issue reproduce with something less ancient? E.g. LLVM 18?
Yes, I download latest git repo and it is the same crash. Using debug build, this assert causes core dump:
clang/lib/Tooling/Syntax/BuildTree.cpp:1750
const syntax::Token *syntax::TreeBuilder::findToken(SourceLocation L) const {
if (L.isInvalid())
return nullptr;
auto It = LocationToToken.find(L);
assert(It != LocationToToken.end());
return It->second;
}
FYI, using usual Release or RelDebInfo build type is a bit misleading as the crash point is when the SourceLocation is invalid or something like token not found by location etc. In short, only Debug build gives this issue at first place.
@asl Is this libLLVM.so.19.0git the evidence you are requiring to have? Currently I only have ubuntu 22.04 to test, but my gdb shows it is a kind of platform independent issue. i.e. BuildTree.cpp is using a different alglorithm than Parser.cpp has. Maybe this is the purpose to have an independent way to check clang parsing.
$ cat /tmp/test7.cpp
struct Foo {
Foo() = default;
};
$ clang-check --syntax-tree-dump /tmp/test7.cpp --
#0 0x0000735e578c51a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libLLVM.so.19.0git+0x14c51a0)
#1 0x0000735e578c275e SignalHandler(int) Signals.cpp:0:0
#2 0x0000735e56042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x0000735e5e684d84 clang::syntax::TreeBuilder::getDeclarationRange(clang::Decl*) BuildTree.cpp:0:0
#4 0x0000735e5e687107 bool (anonymous namespace)::BuildTreeVisitor::processDeclaratorAndDeclaration<clang::DeclaratorDecl>(clang::DeclaratorDecl*) BuildTree.cpp:0:0
#5 0x0000735e5e68f2cb clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) BuildTree.cpp:0:0
#6 0x0000735e5e68df63 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDecl(clang::Decl*) (.part.0) BuildTree.cpp:0:0
#7 0x0000735e5e68f2cb clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) BuildTree.cpp:0:0
#8 0x0000735e5e6a6248 clang::RecursiveASTVisitor<(anonymous namespace)::BuildTreeVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) BuildTree.cpp:0:0
#9 0x0000735e5e6a1495 clang::syntax::buildSyntaxTree(clang::syntax::Arena&, clang::syntax::TokenBufferTokenManager&, clang::ASTContext&) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3aa1495)
#10 0x00005fb397ec62d7 (anonymous namespace)::DumpSyntaxTree::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)::Consumer::HandleTranslationUnit(clang::ASTContext&) ClangCheck.cpp:0:0
#11 0x0000735e5c05bffc clang::ParseAST(clang::Sema&, bool, bool) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x145bffc)
#12 0x0000735e5e530419 clang::FrontendAction::Execute() (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3930419)
#13 0x0000735e5e4a0839 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x38a0839)
#14 0x0000735e5e73ae44 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3b3ae44)
#15 0x0000735e5e734905 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3b34905)
#16 0x0000735e5e736a1b clang::tooling::ToolInvocation::run() (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3b36a1b)
#17 0x0000735e5e738bcf clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/nick/workspace/llvm-project/install-release/bin/../lib/libclang-cpp.so.19.0git+0x3b38bcf)
#18 0x00005fb397ec7353 main (../install-release/bin/clang-check+0x7353)
#19 0x0000735e56029d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#20 0x0000735e56029e40 call_init ./csu/../csu/libc-start.c:128:20
#21 0x0000735e56029e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#22 0x00005fb397ec56b5 _start (../install-release/bin/clang-check+0x56b5)
Segmentation fault (core dumped)
clang-check always crash for option --syntax-tree-dump when a function has key word like default or delete
`