clang-tools  14.0.0git
UseDefaultNoneCheck.cpp
Go to the documentation of this file.
1 //===--- UseDefaultNoneCheck.cpp - clang-tidy -----------------------------===//
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 #include "UseDefaultNoneCheck.h"
10 #include "clang/AST/ASTContext.h"
11 #include "clang/AST/OpenMPClause.h"
12 #include "clang/AST/Stmt.h"
13 #include "clang/AST/StmtOpenMP.h"
14 #include "clang/ASTMatchers/ASTMatchFinder.h"
15 #include "clang/ASTMatchers/ASTMatchers.h"
16 #include "clang/ASTMatchers/ASTMatchersMacros.h"
17 
18 using namespace clang::ast_matchers;
19 
20 namespace clang {
21 namespace tidy {
22 namespace openmp {
23 
24 void UseDefaultNoneCheck::registerMatchers(MatchFinder *Finder) {
25  Finder->addMatcher(
26  ompExecutableDirective(
27  allOf(isAllowedToContainClauseKind(llvm::omp::OMPC_default),
28  anyOf(unless(hasAnyClause(ompDefaultClause())),
29  hasAnyClause(ompDefaultClause(unless(isNoneKind()))
30  .bind("clause")))))
31  .bind("directive"),
32  this);
33 }
34 
35 void UseDefaultNoneCheck::check(const MatchFinder::MatchResult &Result) {
36  const auto *Directive =
37  Result.Nodes.getNodeAs<OMPExecutableDirective>("directive");
38  assert(Directive != nullptr && "Expected to match some directive.");
39 
40  if (const auto *Clause = Result.Nodes.getNodeAs<OMPDefaultClause>("clause")) {
41  diag(Directive->getBeginLoc(),
42  "OpenMP directive '%0' specifies 'default(%1)' clause, consider using "
43  "'default(none)' clause instead")
44  << getOpenMPDirectiveName(Directive->getDirectiveKind())
45  << getOpenMPSimpleClauseTypeName(Clause->getClauseKind(),
46  unsigned(Clause->getDefaultKind()));
47  diag(Clause->getBeginLoc(), "existing 'default' clause specified here",
48  DiagnosticIDs::Note);
49  return;
50  }
51 
52  diag(Directive->getBeginLoc(),
53  "OpenMP directive '%0' does not specify 'default' clause, consider "
54  "specifying 'default(none)' clause")
55  << getOpenMPDirectiveName(Directive->getDirectiveKind());
56 }
57 
58 } // namespace openmp
59 } // namespace tidy
60 } // namespace clang
UseDefaultNoneCheck.h
clang::ast_matchers
Definition: AbseilMatcher.h:14
clang::clangd::check
bool check(llvm::StringRef File, llvm::function_ref< bool(const Position &)> ShouldCheckLine, const ThreadsafeFS &TFS, const ClangdLSPServer::Options &Opts, bool EnableCodeCompletion)
Definition: Check.cpp:258
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27