clang-tools  14.0.0git
BufferDerefCheck.h
Go to the documentation of this file.
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 
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 #include "clang/StaticAnalyzer/Checkers/MPIFunctionClassifier.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
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  void onEndOfTranslationUnit() override;
35 
36 private:
37  /// Checks for all buffers in an MPI call if they are sufficiently
38  /// dereferenced.
39  ///
40  /// \param BufferTypes buffer types
41  /// \param BufferExprs buffer arguments as expressions
42  void checkBuffers(ArrayRef<const Type *> BufferTypes,
43  ArrayRef<const Expr *> BufferExprs);
44 
45  enum class IndirectionType : unsigned char { Pointer, Array };
46 
47  Optional<ento::mpi::MPIFunctionClassifier> FuncClassifier;
48 };
49 
50 } // namespace mpi
51 } // namespace tidy
52 } // namespace clang
53 
54 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MPI_BUFFER_DEREF_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::mpi::BufferDerefCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition: BufferDerefCheck.cpp:130
clang::tidy::mpi::BufferDerefCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: BufferDerefCheck.cpp:24
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::mpi::BufferDerefCheck
This check verifies if a buffer passed to an MPI (Message Passing Interface) function is sufficiently...
Definition: BufferDerefCheck.h:28
clang::tidy::mpi::BufferDerefCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: BufferDerefCheck.cpp:20
clang::tidy::mpi::BufferDerefCheck::BufferDerefCheck
BufferDerefCheck(StringRef Name, ClangTidyContext *Context)
Definition: BufferDerefCheck.h:30
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27