blob: 40eb0631d7c517fbe5f1948914dc26a947022038 [file] [log] [blame]
Devin Coughlin160f19c2016-06-13 03:22:41 +00001//===-- MPIBugReporter.h - bug reporter -----------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// This file defines prefabricated reports which are emitted in
12/// case of MPI related bugs, detected by path-sensitive analysis.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H
17#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H
18
19#include "MPITypes.h"
20#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
21
22namespace clang {
23namespace ento {
24namespace mpi {
25
26class MPIBugReporter {
27public:
28 MPIBugReporter(const CheckerBase &CB) {
29 UnmatchedWaitBugType.reset(new BugType(&CB, "Unmatched wait", MPIError));
30 DoubleNonblockingBugType.reset(
31 new BugType(&CB, "Double nonblocking", MPIError));
32 MissingWaitBugType.reset(new BugType(&CB, "Missing wait", MPIError));
33 }
34
35 /// Report duplicate request use by nonblocking calls without intermediate
36 /// wait.
37 ///
38 /// \param MPICallEvent MPI call that caused the double nonblocking
39 /// \param Req request that was used by two nonblocking calls in sequence
40 /// \param RequestRegion memory region of the request
41 /// \param ExplNode node in the graph the bug appeared at
42 /// \param BReporter bug reporter for current context
43 void reportDoubleNonblocking(const CallEvent &MPICallEvent,
44 const Request &Req,
45 const MemRegion *const RequestRegion,
46 const ExplodedNode *const ExplNode,
47 BugReporter &BReporter) const;
48
Devin Coughlin1bb47ac2016-08-02 23:24:40 +000049 /// Report a missing wait for a nonblocking call.
Devin Coughlin160f19c2016-06-13 03:22:41 +000050 ///
51 /// \param Req request that is not matched by a wait
52 /// \param RequestRegion memory region of the request
53 /// \param ExplNode node in the graph the bug appeared at
54 /// \param BReporter bug reporter for current context
55 void reportMissingWait(const Request &Req,
56 const MemRegion *const RequestRegion,
57 const ExplodedNode *const ExplNode,
58 BugReporter &BReporter) const;
59
60 /// Report a wait on a request that has not been used at all before.
61 ///
62 /// \param CE wait call that uses the request
NAKAMURA Takumidbc9e5f2016-06-13 05:46:35 +000063 /// \param RequestRegion memory region of the request
Devin Coughlin160f19c2016-06-13 03:22:41 +000064 /// \param ExplNode node in the graph the bug appeared at
65 /// \param BReporter bug reporter for current context
66 void reportUnmatchedWait(const CallEvent &CE,
67 const MemRegion *const RequestRegion,
68 const ExplodedNode *const ExplNode,
69 BugReporter &BReporter) const;
70
71private:
Devin Coughlin9cffa402016-06-13 03:58:58 +000072 const std::string MPIError = "MPI Error";
Devin Coughlin160f19c2016-06-13 03:22:41 +000073
74 // path-sensitive bug types
75 std::unique_ptr<BugType> UnmatchedWaitBugType;
76 std::unique_ptr<BugType> MissingWaitBugType;
77 std::unique_ptr<BugType> DoubleNonblockingBugType;
78
79 /// Bug visitor class to find the node where the request region was previously
80 /// used in order to include it into the BugReport path.
George Karpenkov70ec1dd2018-06-26 21:12:08 +000081 class RequestNodeVisitor : public BugReporterVisitor {
Devin Coughlin160f19c2016-06-13 03:22:41 +000082 public:
83 RequestNodeVisitor(const MemRegion *const MemoryRegion,
84 const std::string &ErrText)
Devin Coughlin9cffa402016-06-13 03:58:58 +000085 : RequestRegion(MemoryRegion), ErrorText(ErrText) {}
Devin Coughlin160f19c2016-06-13 03:22:41 +000086
87 void Profile(llvm::FoldingSetNodeID &ID) const override {
88 static int X = 0;
89 ID.AddPointer(&X);
90 ID.AddPointer(RequestRegion);
91 }
92
David Blaikie0a0c2752017-01-05 17:26:53 +000093 std::shared_ptr<PathDiagnosticPiece> VisitNode(const ExplodedNode *N,
94 const ExplodedNode *PrevN,
95 BugReporterContext &BRC,
96 BugReport &BR) override;
Devin Coughlin160f19c2016-06-13 03:22:41 +000097
98 private:
99 const MemRegion *const RequestRegion;
Devin Coughlin9cffa402016-06-13 03:58:58 +0000100 bool IsNodeFound = false;
Devin Coughlin160f19c2016-06-13 03:22:41 +0000101 std::string ErrorText;
102 };
103};
104
105} // end of namespace: mpi
106} // end of namespace: ento
107} // end of namespace: clang
108
109#endif