MPIBugReporter.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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-exception
  6. //
  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. #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H
  15. #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_MPICHECKER_MPIBUGREPORTER_H
  16. #include "MPITypes.h"
  17. #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
  18. namespace clang {
  19. namespace ento {
  20. namespace mpi {
  21. class MPIBugReporter {
  22. public:
  23. MPIBugReporter(const CheckerBase &CB) {
  24. UnmatchedWaitBugType.reset(new BugType(&CB, "Unmatched wait", MPIError));
  25. DoubleNonblockingBugType.reset(
  26. new BugType(&CB, "Double nonblocking", MPIError));
  27. MissingWaitBugType.reset(new BugType(&CB, "Missing wait", MPIError));
  28. }
  29. /// Report duplicate request use by nonblocking calls without intermediate
  30. /// wait.
  31. ///
  32. /// \param MPICallEvent MPI call that caused the double nonblocking
  33. /// \param Req request that was used by two nonblocking calls in sequence
  34. /// \param RequestRegion memory region of the request
  35. /// \param ExplNode node in the graph the bug appeared at
  36. /// \param BReporter bug reporter for current context
  37. void reportDoubleNonblocking(const CallEvent &MPICallEvent,
  38. const Request &Req,
  39. const MemRegion *const RequestRegion,
  40. const ExplodedNode *const ExplNode,
  41. BugReporter &BReporter) const;
  42. /// Report a missing wait for a nonblocking call.
  43. ///
  44. /// \param Req request that is not matched by a wait
  45. /// \param RequestRegion memory region of the request
  46. /// \param ExplNode node in the graph the bug appeared at
  47. /// \param BReporter bug reporter for current context
  48. void reportMissingWait(const Request &Req,
  49. const MemRegion *const RequestRegion,
  50. const ExplodedNode *const ExplNode,
  51. BugReporter &BReporter) const;
  52. /// Report a wait on a request that has not been used at all before.
  53. ///
  54. /// \param CE wait call that uses the request
  55. /// \param RequestRegion memory region of the request
  56. /// \param ExplNode node in the graph the bug appeared at
  57. /// \param BReporter bug reporter for current context
  58. void reportUnmatchedWait(const CallEvent &CE,
  59. const MemRegion *const RequestRegion,
  60. const ExplodedNode *const ExplNode,
  61. BugReporter &BReporter) const;
  62. private:
  63. const std::string MPIError = "MPI Error";
  64. // path-sensitive bug types
  65. std::unique_ptr<BugType> UnmatchedWaitBugType;
  66. std::unique_ptr<BugType> MissingWaitBugType;
  67. std::unique_ptr<BugType> DoubleNonblockingBugType;
  68. /// Bug visitor class to find the node where the request region was previously
  69. /// used in order to include it into the BugReport path.
  70. class RequestNodeVisitor : public BugReporterVisitor {
  71. public:
  72. RequestNodeVisitor(const MemRegion *const MemoryRegion,
  73. const std::string &ErrText)
  74. : RequestRegion(MemoryRegion), ErrorText(ErrText) {}
  75. void Profile(llvm::FoldingSetNodeID &ID) const override {
  76. static int X = 0;
  77. ID.AddPointer(&X);
  78. ID.AddPointer(RequestRegion);
  79. }
  80. PathDiagnosticPieceRef VisitNode(const ExplodedNode *N,
  81. BugReporterContext &BRC,
  82. PathSensitiveBugReport &BR) override;
  83. private:
  84. const MemRegion *const RequestRegion;
  85. bool IsNodeFound = false;
  86. std::string ErrorText;
  87. };
  88. };
  89. } // end of namespace: mpi
  90. } // end of namespace: ento
  91. } // end of namespace: clang
  92. #endif