Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy segfault #101323

Closed
sonofR9 opened this issue Jul 31, 2024 · 8 comments
Closed

clang-tidy segfault #101323

sonofR9 opened this issue Jul 31, 2024 · 8 comments
Labels
clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate

Comments

@sonofR9
Copy link

sonofR9 commented Jul 31, 2024

[build] Error running 'clang-tidy': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
[build] Stack dump:
[build] 0. Program arguments: clang-tidy --export-fixes=fixes.yaml --use-color -p= --extra-arg-before=--driver-mode=g++ /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp -- /usr/local/bin/clang++ -DQT_CORE_LIB -Duniplugin_socket_EXPORTS -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -I/usr/include/jsoncpp -I/usr/dgate/include -I/home/novak_share/repos/socket-dgate/src/plugin/net_part -I/home/novak_share/repos/socket-dgate/src/plugin/. -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/home/novak_share/repos/socket-dgate/src/tesla-interface/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -g -std=gnu++17 -fPIC -Wall -Wextra -Wpedantic -Wswitch-enum -Wno-c++20-designator -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -DPARSEC -D__UNICODE -D__UTF8 -D__STDC_FORMAT_MACROS -D__PGIFACE_VIRTUAL -I/usr/include/jsoncpp -I/usr/include -I/usr/dgate/include -DQT_XML_LIB -DQT_XMLPATTERNS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/usr/include/x86_64-linux-gnu/qt5/QtCore -fPIC -MD -MT src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -MF src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o.d -o src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -c /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp
[build] 1. parser at end of file
[build] 2. ASTMatcher: Matching 'cppcoreguidelines-owning-memory' against:
[build] CXXMethodDecl DynamicAddressResolver::onReadFromTesla : </home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp:390:1, line:532:1>
[build] Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
[build] 0 clang-tidy 0x0000000003ab4418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
[build] 1 clang-tidy 0x0000000003ab1c6c
[build] 2 libpthread.so.0 0x000075ec01c74730
[build] 3 clang-tidy 0x0000000002a8eef0 clang::ASTNodeKind::getFromNode(clang::Stmt const&) + 0
[build] 4 clang-tidy 0x000000000291634f
[build] 5 clang-tidy 0x0000000002918266
[build] 6 clang-tidy 0x00000000029197a8
[build] 7 clang-tidy 0x000000000291fabc
[build] 8 clang-tidy 0x0000000002916fab
[build] 9 clang-tidy 0x00000000029197a8
[build] 10 clang-tidy 0x000000000291f903
[build] 11 clang-tidy 0x000000000292cac8
[build] 12 clang-tidy 0x0000000002915069
[build] 13 clang-tidy 0x000000000292d326
[build] 14 clang-tidy 0x000000000292e178
[build] 15 clang-tidy 0x0000000000a92340
[build] 16 clang-tidy 0x000000000294b873 clang::ast_matchers::internal::DynTypedMatcher::matchesNoKindCheck(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 195
[build] 17 clang-tidy 0x000000000294ba1e
[build] 18 clang-tidy 0x000000000294c681
[build] 19 clang-tidy 0x000000000294bb21 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 209
[build] 20 clang-tidy 0x0000000000c46ac8
[build] 21 clang-tidy 0x000000000294bb21 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 209
[build] 22 clang-tidy 0x000000000290f7be
[build] 23 clang-tidy 0x0000000002930c7a
[build] 24 clang-tidy 0x00000000029315ea
[build] 25 clang-tidy 0x000000000294137d
[build] 26 clang-tidy 0x0000000002930c85
[build] 27 clang-tidy 0x0000000002930f11 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) + 513
[build] 28 clang-tidy 0x0000000001a1d368 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) + 40
[build] 29 clang-tidy 0x0000000001c63f91 clang::ParseAST(clang::Sema&, bool, bool) + 1105
[build] 30 clang-tidy 0x00000000019e7ed1 clang::FrontendAction::Execute() + 145
[build] 31 clang-tidy 0x000000000196a2da clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 298
[build] 32 clang-tidy 0x0000000001239c0e clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptrclang::CompilerInvocation, clang::FileManager*, std::shared_ptrclang::PCHContainerOperations, clang::DiagnosticConsumer*) + 302
[build] 33 clang-tidy 0x00000000011e8bf5
[build] 34 clang-tidy 0x0000000001233dd3 clang::tooling::ToolInvocation::run() + 1315
[build] 35 clang-tidy 0x00000000012376cd clang::tooling::ClangTool::run(clang::tooling::ToolAction*) + 3373
[build] 36 clang-tidy 0x00000000011f4845 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits, std::allocator>>, llvm::IntrusiveRefCntPtrllvm::vfs::OverlayFileSystem, bool, bool, llvm::StringRef) + 965
[build] 37 clang-tidy 0x0000000000a1be01 clang::tidy::clangTidyMain(int, char const**) + 1905
[build] 38 libc.so.6 0x000075ec0177609b __libc_start_main + 235
[build] 39 clang-tidy 0x0000000000a138ca _start + 42
[build] Segmentation fault

Clang-tidy version:
LLVM (http://llvm.org/):
LLVM version 18.1.1
Optimized build.
System: proprietary linux based on Debian (I don't know version on which it is based). Kernel version: 5.15.0-70-generic.

@sonofR9
Copy link
Author

sonofR9 commented Jul 31, 2024

Added llvm-symbolizer to path:

  1.  Program arguments: clang-tidy --export-fixes=fixes.yaml --use-color -p= --extra-arg-before=--driver-mode=g++ /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp -- /usr/local/bin/clang++ -DQT_CORE_LIB -Duniplugin_socket_EXPORTS -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -I/usr/include/jsoncpp -I/usr/dgate/include -I/home/novak_share/repos/socket-dgate/src/plugin/net_part -I/home/novak_share/repos/socket-dgate/src/plugin/. -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/home/novak_share/repos/socket-dgate/src/tesla-interface/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -g -std=gnu++17 -fPIC -Wall -Wextra -Wpedantic -Wswitch-enum -Wno-c++20-designator -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -DPARSEC -D__UNICODE -D__UTF8 -D__STDC_FORMAT_MACROS -D__PGIFACE_VIRTUAL -I/usr/include/jsoncpp -I/usr/include -I/usr/dgate/include -DQT_XML_LIB -DQT_XMLPATTERNS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/usr/include/x86_64-linux-gnu/qt5/QtCore -fPIC -MD -MT src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -MF src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o.d -o src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -c /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp
    
  2.  <eof> parser at end of file
    
  3.  ASTMatcher: Matching 'cppcoreguidelines-owning-memory' against:
     CXXMethodDecl DynamicAddressResolver::onReadFromTesla : </home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp:390:1, line:532:1>
    

#0 0x0000000003ab4418 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/clang-18/bin/clang-tidy+0x3ab4418)
#1 0x0000000003ab1c6c SignalHandler(int) Signals.cpp:0:0
#2 0x000078d64e01b730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
#3 0x0000000002a8eef0 clang::ASTNodeKind::getFromNode(clang::Stmt const&) (/usr/local/clang-18/bin/clang-tidy+0x2a8eef0)
#4 0x000000000291634f clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseLambdaExpr(clang::LambdaExpr*) ASTMatchFinder.cpp:0:0
#5 0x0000000002918266 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraitsclang::Stmt*, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraitsclang::Stmt*>>>) ASTMatchFinder.cpp:0:0
#6 0x00000000029197a8 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseStmt(clang::Stmt
, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraitsclang::Stmt*, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraitsclang::Stmt*>>>) (.part.6629) ASTMatchFinder.cpp:0:0
#7 0x000000000291fabc clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseCXXForRangeStmt(clang::CXXForRangeStmt
) ASTMatchFinder.cpp:0:0
#8 0x0000000002916fab clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraitsclang::Stmt*, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraitsclang::Stmt*>>>) ASTMatchFinder.cpp:0:0
#9 0x00000000029197a8 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseStmt(clang::Stmt
, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraitsclang::Stmt*, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraitsclang::Stmt*>>>) (.part.6629) ASTMatchFinder.cpp:0:0
#10 0x000000000291f903 clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseStmt(clang::Stmt
, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraitsclang::Stmt*, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraitsclang::Stmt*>>>) (.constprop.6958) ASTMatchFinder.cpp:0:0
#11 0x000000000292cac8 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl
) ASTMatchFinder.cpp:0:0
#12 0x0000000002915069 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#13 0x000000000292d326 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchesRecursively(clang::DynTypedNode const&, clang::ast_matchers::internal::DynTypedMatcher const&, clang::ast_matchers::internal::BoundNodesTreeBuilder*, int, clang::ast_matchers::internal::ASTMatchFinder::BindKind) ASTMatchFinder.cpp:0:0
#14 0x000000000292e178 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchesDescendantOf(clang::DynTypedNode const&, clang::ASTContext&, clang::ast_matchers::internal::DynTypedMatcher const&, clang::ast_matchers::internal::BoundNodesTreeBuilder*, clang::ast_matchers::internal::ASTMatchFinder::BindKind) ASTMatchFinder.cpp:0:0
#15 0x0000000000a92340 clang::ast_matchers::internal::HasDescendantMatcher<clang::FunctionDecl, clang::Stmt>::matches(clang::FunctionDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-18/bin/clang-tidy+0xa92340)
#16 0x000000000294b873 clang::ast_matchers::internal::DynTypedMatcher::matchesNoKindCheck(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-18/bin/clang-tidy+0x294b873)
#17 0x000000000294ba1e clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRefclang::ast_matchers::internal::DynTypedMatcher)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const ASTMatchersInternal.cpp:0:0
#18 0x000000000294c681 clang::ast_matchers::internal::(anonymous namespace)::IdDynMatcher::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const ASTMatchersInternal.cpp:0:0
#19 0x000000000294bb21 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-18/bin/clang-tidy+0x294bb21)
#20 0x0000000000c46ac8 clang::ast_matchers::internal::TraversalMatcherclang::Decl::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-18/bin/clang-tidy+0xc46ac8)
#21 0x000000000294bb21 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-18/bin/clang-tidy+0x294bb21)
#22 0x000000000290f7be clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
#23 0x0000000002930c7a clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#24 0x00000000029315ea clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.6777) ASTMatchFinder.cpp:0:0
#25 0x000000000294137d clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0
#26 0x0000000002930c85 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#27 0x0000000002930f11 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/usr/local/clang-18/bin/clang-tidy+0x2930f11)
#28 0x0000000001a1d368 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/clang-18/bin/clang-tidy+0x1a1d368)
#29 0x0000000001c63f91 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/clang-18/bin/clang-tidy+0x1c63f91)
#30 0x00000000019e7ed1 clang::FrontendAction::Execute() (/usr/local/clang-18/bin/clang-tidy+0x19e7ed1)
#31 0x000000000196a2da clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/clang-18/bin/clang-tidy+0x196a2da)
#32 0x0000000001239c0e clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptrclang::CompilerInvocation, clang::FileManager*, std::shared_ptrclang::PCHContainerOperations, clang::DiagnosticConsumer*) (/usr/local/clang-18/bin/clang-tidy+0x1239c0e)
#33 0x00000000011e8bf5 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits, std::allocator>>, llvm::IntrusiveRefCntPtrllvm::vfs::OverlayFileSystem, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptrclang::CompilerInvocation, clang::FileManager*, std::shared_ptrclang::PCHContainerOperations, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0
#34 0x0000000001233dd3 clang::tooling::ToolInvocation::run() (/usr/local/clang-18/bin/clang-tidy+0x1233dd3)
#35 0x00000000012376cd clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/usr/local/clang-18/bin/clang-tidy+0x12376cd)
#36 0x00000000011f4845 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits, std::allocator>>, llvm::IntrusiveRefCntPtrllvm::vfs::OverlayFileSystem, bool, bool, llvm::StringRef) (/usr/local/clang-18/bin/clang-tidy+0x11f4845)
#37 0x0000000000a1be01 clang::tidy::clangTidyMain(int, char const**) (/usr/local/clang-18/bin/clang-tidy+0xa1be01)
#38 0x000078d64db1d09b __libc_start_main /opt/build/glibc-2.28/csu/../csu/libc-start.c:342:3
#39 0x0000000000a138ca _start (/usr/local/clang-18/bin/clang-tidy+0xa138ca)
Segmentation fault

@sonofR9
Copy link
Author

sonofR9 commented Jul 31, 2024

Function on which it happens (code is bad, but...)

void DynamicAddressResolver::onReadFromTesla(const AddressResolveFromTesla& resolved)
{
    std::unique_lock lock{tasksMutex_};
    auto* plugin{pluginP_->plugin_};
    plugin->log(DGateBaseAPI::LogDebug,
                "Processing new address resolve result '%d'",
                resolved.description.index());

    switch (static_cast<AddressResolveFromTesla::Type>(resolved.description.index()))
    {
    case AddressResolveFromTesla::RouteToDgate: {
        plugin->log(DGateBaseAPI::LogDebug, "Got route to dgate");
        const auto& toDgate{std::get<RouteToDgateInfo>(resolved.description)};
        const auto& route{toDgate.route};
        if (!route.hasFrom)
        {
            plugin->log(DGateBaseAPI::LogDebug, "No source for msg to dgate, skipping");
            if (messagesFromSocketByUniqueNumber_.count(toDgate.originalUniqueNumber) != 0)
            {
                messagesFromSocketByUniqueNumber_.erase(toDgate.originalUniqueNumber);
            }
            return;
        }

        auto from{route.from};
        auto to{route.to};
        auto msg{std::move(messagesFromSocketByUniqueNumber_.at(toDgate.originalUniqueNumber))};
        messagesFromSocketByUniqueNumber_.erase(toDgate.originalUniqueNumber);

        if (to.empty())
        {
            plugin->log(DGateBaseAPI::LogDebug, "Got message without destination, skipping");
            return;
        }

        std::string_view msgBody{msg->body()};
        std::string cuttedMsg{msgBody.substr(0, std::min<size_t>(80, msgBody.size()))};
        plugin->log(DGateKernelAPI::LogDebug,
                    "Message '%s' is accepted to processing",
                    cuttedMsg.data());

        // TODO() ref make it smaller
        taskQueue_.emplace(
                [this,
                 from = std::move(from),
                 to = std::move(to),
                 dgateMsg = msg.release(),  // because function must be copyable
                 cuttedMsg = std::move(cuttedMsg),
                 plugin]() mutable -> void {
                    using FullyAccessibleDgateMessage = tesla_dgate::FullyAccessibleDgateMessage;
                    plugin->log(DGateKernelAPI::LogDebug,
                                "Start processing msg '%s'",
                                cuttedMsg.data());

                    auto remoteAddress{endpointToDgateAddr(from)};

                    SocketMessage message(
                            pluginP_,
                            std::unique_ptr<FullyAccessibleDgateMessage>(dgateMsg),
                            remoteAddress,
                            endpointToDgateAddr(pluginP_->localAddress_, pluginP_->localPort_));
                    gsl::owner<DGateAddress**> addresses{new DGateAddress*[to.size()]};
                    for (std::size_t i{0}; i < to.size(); ++i)
                    {
                        // NOLINTNEXTLINE
                        addresses[i] = new SocketAddress(endpointToDgateAddr(to[i]).c_str());
                    }
                    message.setTo(addresses, static_cast<int>(to.size()));

                    int id = plugin->saveMessage(&message);
                    if (id == 0)
                    {
                        plugin->log(DGateKernelAPI::LogErr,
                                    "Error while saving message '%s'",
                                    cuttedMsg.data());
                        return;
                    }

                    if (!plugin->sendMessage(id))
                    {
                        plugin->log(DGateKernelAPI::LogErr,
                                    "Error while sending message '%s'",
                                    cuttedMsg.data());
                        return;
                    }
                });
        tasksCv_.notify_all();
    }
    break;
    case AddressResolveFromTesla::RouteToSocket: {
        plugin->log(DGateBaseAPI::LogDebug, "Got route to socket");
        const auto& toSocket{std::get<RouteToSocketInfo>(resolved.description)};
        const auto& route{toSocket.route};
        SocketInfo from = route.hasFrom ? route.from : SocketInfo{};

        auto msg{std::move(messagesFromDgateByUniqueNumber_.at(toSocket.originalUniqueNumber))};
        messagesFromDgateByUniqueNumber_.erase(toSocket.originalUniqueNumber);

        if (!route.hasFrom || from.ip != pluginP_->localAddress_ ||
            from.port != pluginP_->localPort_)
        {  // send as client
            std::shared_ptr<DGateMessage> msgShared{msg.get()};
            for (const auto& to: route.to)
            {
                SocketPair socketPair{.local = from, .remote = to};
                if (clientsByConnection_.count(socketPair) == 0)
                {
                    auto client{std::make_unique<SocketClient>(
                            this,
                            pluginP_,
                            socketPair.local.ip,
                            socketPair.local.port,
                            socketPair.remote.ip,
                            socketPair.remote.port)};
                    client->startThread();
                    socketPair.local.port = client->getLocalPort();
                    clientsByConnection_[socketPair] = std::move(client);
                }
                if (!clientsByConnection_[socketPair]->waitToConnect())
                {
                    taskQueue_.emplace([plugin, msg]() {
                        plugin->setMessageProcessingStatus(
                                msg->dgateId(), DGateKernelAPI::ProcessingError);
                        delete msg;
                        int len{0};
                        plugin->log(DGateBaseAPI::LogDebug,
                                    "error while sending message %s: can't connect to remote "
                                    "socket",
                                    msg->nativeId(len));
                    });
                    return;
                }
                clientsByConnection_[socketPair]->onMessageFromDgate(msgShared, true, {to});
            }
        } else  // send as server
        {
            server_->onMessageFromDgate(std::move(msg), true, route.to);
        }
        // delete msg;
    }
    break;
    }
}

@firewave firewave added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Jul 31, 2024
@PiotrZSL
Copy link
Member

Could you test on Clang-tidy 19 ?
There is a chance that this issue were somehow fixed by 0a40f5d.

@sonofR9
Copy link
Author

sonofR9 commented Jul 31, 2024

I'll test within 24-48 hours probably.

@sonofR9
Copy link
Author

sonofR9 commented Aug 1, 2024

Clang-tidy still crashes((

clang-tidy --version
LLVM (http://llvm.org/):
LLVM version 19.1.0-rc1
Optimized build.

Stacktrace seems to look the same, but just in case:

Error running 'clang-tidy': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-tidy --export-fixes=fixes.yaml --use-color -p= --extra-arg-before=--driver-mode=g++ /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp -- /usr/local/bin/clang++ -DQT_CORE_LIB -Duniplugin_socket_EXPORTS -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -I/usr/include/jsoncpp -I/usr/dgate/include -I/home/novak_share/repos/socket-dgate/src/plugin/net_part -I/home/novak_share/repos/socket-dgate/src/plugin/. -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/home/novak_share/repos/socket-dgate/src/tesla-interface/include -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -g -std=gnu++17 -fPIC -Wall -Wextra -Wpedantic -Wswitch-enum -Wno-c++20-designator -I/usr/local/udps/include -I/usr/local/metamanager/include -I/usr/local/ods/include -I/usr/local/ptconvert/include -I/usr/local/tesla/include -I/usr/local/seal/include -I/usr/local/base/include -DPARSEC -D__UNICODE -D__UTF8 -D__STDC_FORMAT_MACROS -D__PGIFACE_VIRTUAL -I/usr/include/jsoncpp -I/usr/include -I/usr/dgate/include -DQT_XML_LIB -DQT_XMLPATTERNS_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/include/x86_64-linux-gnu/qt5/QtXml -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtXmlPatterns -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/usr/include/x86_64-linux-gnu/qt5/QtCore -fPIC -MD -MT src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -MF src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o.d -o src/plugin/CMakeFiles/uniplugin_socket.dir/dynamic_address_resolver.cpp.o -c /home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp
1.      <eof> parser at end of file
2.      ASTMatcher: Matching 'cppcoreguidelines-owning-memory' against:
        CXXMethodDecl DynamicAddressResolver::onReadFromTesla : </home/novak_share/repos/socket-dgate/src/plugin/dynamic_address_resolver.cpp:390:1, line:532:1>
 #0 0x0000630927e41e78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/clang-19/bin/clang-tidy+0x3e47e78)
 #1 0x0000630927e3fc3e llvm::sys::RunSignalHandlers() (/usr/local/clang-19/bin/clang-tidy+0x3e45c3e)
 #2 0x0000630927e4267d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007b671f8db730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #4 0x0000630926ef4cc0 clang::ASTNodeKind::getFromNode(clang::Stmt const&) (/usr/local/clang-19/bin/clang-tidy+0x2efacc0)
 #5 0x0000630926d62632 bool clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::match<clang::Expr>(clang::Expr const&) ASTMatchFinder.cpp:0:0
 #6 0x0000630926d5304d clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseLambdaExpr(clang::LambdaExpr*) ASTMatchFinder.cpp:0:0
 #7 0x0000630926d4d8e4 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
 #8 0x0000630926d61edb clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseCXXForRangeStmt(clang::CXXForRangeStmt*) ASTMatchFinder.cpp:0:0
 #9 0x0000630926d4e256 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#10 0x0000630926d4cdb8 clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#11 0x0000630926d6180b clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseCompoundStmt(clang::CompoundStmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#12 0x0000630926d4e436 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchChildASTVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#13 0x0000630926d44c76 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchesRecursively(clang::DynTypedNode const&, clang::ast_matchers::internal::DynTypedMatcher const&, clang::ast_matchers::internal::BoundNodesTreeBuilder*, int, clang::ast_matchers::internal::ASTMatchFinder::BindKind) ASTMatchFinder.cpp:0:0
#14 0x0000630926d44878 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::memoizedMatchesRecursively(clang::DynTypedNode const&, clang::ASTContext&, clang::ast_matchers::internal::DynTypedMatcher const&, clang::ast_matchers::internal::BoundNodesTreeBuilder*, int, clang::ast_matchers::internal::ASTMatchFinder::BindKind) ASTMatchFinder.cpp:0:0
#15 0x0000630926d42d28 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchesDescendantOf(clang::DynTypedNode const&, clang::ASTContext&, clang::ast_matchers::internal::DynTypedMatcher const&, clang::ast_matchers::internal::BoundNodesTreeBuilder*, clang::ast_matchers::internal::ASTMatchFinder::BindKind) ASTMatchFinder.cpp:0:0
#16 0x0000630924cc533a clang::ast_matchers::internal::HasDescendantMatcher<clang::Stmt, clang::Stmt>::matches(clang::Stmt const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0xccb33a)
#17 0x0000630926d9c2aa clang::ast_matchers::internal::DynTypedMatcher::matchesNoKindCheck(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0x2da22aa)
#18 0x0000630926d9ec2f clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const ASTMatchersInternal.cpp:0:0
#19 0x0000630926d9c189 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0x2da2189)
#20 0x0000630924dbd1f6 clang::ast_matchers::internal::matcher_hasBody0Matcher<clang::FunctionDecl, clang::ast_matchers::internal::Matcher<clang::Stmt>>::matches(clang::FunctionDecl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0xdc31f6)
#21 0x0000630926d9c2aa clang::ast_matchers::internal::DynTypedMatcher::matchesNoKindCheck(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0x2da22aa)
#22 0x0000630926d9ec09 clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const ASTMatchersInternal.cpp:0:0
#23 0x0000630926d9c189 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0x2da2189)
#24 0x0000630924eb046c clang::ast_matchers::internal::TraversalMatcher<clang::Decl>::matches(clang::Decl const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0xeb646c)
#25 0x0000630926d9c189 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const (/usr/local/clang-19/bin/clang-tidy+0x2da2189)
#26 0x0000630926d6c5ba clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
#27 0x0000630926d6f009 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#28 0x0000630926d6f9cb clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0
#29 0x0000630926d6f030 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#30 0x0000630926d425c0 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/usr/local/clang-19/bin/clang-tidy+0x2d485c0)
#31 0x0000630925e0429c clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/clang-19/bin/clang-tidy+0x1e0a29c)
#32 0x000063092606c3f9 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/clang-19/bin/clang-tidy+0x20723f9)
#33 0x0000630925dc87c6 clang::FrontendAction::Execute() (/usr/local/clang-19/bin/clang-tidy+0x1dce7c6)
#34 0x0000630925d39f24 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/clang-19/bin/clang-tidy+0x1d3ff24)
#35 0x0000630925781313 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/usr/local/clang-19/bin/clang-tidy+0x1787313)
#36 0x000063092574a354 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0
#37 0x0000630925781068 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/usr/local/clang-19/bin/clang-tidy+0x1787068)
#38 0x000063092577fe29 clang::tooling::ToolInvocation::run() (/usr/local/clang-19/bin/clang-tidy+0x1785e29)
#39 0x0000630925783482 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/usr/local/clang-19/bin/clang-tidy+0x1789482)
#40 0x0000630925744b07 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) (/usr/local/clang-19/bin/clang-tidy+0x174ab07)
#41 0x0000630924c7270c clang::tidy::clangTidyMain(int, char const**) (/usr/local/clang-19/bin/clang-tidy+0xc7870c)
#42 0x00007b671f3fb09b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
#43 0x0000630924c6ddea _start (/usr/local/clang-19/bin/clang-tidy+0xc73dea)
Segmentation fault

@sonofR9
Copy link
Author

sonofR9 commented Aug 1, 2024

Also, changing this part (it is close to the end of the code snippet):

                    taskQueue_.emplace([plugin, msg]() {
                        plugin->setMessageProcessingStatus(
                                msg->dgateId(), DGateKernelAPI::ProcessingError);
                        delete msg;
                        int len{0};
                        plugin->log(DGateBaseAPI::LogDebug,
                                    "error while sending message %s: can't connect to remote "
                                    "socket",
                                    msg->nativeId(len));
                    });

To this:

                      plugin->setMessageProcessingStatus(
                            msg->dgateId(), DGateKernelAPI::ProcessingError);
                    int len{0};
                    plugin->log(DGateBaseAPI::LogDebug,
                                "error while sending message %s: can't connect to remote "
                                "socket",
                                msg->nativeId(len));

P.S. 1. Here msg is std::unique_ptr<my_class> and plugin is different_class*. But there are gsl::owner somewhere in the code above.
P.S. 2. Removing just delete msg; line does not fix segfault.

                    taskQueue_.emplace([plugin, msg]() {
                        plugin->setMessageProcessingStatus(
                                msg->dgateId(), DGateKernelAPI::ProcessingError);
                        int len{0};
                        plugin->log(DGateBaseAPI::LogDebug,
                                    "error while sending message %s: can't connect to remote "
                                    "socket",
                                    msg->nativeId(len));
                    });

@sonofR9
Copy link
Author

sonofR9 commented Aug 1, 2024

Sorry, I can't send you a full code to reproduce the error / make some simplified version of it right now.

@PiotrZSL
Copy link
Member

PiotrZSL commented Aug 1, 2024

Looks to be duplicate of #70460

@sonofR9 sonofR9 closed this as completed Aug 26, 2024
@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Aug 26, 2024
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid] duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants