llvm / llvm-project

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

clang-tidy: Error evaluating statement (LLVM 18.1.8 from Fedora 40) #112220

Open jeanthom opened 3 weeks ago

jeanthom commented 3 weeks ago

Hi, I'm running into an issue with clang-tidy on Fedora 40 where it crashes while parsing my C++23 project. Here's the crash stack:

stack dump:
0.  Program arguments: clang-tidy -p "redacted_prj_folder/build" "redacted_prj_folder/src/gui/MainWindow.cpp"
1.  <eof> parser at end of file
2.  While analyzing stack: 
    #0 Calling qtToNativeValue(RedactedEnumClass, const QVariant &) at line 247
    #1 Calling MainWindow::redacted_method_name(const QImage &)
3.  ../src/gui/MainWindow.cpp:33:31: Error evaluating statement
4.  ../src/gui/MainWindow.cpp:33:31: Error evaluating statement
 #0 0x00007f0cd1a044fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM.so.18.1+0x6044fa)
 #1 0x00007f0cd1a01ce4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM.so.18.1+0x601ce4)
 #2 0x00007f0cd1a04c5b (/lib64/libLLVM.so.18.1+0x604c5b)
 #3 0x00007f0cd0e4fd00 __restore_rt (/lib64/libc.so.6+0x40d00)
 #4 0x00007f0cd8e4656e clang::CXXMethodDecl::getThisType(clang::FunctionProtoType const*, clang::CXXRecordDecl const*) (/lib64/libclang-cpp.so.18.1+0x84656e)
 #5 0x00007f0cdb14b07d clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/lib64/libclang-cpp.so.18.1+0x2b4b07d)
 #6 0x00007f0cdb12ad0a clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/lib64/libclang-cpp.so.18.1+0x2b2ad0a)
 #7 0x00007f0cdb1280bb clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/lib64/libclang-cpp.so.18.1+0x2b280bb)
 #8 0x00007f0cdb127da0 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/lib64/libclang-cpp.so.18.1+0x2b27da0)
 #9 0x00007f0cdb10cc19 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/lib64/libclang-cpp.so.18.1+0x2b0cc19)
#10 0x00007f0cdb10c6dd clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/lib64/libclang-cpp.so.18.1+0x2b0c6dd)
#11 0x00007f0cdb5af2c9 (/lib64/libclang-cpp.so.18.1+0x2faf2c9)
#12 0x00007f0cdb58a9dd (/lib64/libclang-cpp.so.18.1+0x2f8a9dd)
#13 0x00007f0cdae538ec clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/lib64/libclang-cpp.so.18.1+0x28538ec)
#14 0x00007f0cd8b743e6 clang::ParseAST(clang::Sema&, bool, bool) (/lib64/libclang-cpp.so.18.1+0x5743e6)
#15 0x00007f0cdae1c816 clang::FrontendAction::Execute() (/lib64/libclang-cpp.so.18.1+0x281c816)
#16 0x00007f0cdad94520 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib64/libclang-cpp.so.18.1+0x2794520)
#17 0x00007f0cdb031721 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/lib64/libclang-cpp.so.18.1+0x2a31721)
#18 0x000055b4f1ce302e (/usr/bin/clang-tidy+0x102902e)
#19 0x00007f0cdb0313e4 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/lib64/libclang-cpp.so.18.1+0x2a313e4)
#20 0x00007f0cdb030164 clang::tooling::ToolInvocation::run() (/lib64/libclang-cpp.so.18.1+0x2a30164)
#21 0x00007f0cdb033315 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/lib64/libclang-cpp.so.18.1+0x2a33315)
#22 0x000055b4f1cde3da 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+0x10243da)
#23 0x000055b4f0ecf06c clang::tidy::clangTidyMain(int, char const**) (/usr/bin/clang-tidy+0x21506c)
#24 0x00007f0cd0e39088 __libc_start_call_main (/lib64/libc.so.6+0x2a088)
#25 0x00007f0cd0e3914b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14b)
#26 0x000055b4f0ecb245 _start (/usr/bin/clang-tidy+0x211245)

This seems to be the offending piece of code (MainWindow.cpp:33):

std::variant<redacted> qtToNativeValue(RedactedEnumClass attribute, const QVariant& value)
{
    ...

        QByteArray ba;
        QBuffer buffer(&ba);
        buffer.open(QIODevice::WriteOnly);
        image.save(&buffer, "PNG");
        BinaryPayload payload(std::vector<unsigned char>(ba.begin(), ba.end())); // Line 33

    ...
}

Non-redacted BinaryPayload definition:

class BinaryPayload : public std::vector<unsigned char> {
};

A few version infos that may be useful:

$ clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 18.1.8
  Optimized build.
$ cat /etc/fedora-release
Fedora release 40 (Forty)
llvmbot commented 3 weeks ago

@llvm/issue-subscribers-clang-static-analyzer

Author: Jean THOMAS (jeanthom)

Hi, I'm running into an issue with clang-tidy on Fedora 40 where it crashes while parsing my C++23 project. Here's the crash stack: ``` stack dump: 0. Program arguments: clang-tidy -p "redacted_prj_folder/build" "redacted_prj_folder/src/gui/MainWindow.cpp" 1. <eof> parser at end of file 2. While analyzing stack: #0 Calling qtToNativeValue(RedactedEnumClass, const QVariant &) at line 247 #1 Calling MainWindow::redacted_method_name(const QImage &) 3. ../src/gui/MainWindow.cpp:33:31: Error evaluating statement 4. ../src/gui/MainWindow.cpp:33:31: Error evaluating statement #0 0x00007f0cd1a044fa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib64/libLLVM.so.18.1+0x6044fa) #1 0x00007f0cd1a01ce4 llvm::sys::RunSignalHandlers() (/lib64/libLLVM.so.18.1+0x601ce4) #2 0x00007f0cd1a04c5b (/lib64/libLLVM.so.18.1+0x604c5b) #3 0x00007f0cd0e4fd00 __restore_rt (/lib64/libc.so.6+0x40d00) #4 0x00007f0cd8e4656e clang::CXXMethodDecl::getThisType(clang::FunctionProtoType const*, clang::CXXRecordDecl const*) (/lib64/libclang-cpp.so.18.1+0x84656e) #5 0x00007f0cdb14b07d clang::ento::ExprEngine::handleConstructor(clang::Expr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/lib64/libclang-cpp.so.18.1+0x2b4b07d) #6 0x00007f0cdb12ad0a clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/lib64/libclang-cpp.so.18.1+0x2b2ad0a) #7 0x00007f0cdb1280bb clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/lib64/libclang-cpp.so.18.1+0x2b280bb) #8 0x00007f0cdb127da0 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/lib64/libclang-cpp.so.18.1+0x2b27da0) #9 0x00007f0cdb10cc19 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/lib64/libclang-cpp.so.18.1+0x2b0cc19) #10 0x00007f0cdb10c6dd clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) (/lib64/libclang-cpp.so.18.1+0x2b0c6dd) #11 0x00007f0cdb5af2c9 (/lib64/libclang-cpp.so.18.1+0x2faf2c9) #12 0x00007f0cdb58a9dd (/lib64/libclang-cpp.so.18.1+0x2f8a9dd) #13 0x00007f0cdae538ec clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/lib64/libclang-cpp.so.18.1+0x28538ec) #14 0x00007f0cd8b743e6 clang::ParseAST(clang::Sema&, bool, bool) (/lib64/libclang-cpp.so.18.1+0x5743e6) #15 0x00007f0cdae1c816 clang::FrontendAction::Execute() (/lib64/libclang-cpp.so.18.1+0x281c816) #16 0x00007f0cdad94520 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/lib64/libclang-cpp.so.18.1+0x2794520) #17 0x00007f0cdb031721 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/lib64/libclang-cpp.so.18.1+0x2a31721) #18 0x000055b4f1ce302e (/usr/bin/clang-tidy+0x102902e) #19 0x00007f0cdb0313e4 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/lib64/libclang-cpp.so.18.1+0x2a313e4) #20 0x00007f0cdb030164 clang::tooling::ToolInvocation::run() (/lib64/libclang-cpp.so.18.1+0x2a30164) #21 0x00007f0cdb033315 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/lib64/libclang-cpp.so.18.1+0x2a33315) #22 0x000055b4f1cde3da 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+0x10243da) #23 0x000055b4f0ecf06c clang::tidy::clangTidyMain(int, char const**) (/usr/bin/clang-tidy+0x21506c) #24 0x00007f0cd0e39088 __libc_start_call_main (/lib64/libc.so.6+0x2a088) #25 0x00007f0cd0e3914b __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14b) #26 0x000055b4f0ecb245 _start (/usr/bin/clang-tidy+0x211245) ``` This seems to be the offending piece of code (MainWindow.cpp:33): ```c++ std::variant<redacted> qtToNativeValue(RedactedEnumClass attribute, const QVariant& value) { ... QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); image.save(&buffer, "PNG"); BinaryPayload payload(std::vector<unsigned char>(ba.begin(), ba.end())); // Line 33 ... } ``` Non-redacted BinaryPayload definition: ```c++ class BinaryPayload : public std::vector<unsigned char> { }; ``` A few version infos that may be useful: ``` $ clang-tidy --version LLVM (http://llvm.org/): LLVM version 18.1.8 Optimized build. $ cat /etc/fedora-release Fedora release 40 (Forty) ```
EugeneZelenko commented 3 weeks ago

Could you please try 19 or main branch? https://godbolt.org should be helpful.