Skip to content

Commit d8a6080

Browse files
authored
Merge branch 'main' into users/el-ev/05-17-_clang_nfc_use_llvm_sort_
2 parents 654b3ab + a86344c commit d8a6080

File tree

599 files changed

+12330
-9349
lines changed

Some content is hidden

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

599 files changed

+12330
-9349
lines changed

bolt/include/bolt/Profile/DataReader.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ struct FuncBranchData {
114114

115115
FuncBranchData() {}
116116

117-
FuncBranchData(StringRef Name, ContainerTy Data)
118-
: Name(Name), Data(std::move(Data)) {}
119-
120-
FuncBranchData(StringRef Name, ContainerTy Data, ContainerTy EntryData)
117+
FuncBranchData(StringRef Name, ContainerTy Data = ContainerTy(),
118+
ContainerTy EntryData = ContainerTy())
121119
: Name(Name), Data(std::move(Data)), EntryData(std::move(EntryData)) {}
122120

123121
ErrorOr<const BranchInfo &> getBranch(uint64_t From, uint64_t To) const;
@@ -205,7 +203,7 @@ struct FuncMemData {
205203

206204
FuncMemData() {}
207205

208-
FuncMemData(StringRef Name, ContainerTy Data)
206+
FuncMemData(StringRef Name, ContainerTy Data = ContainerTy())
209207
: Name(Name), Data(std::move(Data)) {}
210208
};
211209

@@ -241,7 +239,7 @@ struct FuncBasicSampleData {
241239
StringRef Name;
242240
ContainerTy Data;
243241

244-
FuncBasicSampleData(StringRef Name, ContainerTy Data)
242+
FuncBasicSampleData(StringRef Name, ContainerTy Data = ContainerTy())
245243
: Name(Name), Data(std::move(Data)) {}
246244

247245
/// Get the number of samples recorded in [Start, End)

bolt/lib/Core/DebugData.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ static void writeDWARF5LocList(uint32_t &NumberOfEntries, DIEValue &AttrInfo,
676676
return;
677677
}
678678

679-
std::vector<uint64_t> OffsetsArray;
680679
auto writeExpression = [&](uint32_t Index) -> void {
681680
const DebugLocationEntry &Entry = LocList[Index];
682681
encodeULEB128(Entry.Expr.size(), LocBodyStream);

bolt/lib/Passes/FrameAnalysis.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ bool FrameAnalysis::updateArgsTouchedFor(const BinaryFunction &BF, MCInst &Inst,
320320
if (!BC.MIB->isCall(Inst))
321321
return false;
322322

323-
std::set<int64_t> Res;
324323
const MCSymbol *TargetSymbol = BC.MIB->getTargetSymbol(Inst);
325324
// If indirect call, we conservatively assume it accesses all stack positions
326325
if (TargetSymbol == nullptr) {

bolt/lib/Passes/HFSort.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ std::vector<Cluster> clusterize(const CallGraph &Cg) {
239239
}
240240

241241
std::vector<Cluster> randomClusters(const CallGraph &Cg) {
242-
std::vector<NodeId> FuncIds(Cg.numNodes(), 0);
243242
std::vector<Cluster> Clusters;
244243
Clusters.reserve(Cg.numNodes());
245244

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,13 @@ void ShrinkWrapping::computeSaveLocations() {
825825
if (!CSA.CalleeSaved[I])
826826
continue;
827827

828-
std::stable_sort(BestSavePos[I].begin(), BestSavePos[I].end(),
829-
[&](const MCInst *A, const MCInst *B) {
830-
const BinaryBasicBlock *BBA = InsnToBB[A];
831-
const BinaryBasicBlock *BBB = InsnToBB[B];
832-
const uint64_t CountA = BBA->getKnownExecutionCount();
833-
const uint64_t CountB = BBB->getKnownExecutionCount();
834-
return CountB < CountA;
835-
});
828+
llvm::stable_sort(BestSavePos[I], [&](const MCInst *A, const MCInst *B) {
829+
const BinaryBasicBlock *BBA = InsnToBB[A];
830+
const BinaryBasicBlock *BBB = InsnToBB[B];
831+
const uint64_t CountA = BBA->getKnownExecutionCount();
832+
const uint64_t CountB = BBB->getKnownExecutionCount();
833+
return CountB < CountA;
834+
});
836835

837836
for (MCInst *Pos : BestSavePos[I]) {
838837
const BinaryBasicBlock *BB = InsnToBB[Pos];

bolt/lib/Profile/DataReader.cpp

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,26 +1088,11 @@ bool DataReader::hasMemData() {
10881088

10891089
std::error_code DataReader::parseInNoLBRMode() {
10901090
auto GetOrCreateFuncEntry = [&](StringRef Name) {
1091-
auto I = NamesToBasicSamples.find(Name);
1092-
if (I == NamesToBasicSamples.end()) {
1093-
bool Success;
1094-
std::tie(I, Success) = NamesToBasicSamples.insert(std::make_pair(
1095-
Name, FuncBasicSampleData(Name, FuncBasicSampleData::ContainerTy())));
1096-
1097-
assert(Success && "unexpected result of insert");
1098-
}
1099-
return I;
1091+
return NamesToBasicSamples.try_emplace(Name, Name).first;
11001092
};
11011093

11021094
auto GetOrCreateFuncMemEntry = [&](StringRef Name) {
1103-
auto I = NamesToMemEvents.find(Name);
1104-
if (I == NamesToMemEvents.end()) {
1105-
bool Success;
1106-
std::tie(I, Success) = NamesToMemEvents.insert(
1107-
std::make_pair(Name, FuncMemData(Name, FuncMemData::ContainerTy())));
1108-
assert(Success && "unexpected result of insert");
1109-
}
1110-
return I;
1095+
return NamesToMemEvents.try_emplace(Name, Name).first;
11111096
};
11121097

11131098
while (hasBranchData()) {
@@ -1151,26 +1136,11 @@ std::error_code DataReader::parseInNoLBRMode() {
11511136

11521137
std::error_code DataReader::parse() {
11531138
auto GetOrCreateFuncEntry = [&](StringRef Name) {
1154-
auto I = NamesToBranches.find(Name);
1155-
if (I == NamesToBranches.end()) {
1156-
bool Success;
1157-
std::tie(I, Success) = NamesToBranches.insert(std::make_pair(
1158-
Name, FuncBranchData(Name, FuncBranchData::ContainerTy(),
1159-
FuncBranchData::ContainerTy())));
1160-
assert(Success && "unexpected result of insert");
1161-
}
1162-
return I;
1139+
return NamesToBranches.try_emplace(Name, Name).first;
11631140
};
11641141

11651142
auto GetOrCreateFuncMemEntry = [&](StringRef Name) {
1166-
auto I = NamesToMemEvents.find(Name);
1167-
if (I == NamesToMemEvents.end()) {
1168-
bool Success;
1169-
std::tie(I, Success) = NamesToMemEvents.insert(
1170-
std::make_pair(Name, FuncMemData(Name, FuncMemData::ContainerTy())));
1171-
assert(Success && "unexpected result of insert");
1172-
}
1173-
return I;
1143+
return NamesToMemEvents.try_emplace(Name, Name).first;
11741144
};
11751145

11761146
Col = 0;

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4703,7 +4703,6 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
47034703
}
47044704

47054705
// Assign indices to sections.
4706-
std::unordered_map<std::string, uint64_t> NameToIndex;
47074706
for (uint32_t Index = 1; Index < OutputSections.size(); ++Index)
47084707
OutputSections[Index].first->setIndex(Index);
47094708

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
247247
Inst.clear();
248248
Inst.addOperand(MCOperand::createExpr(RISCVMCExpr::create(
249249
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx),
250-
RISCVMCExpr::VK_CALL, *Ctx)));
250+
ELF::R_RISCV_CALL_PLT, *Ctx)));
251251
}
252252

253253
void createCall(MCInst &Inst, const MCSymbol *Target,
@@ -435,19 +435,19 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
435435
case ELF::R_RISCV_TLS_GD_HI20:
436436
// The GOT is reused so no need to create GOT relocations
437437
case ELF::R_RISCV_PCREL_HI20:
438-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_HI, Ctx);
438+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_PCREL_HI20, Ctx);
439439
case ELF::R_RISCV_PCREL_LO12_I:
440440
case ELF::R_RISCV_PCREL_LO12_S:
441441
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_LO, Ctx);
442442
case ELF::R_RISCV_HI20:
443-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_HI, Ctx);
443+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_HI20, Ctx);
444444
case ELF::R_RISCV_LO12_I:
445445
case ELF::R_RISCV_LO12_S:
446446
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_LO, Ctx);
447447
case ELF::R_RISCV_CALL:
448-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL, Ctx);
448+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_CALL_PLT, Ctx);
449449
case ELF::R_RISCV_CALL_PLT:
450-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL_PLT, Ctx);
450+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_CALL_PLT, Ctx);
451451
}
452452
}
453453

@@ -472,8 +472,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
472472
switch (cast<RISCVMCExpr>(ImmExpr)->getSpecifier()) {
473473
default:
474474
return false;
475-
case RISCVMCExpr::VK_CALL:
476-
case RISCVMCExpr::VK_CALL_PLT:
475+
case ELF::R_RISCV_CALL_PLT:
477476
return true;
478477
}
479478
}

bolt/tools/bat-dump/bat-dump.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,6 @@ static void report_error(StringRef Message, Error E) {
7373
exit(1);
7474
}
7575

76-
static std::string GetExecutablePath(const char *Argv0) {
77-
SmallString<256> ExecutablePath(Argv0);
78-
// Do a PATH lookup if Argv0 isn't a valid path.
79-
if (!llvm::sys::fs::exists(ExecutablePath))
80-
if (llvm::ErrorOr<std::string> P =
81-
llvm::sys::findProgramByName(ExecutablePath))
82-
ExecutablePath = *P;
83-
return std::string(ExecutablePath);
84-
}
85-
8676
void dumpBATFor(llvm::object::ELFObjectFileBase *InputFile) {
8777
BoltAddressTranslation BAT;
8878
if (!BAT.enabledFor(InputFile)) {
@@ -163,7 +153,6 @@ int main(int argc, char **argv) {
163153
report_error(opts::InputFilename, errc::no_such_file_or_directory);
164154

165155
ToolName = argv[0];
166-
std::string ToolPath = GetExecutablePath(argv[0]);
167156
Expected<llvm::object::OwningBinary<llvm::object::Binary>> BinaryOrErr =
168157
llvm::object::createBinary(opts::InputFilename);
169158
if (Error E = BinaryOrErr.takeError())

clang-tools-extra/clang-include-fixer/find-all-symbols/SymbolInfo.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "llvm/Support/YAMLTraits.h"
1313
#include "llvm/Support/raw_ostream.h"
1414

15-
using llvm::yaml::MappingTraits;
1615
using ContextType = clang::find_all_symbols::SymbolInfo::ContextType;
1716
using clang::find_all_symbols::SymbolInfo;
1817
using clang::find_all_symbols::SymbolAndSignals;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "LambdaFunctionNameCheck.h"
4242
#include "MacroParenthesesCheck.h"
4343
#include "MacroRepeatedSideEffectsCheck.h"
44+
#include "MisleadingSetterOfReferenceCheck.h"
4445
#include "MisplacedOperatorInStrlenInAllocCheck.h"
4546
#include "MisplacedPointerArithmeticInAllocCheck.h"
4647
#include "MisplacedWideningCastCheck.h"
@@ -170,6 +171,8 @@ class BugproneModule : public ClangTidyModule {
170171
"bugprone-macro-parentheses");
171172
CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
172173
"bugprone-macro-repeated-side-effects");
174+
CheckFactories.registerCheck<MisleadingSetterOfReferenceCheck>(
175+
"bugprone-misleading-setter-of-reference");
173176
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
174177
"bugprone-misplaced-operator-in-strlen-in-alloc");
175178
CheckFactories.registerCheck<MisplacedPointerArithmeticInAllocCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_clang_library(clangTidyBugproneModule STATIC
4242
LambdaFunctionNameCheck.cpp
4343
MacroParenthesesCheck.cpp
4444
MacroRepeatedSideEffectsCheck.cpp
45+
MisleadingSetterOfReferenceCheck.cpp
4546
MisplacedOperatorInStrlenInAllocCheck.cpp
4647
MisplacedPointerArithmeticInAllocCheck.cpp
4748
MisplacedWideningCastCheck.cpp
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===--- MisleadingSetterOfReferenceCheck.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 "MisleadingSetterOfReferenceCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang::tidy::bugprone {
16+
17+
void MisleadingSetterOfReferenceCheck::registerMatchers(MatchFinder *Finder) {
18+
auto RefField = fieldDecl(hasType(hasCanonicalType(referenceType(
19+
pointee(equalsBoundNode("type"))))))
20+
.bind("member");
21+
auto AssignLHS = memberExpr(
22+
hasObjectExpression(ignoringParenCasts(cxxThisExpr())), member(RefField));
23+
auto DerefOperand = expr(ignoringParenCasts(
24+
declRefExpr(to(parmVarDecl(equalsBoundNode("parm"))))));
25+
auto AssignRHS = expr(ignoringParenCasts(
26+
unaryOperator(hasOperatorName("*"), hasUnaryOperand(DerefOperand))));
27+
28+
auto BinaryOpAssign = binaryOperator(hasOperatorName("="), hasLHS(AssignLHS),
29+
hasRHS(AssignRHS));
30+
auto CXXOperatorCallAssign = cxxOperatorCallExpr(
31+
hasOverloadedOperatorName("="), hasLHS(AssignLHS), hasRHS(AssignRHS));
32+
33+
auto SetBody =
34+
compoundStmt(statementCountIs(1),
35+
anyOf(has(BinaryOpAssign), has(CXXOperatorCallAssign)));
36+
auto BadSetFunction =
37+
cxxMethodDecl(
38+
parameterCountIs(1),
39+
hasParameter(
40+
0,
41+
parmVarDecl(hasType(hasCanonicalType(pointerType(pointee(qualType(
42+
hasCanonicalType(qualType().bind("type"))))))))
43+
.bind("parm")),
44+
hasBody(SetBody))
45+
.bind("bad-set-function");
46+
Finder->addMatcher(BadSetFunction, this);
47+
}
48+
49+
void MisleadingSetterOfReferenceCheck::check(
50+
const MatchFinder::MatchResult &Result) {
51+
const auto *Found = Result.Nodes.getNodeAs<CXXMethodDecl>("bad-set-function");
52+
const auto *Member = Result.Nodes.getNodeAs<FieldDecl>("member");
53+
54+
diag(Found->getBeginLoc(),
55+
"function '%0' can be mistakenly used in order to change the "
56+
"reference '%1' instead of the value of it; consider not using a "
57+
"pointer as argument")
58+
<< Found->getName() << Member->getName();
59+
}
60+
61+
} // namespace clang::tidy::bugprone
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- MisleadingSetterOfReferenceCheck.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_BUGPRONE_MISLEADINGSETTEROFREFERENCECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISLEADINGSETTEROFREFERENCECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Emits a warning when a setter-like function that has a pointer parameter
17+
/// is used to set value of a field with reference type.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/throw-keyword-missing.html
21+
class MisleadingSetterOfReferenceCheck : public ClangTidyCheck {
22+
public:
23+
MisleadingSetterOfReferenceCheck(StringRef Name, ClangTidyContext *Context)
24+
: ClangTidyCheck(Name, Context) {}
25+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
26+
return LangOpts.CPlusPlus;
27+
}
28+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30+
std::optional<TraversalKind> getCheckTraversalKind() const override {
31+
return TK_IgnoreUnlessSpelledInSource;
32+
}
33+
};
34+
35+
} // namespace clang::tidy::bugprone
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISLEADINGSETTEROFREFERENCECHECK_H

clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,21 @@ void NewDeleteOverloadsCheck::onEndOfTranslationUnit() {
168168
// complexity when searching for corresponding free store functions.
169169
for (const auto *Overload : RP.second) {
170170
const auto *Match =
171-
std::find_if(RP.second.begin(), RP.second.end(),
172-
[&Overload](const FunctionDecl *FD) {
173-
if (FD == Overload)
174-
return false;
175-
// If the declaration contexts don't match, we don't
176-
// need to check any further.
177-
if (FD->getDeclContext() != Overload->getDeclContext())
178-
return false;
179-
180-
// Since the declaration contexts match, see whether
181-
// the current element is the corresponding operator.
182-
if (!areCorrespondingOverloads(Overload, FD))
183-
return false;
184-
185-
return true;
186-
});
171+
llvm::find_if(RP.second, [&Overload](const FunctionDecl *FD) {
172+
if (FD == Overload)
173+
return false;
174+
// If the declaration contexts don't match, we don't
175+
// need to check any further.
176+
if (FD->getDeclContext() != Overload->getDeclContext())
177+
return false;
178+
179+
// Since the declaration contexts match, see whether
180+
// the current element is the corresponding operator.
181+
if (!areCorrespondingOverloads(Overload, FD))
182+
return false;
183+
184+
return true;
185+
});
187186

188187
if (Match == RP.second.end()) {
189188
// Check to see if there is a corresponding overload in a base class

clang-tools-extra/clangd/refactor/Rename.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ void filterRenameTargets(llvm::DenseSet<const NamedDecl *> &Decls) {
185185
// For renaming, we're only interested in foo's declaration, so drop the other
186186
// one. There should never be more than one UsingDecl here, otherwise the
187187
// rename would be ambiguos anyway.
188-
auto UD = std::find_if(Decls.begin(), Decls.end(), [](const NamedDecl *D) {
189-
return llvm::isa<UsingDecl>(D);
190-
});
188+
auto UD = llvm::find_if(
189+
Decls, [](const NamedDecl *D) { return llvm::isa<UsingDecl>(D); });
191190
if (UD != Decls.end()) {
192191
Decls.erase(UD);
193192
}

0 commit comments

Comments
 (0)