BufferDerefCheck.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===--- BufferDerefCheck.h - clang-tidy-------------------------*- 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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
  10. #include "../ClangTidyCheck.h"
  11. #include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.h"
  12. #include <optional>
  13. namespace clang::tidy::mpi {
  14. /// This check verifies if a buffer passed to an MPI (Message Passing Interface)
  15. /// function is sufficiently dereferenced. Buffers should be passed as a single
  16. /// pointer or array. As MPI function signatures specify void * for their buffer
  17. /// types, insufficiently dereferenced buffers can be passed, like for example
  18. /// as double pointers or multidimensional arrays, without a compiler warning
  19. /// emitted.
  20. ///
  21. /// For the user-facing documentation see:
  22. /// http://clang.llvm.org/extra/clang-tidy/checks/mpi/buffer-deref.html
  23. class BufferDerefCheck : public ClangTidyCheck {
  24. public:
  25. BufferDerefCheck(StringRef Name, ClangTidyContext *Context)
  26. : ClangTidyCheck(Name, Context) {}
  27. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  28. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  29. void onEndOfTranslationUnit() override;
  30. private:
  31. /// Checks for all buffers in an MPI call if they are sufficiently
  32. /// dereferenced.
  33. ///
  34. /// \param BufferTypes buffer types
  35. /// \param BufferExprs buffer arguments as expressions
  36. void checkBuffers(ArrayRef<const Type *> BufferTypes,
  37. ArrayRef<const Expr *> BufferExprs);
  38. enum class IndirectionType : unsigned char { Pointer, Array };
  39. std::optional<ento::mpi::MPIFunctionClassifier> FuncClassifier;
  40. };
  41. } // namespace clang::tidy::mpi
  42. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H