1 //===--- UseDefaultNoneCheck.cpp - clang-tidy -----------------------------===//
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
7 //===----------------------------------------------------------------------===//
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"
18 using namespace clang::ast_matchers
;
20 namespace clang::tidy::openmp
{
22 void UseDefaultNoneCheck::registerMatchers(MatchFinder
*Finder
) {
24 ompExecutableDirective(
25 isAllowedToContainClauseKind(llvm::omp::OMPC_default
),
26 anyOf(unless(hasAnyClause(ompDefaultClause())),
28 ompDefaultClause(unless(isNoneKind())).bind("clause"))))
33 void UseDefaultNoneCheck::check(const MatchFinder::MatchResult
&Result
) {
34 const auto *Directive
=
35 Result
.Nodes
.getNodeAs
<OMPExecutableDirective
>("directive");
36 assert(Directive
!= nullptr && "Expected to match some directive.");
38 if (const auto *Clause
= Result
.Nodes
.getNodeAs
<OMPDefaultClause
>("clause")) {
39 diag(Directive
->getBeginLoc(),
40 "OpenMP directive '%0' specifies 'default(%1)' clause, consider using "
41 "'default(none)' clause instead")
42 << getOpenMPDirectiveName(Directive
->getDirectiveKind())
43 << getOpenMPSimpleClauseTypeName(Clause
->getClauseKind(),
44 unsigned(Clause
->getDefaultKind()));
45 diag(Clause
->getBeginLoc(), "existing 'default' clause specified here",
50 diag(Directive
->getBeginLoc(),
51 "OpenMP directive '%0' does not specify 'default' clause, consider "
52 "specifying 'default(none)' clause")
53 << getOpenMPDirectiveName(Directive
->getDirectiveKind());
56 } // namespace clang::tidy::openmp