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