105 lines · c
1//===-- MPIBugReporter.h - bug reporter -----------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file defines prefabricated reports which are emitted in11/// case of MPI related bugs, detected by path-sensitive analysis.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H16#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H17 18#include "MPITypes.h"19#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"20#include "llvm/ADT/StringRef.h"21 22namespace clang {23namespace ento {24namespace mpi {25 26class MPIBugReporter {27public:28 MPIBugReporter(const CheckerBase &CB)29 : UnmatchedWaitBugType(&CB, "Unmatched wait", MPIError),30 MissingWaitBugType(&CB, "Missing wait", MPIError),31 DoubleNonblockingBugType(&CB, "Double nonblocking", MPIError) {}32 33 /// Report duplicate request use by nonblocking calls without intermediate34 /// wait.35 ///36 /// \param MPICallEvent MPI call that caused the double nonblocking37 /// \param Req request that was used by two nonblocking calls in sequence38 /// \param RequestRegion memory region of the request39 /// \param ExplNode node in the graph the bug appeared at40 /// \param BReporter bug reporter for current context41 void reportDoubleNonblocking(const CallEvent &MPICallEvent,42 const Request &Req,43 const MemRegion *const RequestRegion,44 const ExplodedNode *const ExplNode,45 BugReporter &BReporter) const;46 47 /// Report a missing wait for a nonblocking call.48 ///49 /// \param Req request that is not matched by a wait50 /// \param RequestRegion memory region of the request51 /// \param ExplNode node in the graph the bug appeared at52 /// \param BReporter bug reporter for current context53 void reportMissingWait(const Request &Req,54 const MemRegion *const RequestRegion,55 const ExplodedNode *const ExplNode,56 BugReporter &BReporter) const;57 58 /// Report a wait on a request that has not been used at all before.59 ///60 /// \param CE wait call that uses the request61 /// \param RequestRegion memory region of the request62 /// \param ExplNode node in the graph the bug appeared at63 /// \param BReporter bug reporter for current context64 void reportUnmatchedWait(const CallEvent &CE,65 const MemRegion *const RequestRegion,66 const ExplodedNode *const ExplNode,67 BugReporter &BReporter) const;68 69private:70 const llvm::StringLiteral MPIError = "MPI Error";71 const BugType UnmatchedWaitBugType;72 const BugType MissingWaitBugType;73 const BugType DoubleNonblockingBugType;74 75 /// Bug visitor class to find the node where the request region was previously76 /// used in order to include it into the BugReport path.77 class RequestNodeVisitor : public BugReporterVisitor {78 public:79 RequestNodeVisitor(const MemRegion *const MemoryRegion,80 const std::string &ErrText)81 : RequestRegion(MemoryRegion), ErrorText(ErrText) {}82 83 void Profile(llvm::FoldingSetNodeID &ID) const override {84 static int X = 0;85 ID.AddPointer(&X);86 ID.AddPointer(RequestRegion);87 }88 89 PathDiagnosticPieceRef VisitNode(const ExplodedNode *N,90 BugReporterContext &BRC,91 PathSensitiveBugReport &BR) override;92 93 private:94 const MemRegion *const RequestRegion;95 bool IsNodeFound = false;96 std::string ErrorText;97 };98};99 100} // end of namespace: mpi101} // end of namespace: ento102} // end of namespace: clang103 104#endif105