llvm / llvm-project

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

[clang static-analyzer] crash with clang-analyzer-optin.mpi.MPI-Checker on MPI_Wait #64647

Open 5chmidti opened 1 year ago

5chmidti commented 1 year ago
#include "mpi.h"
bool contains();
void do_a() {
    if (contains()) {
        MPI_Request request_item;
        MPI_Wait(&request_item, MPI_STATUS_IGNORE);
    }
    do_a();
}
backtrace ```text Stack dump: 0. Program arguments: clang-tidy -checks=-*,clang-analyzer-optin.mpi.MPI-Checker -p . NetworkMotifs.cpp 1. parser at end of file 2. While analyzing stack: #0 Calling do_a() at line 8 #1 Calling do_a() 3. /path/to/file.cpp:6:3: Error evaluating statement 4. /path/to/file.cpp:6:3: Error evaluating statement #0 0x0000564f85e12198 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/user/install/llvm-project/bin/clang-tidy+0x17b5198) #1 0x0000564f85e100d0 llvm::sys::RunSignalHandlers() (/home/user/install/llvm-project/bin/clang-tidy+0x17b30d0) #2 0x0000564f85e12b48 SignalHandler(int) Signals.cpp:0:0 #3 0x00007f59c323e710 (/usr/lib/libc.so.6+0x3e710) #4 0x0000564f86f23197 clang::ento::mpi::MPIChecker::checkUnmatchedWaits(clang::ento::CallEvent const&, clang::ento::CheckerContext&) const (/home/user/install/llvm-project/bin/clang-tidy+0x28c6197) #5 0x0000564f86f26304 void clang::ento::check::PreCall::_checkCall(void*, clang::ento::CallEvent const&, clang::ento::CheckerContext&) MPIChecker.cpp:0:0 #6 0x0000564f871126c9 clang::ento::CheckerManager::runCheckersForCallEvent(bool, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::ento::CallEvent const&, clang::ento::ExprEngine&, bool) (/home/user/install/llvm-project/bin/clang-tidy+0x2ab56c9) #7 0x0000564f87162040 clang::ento::ExprEngine::evalCall(clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNode*, clang::ento::CallEvent const&) (/home/user/install/llvm-project/bin/clang-tidy+0x2b05040) #8 0x0000564f87161e65 clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/home/user/install/llvm-project/bin/clang-tidy+0x2b04e65) #9 0x0000564f8713f11e clang::ento::ExprEngine::Visit(clang::Stmt const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/home/user/install/llvm-project/bin/clang-tidy+0x2ae211e) #10 0x0000564f8713b4aa clang::ento::ExprEngine::ProcessStmt(clang::Stmt const*, clang::ento::ExplodedNode*) (/home/user/install/llvm-project/bin/clang-tidy+0x2ade4aa) #11 0x0000564f8713b1f4 clang::ento::ExprEngine::processCFGElement(clang::CFGElement, clang::ento::ExplodedNode*, unsigned int, clang::ento::NodeBuilderContext*) (/home/user/install/llvm-project/bin/clang-tidy+0x2ade1f4) #12 0x0000564f8711c364 clang::ento::CoreEngine::dispatchWorkItem(clang::ento::ExplodedNode*, clang::ProgramPoint, clang::ento::WorkListUnit const&) (/home/user/install/llvm-project/bin/clang-tidy+0x2abf364) #13 0x0000564f8711bf58 clang::ento::CoreEngine::ExecuteWorkList(clang::LocationContext const*, unsigned int, llvm::IntrusiveRefCntPtr) (/home/user/install/llvm-project/bin/clang-tidy+0x2abef58) #14 0x0000564f86d21c06 (anonymous namespace)::AnalysisConsumer::HandleCode(clang::Decl*, unsigned int, clang::ento::ExprEngine::InliningModes, llvm::DenseSet>*) AnalysisConsumer.cpp:0:0 #15 0x0000564f86d01623 (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0 #16 0x0000564f8744895c clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/user/install/llvm-project/bin/clang-tidy+0x2deb95c) #17 0x0000564f8764b5f6 clang::ParseAST(clang::Sema&, bool, bool) (/home/user/install/llvm-project/bin/clang-tidy+0x2fee5f6) #18 0x0000564f873ccf17 clang::FrontendAction::Execute() (/home/user/install/llvm-project/bin/clang-tidy+0x2d6ff17) #19 0x0000564f8733ed64 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/user/install/llvm-project/bin/clang-tidy+0x2ce1d64) #20 0x0000564f85e93404 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr, clang::FileManager*, std::shared_ptr, clang::DiagnosticConsumer*) (/home/user/install/llvm-project/bin/clang-tidy+0x1836404) #21 0x0000564f85ef7d3e clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef, std::allocator>>, llvm::IntrusiveRefCntPtr, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr, clang::FileManager*, std::shared_ptr, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0 #22 0x0000564f85e93196 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr, std::shared_ptr) (/home/user/install/llvm-project/bin/clang-tidy+0x1836196) #23 0x0000564f85e91c5b clang::tooling::ToolInvocation::run() (/home/user/install/llvm-project/bin/clang-tidy+0x1834c5b) #24 0x0000564f85e94aef clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/user/install/llvm-project/bin/clang-tidy+0x1837aef) #25 0x0000564f85ef2f77 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef, std::allocator>>, llvm::IntrusiveRefCntPtr, bool, bool, llvm::StringRef) (/home/user/install/llvm-project/bin/clang-tidy+0x1895f77) #26 0x0000564f85ddda6d clang::tidy::clangTidyMain(int, char const**) (/home/user/install/llvm-project/bin/clang-tidy+0x1780a6d) #27 0x00007f59c3227cd0 (/usr/lib/libc.so.6+0x27cd0) #28 0x00007f59c3227d8a __libc_start_main (/usr/lib/libc.so.6+0x27d8a) #29 0x0000564f85dd8a55 _start (/home/user/install/llvm-project/bin/clang-tidy+0x177ba55) fish: Job 1, 'clang-tidy -checks='-*,clang-an…' terminated by signal SIGSEGV (Address boundary error) ```

Invocation: clang-tidy -checks='-*,clang-analyzer-optin.mpi.MPI-Checker' -p . <file> LLVM version: bd686ca4f7a0 Godbolt: https://godbolt.org/z/39P7W6KPa Note that compiler-explorer does not have mpi.h, so I provided the necessary symbols myself.

llvmbot commented 1 year ago

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

danix800 commented 1 year ago

Fix proposed: https://reviews.llvm.org/D158813 Moved into https://reviews.llvm.org/D158858

steakhal commented 1 year ago

This (aka. D158858) seems to be approved but still not merged. What are your plans @danix800? I think it could land without merging D158813 first - which is mentioned as a parent patch. I'd suggest rebasing the approved revision and merging it to close this issue.