19 #include "../ClangSACheckers.h"
37 if (!isa<TypedRegion>(MR) || (ER && !isa<TypedRegion>(ER->
getSuperRegion())))
44 if (Req && Req->
CurrentState == Request::State::Nonblocking) {
52 State = State->set<
RequestMap>(MR, Request::State::Nonblocking);
61 const MemRegion *
const MR = topRegionUsedByWait(PreCallEvent);
67 if (!isa<TypedRegion>(MR) || (ER && !isa<TypedRegion>(ER->
getSuperRegion())))
71 allRegionsUsedByWait(ReqRegions, MR, PreCallEvent, Ctx);
72 if (ReqRegions.empty())
80 for (
const auto &ReqRegion : ReqRegions) {
82 State = State->set<
RequestMap>(ReqRegion, Request::State::Wait);
86 State = ErrorNode->getState();
107 const auto &Requests = State->get<
RequestMap>();
108 if (Requests.isEmpty())
115 for (
const auto &Req : ReqMap) {
117 if (Req.second.CurrentState == Request::State::Nonblocking) {
121 State = ErrorNode->getState();
145 return (
const MemRegion *)
nullptr;
149 void MPIChecker::allRegionsUsedByWait(
151 const MemRegion *
const MR,
const CallEvent &CE, CheckerContext &Ctx)
const {
155 if (FuncClassifier->isMPI_Waitall(CE.getCalleeIdentifier())) {
156 const SubRegion *SuperRegion{
nullptr};
157 if (
const ElementRegion *
const ER = MR->getAs<ElementRegion>()) {
158 SuperRegion = cast<SubRegion>(ER->getSuperRegion());
163 ReqRegions.push_back(MR);
167 const auto &Size = Ctx.getStoreManager().getSizeInElements(
168 Ctx.getState(), SuperRegion,
169 CE.getArgExpr(1)->getType()->getPointeeType());
170 const llvm::APSInt &ArrSize = Size.getAs<nonloc::ConcreteInt>()->
getValue();
172 for (
size_t i = 0; i < ArrSize; ++i) {
173 const NonLoc Idx = Ctx.getSValBuilder().makeArrayIndex(i);
175 const ElementRegion *
const ER = RegionManager->getElementRegion(
176 CE.getArgExpr(1)->getType()->getPointeeType(), Idx, SuperRegion,
177 Ctx.getASTContext());
179 ReqRegions.push_back(ER->getAs<MemRegion>());
181 }
else if (FuncClassifier->isMPI_Wait(CE.getCalleeIdentifier())) {
182 ReqRegions.push_back(MR);
191 void clang::ento::registerMPIChecker(CheckerManager &MGR) {
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
MemRegion - The root abstract class for all memory regions.
bool hasDeadSymbols() const
ExplodedNode * addTransition(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generates a new transition in the program state graph (ExplodedGraph).
void checkMissingWaits(clang::ento::SymbolReaper &SymReaper, clang::ento::CheckerContext &Ctx) const
Check if a nonblocking call is not matched by a wait.
BugReporter & getBugReporter()
bool isLiveRegion(const MemRegion *region)
void reportDoubleNonblocking(const CallEvent &MPICallEvent, const Request &Req, const MemRegion *const RequestRegion, const ExplodedNode *const ExplNode, BugReporter &BReporter) const
Report duplicate request use by nonblocking calls without intermediate wait.
const MemRegion * getSuperRegion() const
void reportUnmatchedWait(const CallEvent &CE, const MemRegion *const RequestRegion, const ExplodedNode *const ExplNode, BugReporter &BReporter) const
Report a wait on a request that has not been used at all before.
const ProgramStateRef & getState() const
const ProgramStateRef & getState() const
This file defines the main class of MPI-Checker which serves as an entry point.
static SVal getValue(SVal val, SValBuilder &svalBuilder)
ExplodedNode * generateNonFatalErrorNode(ProgramStateRef State=nullptr, const ProgramPointTag *Tag=nullptr)
Generate a transition to a node that will be used to report an error.
void reportMissingWait(const Request &Req, const MemRegion *const RequestRegion, const ExplodedNode *const ExplNode, BugReporter &BReporter) const
Report a missing wait for a nonblocking call.
A class responsible for cleaning up unused symbols.
void checkDoubleNonblocking(const clang::ento::CallEvent &PreCallEvent, clang::ento::CheckerContext &Ctx) const
Checks if a request is used by nonblocking calls multiple times in sequence without intermediate wait...
const IdentifierInfo * getCalleeIdentifier() const
Returns the name of the callee, if its name is a simple identifier.
const MemRegion * getAsRegion() const
Represents an abstract call to a function or method along a particular path.
virtual MemRegionManager * getMemRegionManager() const =0
void checkUnmatchedWaits(const clang::ento::CallEvent &PreCallEvent, clang::ento::CheckerContext &Ctx) const
Checks if the request used by the wait function was not used at all before.
virtual unsigned getNumArgs() const =0
Returns the number of arguments (explicit and implicit).
ElementRegin is used to represent both array elements and casts.
Tag that can use a checker name as a message provider (see SimpleProgramPointTag).