Skip to content

Commit 57c5268

Browse files
committed
Merge from 'main' to 'sycl-web' (#10)
CONFLICT (content): Merge conflict in clang/utils/TableGen/ClangAttrEmitter.cpp
2 parents 7242255 + 3b99acb commit 57c5268

File tree

1,463 files changed

+93395
-38567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,463 files changed

+93395
-38567
lines changed

clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ makeRewriteRule(const std::vector<std::string> &StringLikeClassNames,
5353
to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass))));
5454
auto StringFind = cxxMemberCallExpr(
5555
callee(cxxMethodDecl(
56-
hasName("find"),
56+
hasName("find"), parameterCountIs(2),
5757
hasParameter(
5858
0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
5959
hasType(CharType)))))),

clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- BranchCloneCheck.cpp - clang-tidy --------------------------------===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- BranchCloneCheck.h - clang-tidy ------------------------*- C++ -*-===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- UseTrailingReturnTypeCheck.cpp - clang-tidy-----------------------===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- UseTrailingReturnTypeCheck.h - clang-tidy---------------*- C++ -*-===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- SuperSelfCheck.cpp - clang-tidy ----------------------------------===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/objc/SuperSelfCheck.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- SuperSelfCheck.h - clang-tidy --------------------------*- C++ -*-===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/readability/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ add_clang_library(clangTidyReadabilityModule
1313
ElseAfterReturnCheck.cpp
1414
FunctionCognitiveComplexityCheck.cpp
1515
FunctionSizeCheck.cpp
16+
IdentifierLengthCheck.cpp
1617
IdentifierNamingCheck.cpp
1718
ImplicitBoolConversionCheck.cpp
1819
InconsistentDeclarationParameterNameCheck.cpp

clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- ConvertMemberFunctionsToStatic.cpp - clang-tidy ------------------===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- ConvertMemberFunctionsToStatic.h - clang-tidy ----------*- C++ -*-===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
//===--- IdentifierLengthCheck.cpp - clang-tidy
2+
//-----------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "IdentifierLengthCheck.h"
11+
#include "../utils/OptionsUtils.h"
12+
#include "clang/AST/ASTContext.h"
13+
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
15+
using namespace clang::ast_matchers;
16+
17+
namespace clang {
18+
namespace tidy {
19+
namespace readability {
20+
21+
const unsigned DefaultMinimumVariableNameLength = 3;
22+
const unsigned DefaultMinimumLoopCounterNameLength = 2;
23+
const unsigned DefaultMinimumExceptionNameLength = 2;
24+
const unsigned DefaultMinimumParameterNameLength = 3;
25+
const char DefaultIgnoredLoopCounterNames[] = "^[ijk_]$";
26+
const char DefaultIgnoredVariableNames[] = "";
27+
const char DefaultIgnoredExceptionVariableNames[] = "^[e]$";
28+
const char DefaultIgnoredParameterNames[] = "^[n]$";
29+
30+
const char ErrorMessage[] =
31+
"%select{variable|exception variable|loop variable|"
32+
"parameter}0 name %1 is too short, expected at least %2 characters";
33+
34+
IdentifierLengthCheck::IdentifierLengthCheck(StringRef Name,
35+
ClangTidyContext *Context)
36+
: ClangTidyCheck(Name, Context),
37+
MinimumVariableNameLength(Options.get("MinimumVariableNameLength",
38+
DefaultMinimumVariableNameLength)),
39+
MinimumLoopCounterNameLength(Options.get(
40+
"MinimumLoopCounterNameLength", DefaultMinimumLoopCounterNameLength)),
41+
MinimumExceptionNameLength(Options.get(
42+
"MinimumExceptionNameLength", DefaultMinimumExceptionNameLength)),
43+
MinimumParameterNameLength(Options.get(
44+
"MinimumParameterNameLength", DefaultMinimumParameterNameLength)),
45+
IgnoredVariableNamesInput(
46+
Options.get("IgnoredVariableNames", DefaultIgnoredVariableNames)),
47+
IgnoredVariableNames(IgnoredVariableNamesInput),
48+
IgnoredLoopCounterNamesInput(Options.get("IgnoredLoopCounterNames",
49+
DefaultIgnoredLoopCounterNames)),
50+
IgnoredLoopCounterNames(IgnoredLoopCounterNamesInput),
51+
IgnoredExceptionVariableNamesInput(
52+
Options.get("IgnoredExceptionVariableNames",
53+
DefaultIgnoredExceptionVariableNames)),
54+
IgnoredExceptionVariableNames(IgnoredExceptionVariableNamesInput),
55+
IgnoredParameterNamesInput(
56+
Options.get("IgnoredParameterNames", DefaultIgnoredParameterNames)),
57+
IgnoredParameterNames(IgnoredParameterNamesInput) {}
58+
59+
void IdentifierLengthCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
60+
Options.store(Opts, "MinimumVariableNameLength", MinimumVariableNameLength);
61+
Options.store(Opts, "MinimumLoopCounterNameLength",
62+
MinimumLoopCounterNameLength);
63+
Options.store(Opts, "MinimumExceptionNameLength", MinimumExceptionNameLength);
64+
Options.store(Opts, "MinimumParameterNameLength", MinimumParameterNameLength);
65+
Options.store(Opts, "IgnoredLoopCounterNames", IgnoredLoopCounterNamesInput);
66+
Options.store(Opts, "IgnoredVariableNames", IgnoredVariableNamesInput);
67+
Options.store(Opts, "IgnoredExceptionVariableNames",
68+
IgnoredExceptionVariableNamesInput);
69+
Options.store(Opts, "IgnoredParameterNames", IgnoredParameterNamesInput);
70+
}
71+
72+
void IdentifierLengthCheck::registerMatchers(MatchFinder *Finder) {
73+
if (MinimumLoopCounterNameLength > 1)
74+
Finder->addMatcher(
75+
forStmt(hasLoopInit(declStmt(forEach(varDecl().bind("loopVar"))))),
76+
this);
77+
78+
if (MinimumExceptionNameLength > 1)
79+
Finder->addMatcher(varDecl(hasParent(cxxCatchStmt())).bind("exceptionVar"),
80+
this);
81+
82+
if (MinimumParameterNameLength > 1)
83+
Finder->addMatcher(parmVarDecl().bind("paramVar"), this);
84+
85+
if (MinimumVariableNameLength > 1)
86+
Finder->addMatcher(
87+
varDecl(unless(anyOf(hasParent(declStmt(hasParent(forStmt()))),
88+
hasParent(cxxCatchStmt()), parmVarDecl())))
89+
.bind("standaloneVar"),
90+
this);
91+
}
92+
93+
void IdentifierLengthCheck::check(const MatchFinder::MatchResult &Result) {
94+
const auto *StandaloneVar = Result.Nodes.getNodeAs<VarDecl>("standaloneVar");
95+
if (StandaloneVar) {
96+
if (!StandaloneVar->getIdentifier())
97+
return;
98+
99+
StringRef VarName = StandaloneVar->getName();
100+
101+
if (VarName.size() >= MinimumVariableNameLength ||
102+
IgnoredVariableNames.match(VarName))
103+
return;
104+
105+
diag(StandaloneVar->getLocation(), ErrorMessage)
106+
<< 0 << StandaloneVar << MinimumVariableNameLength;
107+
}
108+
109+
auto *ExceptionVarName = Result.Nodes.getNodeAs<VarDecl>("exceptionVar");
110+
if (ExceptionVarName) {
111+
if (!ExceptionVarName->getIdentifier())
112+
return;
113+
114+
StringRef VarName = ExceptionVarName->getName();
115+
if (VarName.size() >= MinimumExceptionNameLength ||
116+
IgnoredExceptionVariableNames.match(VarName))
117+
return;
118+
119+
diag(ExceptionVarName->getLocation(), ErrorMessage)
120+
<< 1 << ExceptionVarName << MinimumExceptionNameLength;
121+
}
122+
123+
const auto *LoopVar = Result.Nodes.getNodeAs<VarDecl>("loopVar");
124+
if (LoopVar) {
125+
if (!LoopVar->getIdentifier())
126+
return;
127+
128+
StringRef VarName = LoopVar->getName();
129+
130+
if (VarName.size() >= MinimumLoopCounterNameLength ||
131+
IgnoredLoopCounterNames.match(VarName))
132+
return;
133+
134+
diag(LoopVar->getLocation(), ErrorMessage)
135+
<< 2 << LoopVar << MinimumLoopCounterNameLength;
136+
}
137+
138+
const auto *ParamVar = Result.Nodes.getNodeAs<VarDecl>("paramVar");
139+
if (ParamVar) {
140+
if (!ParamVar->getIdentifier())
141+
return;
142+
143+
StringRef VarName = ParamVar->getName();
144+
145+
if (VarName.size() >= MinimumParameterNameLength ||
146+
IgnoredParameterNames.match(VarName))
147+
return;
148+
149+
diag(ParamVar->getLocation(), ErrorMessage)
150+
<< 3 << ParamVar << MinimumParameterNameLength;
151+
}
152+
}
153+
154+
} // namespace readability
155+
} // namespace tidy
156+
} // namespace clang
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===--- IdentifierLengthCheck.h - clang-tidy ---------------------*- C++
2+
//-*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERLENGTHCHECK_H
11+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERLENGTHCHECK_H
12+
13+
#include "../ClangTidyCheck.h"
14+
#include "llvm/Support/Regex.h"
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace readability {
19+
20+
/// Warns about identifiers names whose length is too short.
21+
///
22+
/// For the user-facing documentation see:
23+
/// http://clang.llvm.org/extra/clang-tidy/checks/readability-identifier-length.html
24+
class IdentifierLengthCheck : public ClangTidyCheck {
25+
public:
26+
IdentifierLengthCheck(StringRef Name, ClangTidyContext *Context);
27+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
28+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30+
31+
private:
32+
const unsigned MinimumVariableNameLength;
33+
const unsigned MinimumLoopCounterNameLength;
34+
const unsigned MinimumExceptionNameLength;
35+
const unsigned MinimumParameterNameLength;
36+
37+
std::string IgnoredVariableNamesInput;
38+
llvm::Regex IgnoredVariableNames;
39+
40+
std::string IgnoredLoopCounterNamesInput;
41+
llvm::Regex IgnoredLoopCounterNames;
42+
43+
std::string IgnoredExceptionVariableNamesInput;
44+
llvm::Regex IgnoredExceptionVariableNames;
45+
46+
std::string IgnoredParameterNamesInput;
47+
llvm::Regex IgnoredParameterNames;
48+
};
49+
50+
} // namespace readability
51+
} // namespace tidy
52+
} // namespace clang
53+
54+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_IDENTIFIERLENGTHCHECK_H

clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ElseAfterReturnCheck.h"
1919
#include "FunctionCognitiveComplexityCheck.h"
2020
#include "FunctionSizeCheck.h"
21+
#include "IdentifierLengthCheck.h"
2122
#include "IdentifierNamingCheck.h"
2223
#include "ImplicitBoolConversionCheck.h"
2324
#include "InconsistentDeclarationParameterNameCheck.h"
@@ -73,6 +74,8 @@ class ReadabilityModule : public ClangTidyModule {
7374
"readability-function-cognitive-complexity");
7475
CheckFactories.registerCheck<FunctionSizeCheck>(
7576
"readability-function-size");
77+
CheckFactories.registerCheck<IdentifierLengthCheck>(
78+
"readability-identifier-length");
7679
CheckFactories.registerCheck<IdentifierNamingCheck>(
7780
"readability-identifier-naming");
7881
CheckFactories.registerCheck<ImplicitBoolConversionCheck>(

clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- UseAnyOfAllOfCheck.cpp - clang-tidy-------------------------------===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

clang-tools-extra/clang-tidy/readability/UseAnyOfAllOfCheck.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//===--- UseAnyOfAllOfCheck.h - clang-tidy-----------------------*- C++ -*-===//
22
//
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.
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
76
//
87
//===----------------------------------------------------------------------===//
98

0 commit comments

Comments
 (0)