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