blob: 8490fa1c852ae84b28629df22a70e1282f3bc056 [file] [log] [blame]
Alexander Droste1512f9a2016-08-12 19:30:31 +00001//===--- 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
15namespace clang {
16namespace tidy {
17namespace 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
28class BufferDerefCheck : public ClangTidyCheck {
29public:
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
35private:
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