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