Skip to content

clang-tidy crashes on Overload pattern constructed with () #139789

Open
@HaroldVemeno

Description

@HaroldVemeno

The following short c++ program

#include <variant>
#include <iostream>

template<typename ... Fns>
struct Overload : Fns... {
    using Fns::operator()...;
};
template<typename ... Fns> Overload(Fns...) -> Overload<Fns...>;

int main() {
    std::variant<int, char> var = 'x';

    auto fun = Overload(
            [](int a)  { std::cout << "int "  << a << '\n'; },
            [](char c) { std::cout << "char " << c << '\n'; });

    std::visit(fun, var);
}

makes clang-tidy crash with the following backtrace:

Stack dump:
0.	Program arguments: clang-tidy clang-tidy-bug.cpp -- -std=c++20
1.	<eof> parser at end of file
2.	While analyzing stack: 
	#0 Calling main()
3.	/home/stepan/clang-tidy-bug.cpp:14:13: Error evaluating statement
4.	/home/stepan/clang-tidy-bug.cpp:14:13: Error evaluating statement
 #0 0x00007ed68a019920 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/libLLVM.so.19.1+0x819920)
 #1 0x00007ed68a0168bd (/usr/lib/libLLVM.so.19.1+0x8168bd)
 #2 0x00007ed68924def0 (/usr/lib/libc.so.6+0x3def0)
 #3 0x00007ed6928afce6 (/usr/lib/libclang-cpp.so.19.1+0x8afce6)
 #4 0x00007ed6928d8268 clang::CXXMethodDecl::getThisType(clang::FunctionProtoType const*, clang::CXXRecordDecl const*) (/usr/lib/libclang-cpp.so.19.1+0x8d8268)
 #5 0x00007ed694640fbd clang::ento::SValBuilder::getCXXThis(clang::CXXMethodDecl const*, clang::StackFrameContext const*) (/usr/lib/libclang-cpp.so.19.1+0x2640fbd)
 #6 0x00007ed694592105 clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/usr/lib/libclang-cpp.so.19.1+0x2592105)
 #7 0x00007ed69459affa clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/usr/lib/libclang-cpp.so.19.1+0x259affa)
 #8 0x00007ed69459d3d0 clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/usr/lib/libclang-cpp.so.19.1+0x259d3d0)
 #9 0x00007ed69459e065 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/usr/lib/libclang-cpp.so.19.1+0x259e065)
#10 0x00007ed6945326b8 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/usr/lib/libclang-cpp.so.19.1+0x25326b8)
#11 0x00007ed694532c56 clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/usr/lib/libclang-cpp.so.19.1+0x2532c56)
#12 0x00007ed69495fd13 (/usr/lib/libclang-cpp.so.19.1+0x295fd13)
#13 0x00007ed694963a47 (/usr/lib/libclang-cpp.so.19.1+0x2963a47)
#14 0x00007ed6942e1980 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib/libclang-cpp.so.19.1+0x22e1980)
#15 0x00007ed6925d9b86 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.19.1+0x5d9b86)
#16 0x00007ed6943021a1 clang::FrontendAction::Execute() (/usr/lib/libclang-cpp.so.19.1+0x23021a1)
#17 0x00007ed69429808f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.19.1+0x229808f)
#18 0x00007ed69446adfe clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/usr/lib/libclang-cpp.so.19.1+0x246adfe)
#19 0x000061188e79539d (/usr/bin/clang-tidy+0x5a939d)
#20 0x00007ed694467f51 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/usr/lib/libclang-cpp.so.19.1+0x2467f51)
#21 0x00007ed694469f43 clang::tooling::ToolInvocation::run() (/usr/lib/libclang-cpp.so.19.1+0x2469f43)
#22 0x00007ed69446b845 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/usr/lib/libclang-cpp.so.19.1+0x246b845)
#23 0x000061188e7a0978 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/bin/clang-tidy+0x5b4978)
#24 0x000061188e2cbc77 clang::tidy::clangTidyMain(int, char const**) (/usr/bin/clang-tidy+0xdfc77)
#25 0x00007ed6892376b5 (/usr/lib/libc.so.6+0x276b5)
#26 0x00007ed689237769 __libc_start_main (/usr/lib/libc.so.6+0x27769)
#27 0x000061188e2c21a5 _start (/usr/bin/clang-tidy+0xd61a5)

The version is 19.1.7. I have also tried LLVM version 16.0.6, and it seems to crash at the same place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions