Skip to content

Commit 5c30009

Browse files
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6 [skip ci]
2 parents 4b43d2f + 859dc6b commit 5c30009

File tree

273 files changed

+7868
-5804
lines changed

Some content is hidden

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

273 files changed

+7868
-5804
lines changed

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
6262
return std::nullopt;
6363
}
6464

65-
static const llvm::StringSet<> DeprecatedGlobalOptions{
66-
"StrictMode",
67-
"IgnoreMacros",
68-
};
69-
7065
static ClangTidyOptions::OptionMap::const_iterator
7166
findPriorityOption(const ClangTidyOptions::OptionMap &Options,
7267
StringRef NamePrefix, StringRef LocalName,
@@ -78,13 +73,6 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options,
7873
}
7974
auto IterLocal = Options.find((NamePrefix + LocalName).str());
8075
auto IterGlobal = Options.find(LocalName);
81-
// FIXME: temporary solution for deprecation warnings, should be removed
82-
// after 22.x. Warn configuration deps on deprecation global options.
83-
if (IterLocal == Options.end() && IterGlobal != Options.end() &&
84-
DeprecatedGlobalOptions.contains(LocalName))
85-
Context->configurationDiag(
86-
"global option '%0' is deprecated, please use '%1%0' instead.")
87-
<< LocalName << NamePrefix;
8876
if (IterLocal == Options.end())
8977
return IterGlobal;
9078
if (IterGlobal == Options.end())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ AST_MATCHER(Decl, isFromStdNamespaceOrSystemHeader) {
3232
ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
3333
ClangTidyContext *Context)
3434
: ClangTidyCheck(Name, Context),
35-
StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
35+
StrictMode(Options.get("StrictMode", false)),
3636
IgnoreSingleArgument(Options.get("IgnoreSingleArgument", false)),
3737
CommentBoolLiterals(Options.get("CommentBoolLiterals", false)),
3838
CommentIntegerLiterals(Options.get("CommentIntegerLiterals", false)),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ AST_MATCHER(CXXMethodDecl, isInLambda) { return Node.getParent()->isLambda(); }
6464
LambdaFunctionNameCheck::LambdaFunctionNameCheck(StringRef Name,
6565
ClangTidyContext *Context)
6666
: ClangTidyCheck(Name, Context),
67-
IgnoreMacros(
68-
Options.getLocalOrGlobal("IgnoreMacros", DefaultIgnoreMacros)) {}
67+
IgnoreMacros(Options.get("IgnoreMacros", DefaultIgnoreMacros)) {}
6968

7069
void LambdaFunctionNameCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7170
Options.store(Opts, "IgnoreMacros", IgnoreMacros);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static bool isPossiblyBitMask(const EnumDecl *EnumDec) {
106106
SuspiciousEnumUsageCheck::SuspiciousEnumUsageCheck(StringRef Name,
107107
ClangTidyContext *Context)
108108
: ClangTidyCheck(Name, Context),
109-
StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
109+
StrictMode(Options.get("StrictMode", false)) {}
110110

111111
void SuspiciousEnumUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
112112
Options.store(Opts, "StrictMode", StrictMode);

clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidDoWhileCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace clang::tidy::cppcoreguidelines {
1515

1616
AvoidDoWhileCheck::AvoidDoWhileCheck(StringRef Name, ClangTidyContext *Context)
1717
: ClangTidyCheck(Name, Context),
18-
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", false)) {}
18+
IgnoreMacros(Options.get("IgnoreMacros", false)) {}
1919

2020
void AvoidDoWhileCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2121
Options.store(Opts, "IgnoreMacros", IgnoreMacros);

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeConstCastCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static bool hasVolatileQualifier(QualType Type) {
3232
ProTypeConstCastCheck::ProTypeConstCastCheck(StringRef Name,
3333
ClangTidyContext *Context)
3434
: ClangTidyCheck(Name, Context),
35-
StrictMode(Options.getLocalOrGlobal("StrictMode", false)) {}
35+
StrictMode(Options.get("StrictMode", false)) {}
3636

3737
void ProTypeConstCastCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3838
Options.store(Opts, "StrictMode", StrictMode);

clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeStaticCastDowncastCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace clang::tidy::cppcoreguidelines {
1717
ProTypeStaticCastDowncastCheck::ProTypeStaticCastDowncastCheck(
1818
StringRef Name, ClangTidyContext *Context)
1919
: ClangTidyCheck(Name, Context),
20-
StrictMode(Options.getLocalOrGlobal("StrictMode", true)) {}
20+
StrictMode(Options.get("StrictMode", true)) {}
2121

2222
void ProTypeStaticCastDowncastCheck::storeOptions(
2323
ClangTidyOptions::OptionMap &Opts) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_clang_library(clangTidyLLVMModule STATIC
1212
PreferStaticOverAnonymousNamespaceCheck.cpp
1313
TwineLocalCheck.cpp
1414
UseNewMLIROpBuilderCheck.cpp
15+
UseRangesCheck.cpp
1516

1617
LINK_LIBS
1718
clangTidy

clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "PreferStaticOverAnonymousNamespaceCheck.h"
2020
#include "TwineLocalCheck.h"
2121
#include "UseNewMLIROpBuilderCheck.h"
22+
#include "UseRangesCheck.h"
2223

2324
namespace clang::tidy {
2425
namespace llvm_check {
@@ -43,6 +44,7 @@ class LLVMModule : public ClangTidyModule {
4344
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
4445
CheckFactories.registerCheck<UseNewMlirOpBuilderCheck>(
4546
"llvm-use-new-mlir-op-builder");
47+
CheckFactories.registerCheck<UseRangesCheck>("llvm-use-ranges");
4648
}
4749

4850
ClangTidyOptions getModuleOptions() override {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//===--- UseRangesCheck.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 "UseRangesCheck.h"
10+
11+
namespace clang::tidy::llvm_check {
12+
13+
namespace {
14+
15+
class StdToLLVMReplacer : public utils::UseRangesCheck::Replacer {
16+
public:
17+
explicit StdToLLVMReplacer(
18+
ArrayRef<utils::UseRangesCheck::Signature> Signatures)
19+
: Signatures(Signatures) {}
20+
21+
ArrayRef<utils::UseRangesCheck::Signature>
22+
getReplacementSignatures() const override {
23+
return Signatures;
24+
}
25+
26+
std::optional<std::string>
27+
getReplaceName(const NamedDecl &OriginalName) const override {
28+
return ("llvm::" + OriginalName.getName()).str();
29+
}
30+
31+
std::optional<std::string>
32+
getHeaderInclusion(const NamedDecl &) const override {
33+
return "llvm/ADT/STLExtras.h";
34+
}
35+
36+
private:
37+
ArrayRef<utils::UseRangesCheck::Signature> Signatures;
38+
};
39+
40+
} // namespace
41+
42+
utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
43+
ReplacerMap Results;
44+
45+
static const Signature SingleSig = {{0}};
46+
static const Signature TwoSig = {{0}, {2}};
47+
48+
const auto AddStdToLLVM =
49+
[&Results](llvm::IntrusiveRefCntPtr<Replacer> Replacer,
50+
std::initializer_list<StringRef> Names) {
51+
for (const auto &Name : Names) {
52+
Results.try_emplace(("::std::" + Name).str(), Replacer);
53+
}
54+
};
55+
56+
// Single range algorithms
57+
AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(SingleSig),
58+
{"all_of", "any_of",
59+
"none_of", "for_each",
60+
"find", "find_if",
61+
"find_if_not", "fill",
62+
"count", "count_if",
63+
"copy", "copy_if",
64+
"transform", "replace",
65+
"remove_if", "stable_sort",
66+
"partition", "partition_point",
67+
"is_sorted", "min_element",
68+
"max_element", "binary_search",
69+
"lower_bound", "upper_bound",
70+
"unique", "uninitialized_copy"});
71+
72+
// Two range algorithms
73+
AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(TwoSig),
74+
{"equal", "mismatch", "includes"});
75+
76+
return Results;
77+
}
78+
79+
UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
80+
: utils::UseRangesCheck(Name, Context) {}
81+
82+
DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
83+
return diag(Call.getBeginLoc(), "use an LLVM range-based algorithm");
84+
}
85+
86+
ArrayRef<std::pair<StringRef, StringRef>>
87+
UseRangesCheck::getFreeBeginEndMethods() const {
88+
static constexpr std::pair<StringRef, StringRef> Refs[] = {
89+
{"::std::begin", "::std::end"},
90+
{"::std::cbegin", "::std::cend"},
91+
{"::std::rbegin", "::std::rend"},
92+
{"::std::crbegin", "::std::crend"},
93+
};
94+
return Refs;
95+
}
96+
97+
} // namespace clang::tidy::llvm_check

0 commit comments

Comments
 (0)