Skip to content

Commit c518ab0

Browse files
committed
Merge from 'main' to 'sycl-web' (276 commits)
CONFLICT (content): Merge conflict in openmp/libomptarget/test/unified_shared_memory/api.c
2 parents 136afd1 + 52556c3 commit c518ab0

File tree

803 files changed

+55972
-38368
lines changed

Some content is hidden

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

803 files changed

+55972
-38368
lines changed

bolt/include/bolt/Core/DebugData.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,9 @@ class DebugAbbrevWriter {
10491049
assert(&Unit.getContext() == &Context &&
10501050
"cannot update attribute from a different DWARF context");
10511051
std::lock_guard<std::mutex> Lock(WriterMutex);
1052-
bool AlreadyAdded = false;
1053-
for (AbbrevEntry &E : NewAbbrevEntries[&Unit][Abbrev])
1054-
if (E.Attr == AttrTag) {
1055-
AlreadyAdded = true;
1056-
break;
1057-
}
1052+
bool AlreadyAdded =
1053+
llvm::any_of(NewAbbrevEntries[&Unit][Abbrev],
1054+
[&](AbbrevEntry &E) { return E.Attr == AttrTag; });
10581055

10591056
if (AlreadyAdded)
10601057
return;

bolt/include/bolt/Profile/DataReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ class DataReader : public ProfileReaderBase {
449449
bool usesEvent(StringRef Name) const {
450450
for (auto I = EventNames.begin(), E = EventNames.end(); I != E; ++I) {
451451
StringRef Event = I->getKey();
452-
if (Event.find(Name) != StringRef::npos)
452+
if (Event.contains(Name))
453453
return true;
454454
}
455455
return false;

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,13 +1824,9 @@ bool BinaryFunction::postProcessIndirectBranches(
18241824
// If this block contains an epilogue code and has an indirect branch,
18251825
// then most likely it's a tail call. Otherwise, we cannot tell for sure
18261826
// what it is and conservatively reject the function's CFG.
1827-
bool IsEpilogue = false;
1828-
for (const MCInst &Instr : BB) {
1829-
if (BC.MIB->isLeave(Instr) || BC.MIB->isPop(Instr)) {
1830-
IsEpilogue = true;
1831-
break;
1832-
}
1833-
}
1827+
bool IsEpilogue = llvm::any_of(BB, [&](const MCInst &Instr) {
1828+
return BC.MIB->isLeave(Instr) || BC.MIB->isPop(Instr);
1829+
});
18341830
if (IsEpilogue) {
18351831
BC.MIB->convertJmpToTailCall(Instr);
18361832
BB.removeAllSuccessors();

bolt/lib/Passes/FrameAnalysis.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,11 @@ bool shouldFrameOptimize(const llvm::bolt::BinaryFunction &Function) {
5656
FrameOptFunctionNamesFile = "";
5757
}
5858

59-
bool IsValid = true;
60-
if (!FrameOptFunctionNames.empty()) {
61-
IsValid = false;
62-
for (std::string &Name : FrameOptFunctionNames) {
63-
if (Function.hasName(Name)) {
64-
IsValid = true;
65-
break;
66-
}
67-
}
68-
}
69-
if (!IsValid)
70-
return false;
71-
72-
return IsValid;
59+
if (FrameOptFunctionNames.empty())
60+
return true;
61+
return llvm::any_of(FrameOptFunctionNames, [&](std::string &Name) {
62+
return Function.hasName(Name);
63+
});
7364
}
7465
} // namespace opts
7566

bolt/lib/Passes/PatchEntries.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "bolt/Passes/PatchEntries.h"
1515
#include "bolt/Utils/NameResolver.h"
16+
#include "llvm/ADT/STLExtras.h"
1617
#include "llvm/Support/CommandLine.h"
1718

1819
namespace opts {
@@ -34,14 +35,11 @@ void PatchEntries::runOnFunctions(BinaryContext &BC) {
3435
if (!opts::ForcePatch) {
3536
// Mark the binary for patching if we did not create external references
3637
// for original code in any of functions we are not going to emit.
37-
bool NeedsPatching = false;
38-
for (auto &BFI : BC.getBinaryFunctions()) {
39-
BinaryFunction &Function = BFI.second;
40-
if (!BC.shouldEmit(Function) && !Function.hasExternalRefRelocations()) {
41-
NeedsPatching = true;
42-
break;
43-
}
44-
}
38+
bool NeedsPatching = llvm::any_of(
39+
llvm::make_second_range(BC.getBinaryFunctions()),
40+
[&](BinaryFunction &BF) {
41+
return !BC.shouldEmit(BF) && !BF.hasExternalRefRelocations();
42+
});
4543

4644
if (!NeedsPatching)
4745
return;

bolt/lib/Passes/ReorderData.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,9 @@ bool filterSymbol(const BinaryData *BD) {
108108
bool IsValid = true;
109109

110110
if (!opts::ReorderSymbols.empty()) {
111-
IsValid = false;
112-
for (const std::string &Name : opts::ReorderSymbols) {
113-
if (BD->hasName(Name)) {
114-
IsValid = true;
115-
break;
116-
}
117-
}
111+
IsValid = llvm::any_of(opts::ReorderSymbols, [&](const std::string &Name) {
112+
return BD->hasName(Name);
113+
});
118114
}
119115

120116
if (!IsValid)

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,14 +1810,10 @@ BBIterTy ShrinkWrapping::processInsertion(BBIterTy InsertionPoint,
18101810
BBIterTy ShrinkWrapping::processInsertionsList(
18111811
BBIterTy InsertionPoint, BinaryBasicBlock *CurBB,
18121812
std::vector<WorklistItem> &TodoList, int64_t SPVal, int64_t FPVal) {
1813-
bool HasInsertions = false;
1814-
for (WorklistItem &Item : TodoList) {
1815-
if (Item.Action == WorklistItem::Erase ||
1816-
Item.Action == WorklistItem::ChangeToAdjustment)
1817-
continue;
1818-
HasInsertions = true;
1819-
break;
1820-
}
1813+
bool HasInsertions = llvm::any_of(TodoList, [&](WorklistItem &Item) {
1814+
return Item.Action == WorklistItem::InsertLoadOrStore ||
1815+
Item.Action == WorklistItem::InsertPushOrPop;
1816+
});
18211817

18221818
if (!HasInsertions)
18231819
return InsertionPoint;

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "bolt/Profile/Heatmap.h"
1919
#include "bolt/Utils/CommandLineOpts.h"
2020
#include "bolt/Utils/Utils.h"
21+
#include "llvm/ADT/STLExtras.h"
2122
#include "llvm/ADT/ScopeExit.h"
2223
#include "llvm/Support/CommandLine.h"
2324
#include "llvm/Support/Debug.h"
@@ -1157,7 +1158,7 @@ ErrorOr<DataAggregator::PerfMemSample> DataAggregator::parseMemSample() {
11571158
ErrorOr<StringRef> Event = parseString(FieldSeparator);
11581159
if (std::error_code EC = Event.getError())
11591160
return EC;
1160-
if (Event.get().find("mem-loads") == StringRef::npos) {
1161+
if (!Event.get().contains("mem-loads")) {
11611162
consumeRestOfLine();
11621163
return Res;
11631164
}
@@ -2022,19 +2023,16 @@ std::error_code DataAggregator::parseMMapEvents() {
20222023
MMapInfo &MMapInfo = I->second;
20232024
if (BC->HasFixedLoadAddress && MMapInfo.MMapAddress) {
20242025
// Check that the binary mapping matches one of the segments.
2025-
bool MatchFound = false;
2026-
for (auto &KV : BC->SegmentMapInfo) {
2027-
SegmentInfo &SegInfo = KV.second;
2028-
// The mapping is page-aligned and hence the MMapAddress could be
2029-
// different from the segment start address. We cannot know the page
2030-
// size of the mapping, but we know it should not exceed the segment
2031-
// alignment value. Hence we are performing an approximate check.
2032-
if (SegInfo.Address >= MMapInfo.MMapAddress &&
2033-
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment) {
2034-
MatchFound = true;
2035-
break;
2036-
}
2037-
}
2026+
bool MatchFound = llvm::any_of(
2027+
llvm::make_second_range(BC->SegmentMapInfo),
2028+
[&](SegmentInfo &SegInfo) {
2029+
// The mapping is page-aligned and hence the MMapAddress could be
2030+
// different from the segment start address. We cannot know the page
2031+
// size of the mapping, but we know it should not exceed the segment
2032+
// alignment value. Hence we are performing an approximate check.
2033+
return SegInfo.Address >= MMapInfo.MMapAddress &&
2034+
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment;
2035+
});
20382036
if (!MatchFound) {
20392037
errs() << "PERF2BOLT-WARNING: ignoring mapping of " << NameToUse
20402038
<< " at 0x" << Twine::utohexstr(MMapInfo.MMapAddress) << '\n';

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "bolt/Utils/CommandLineOpts.h"
3232
#include "bolt/Utils/Utils.h"
3333
#include "llvm/ADT/Optional.h"
34+
#include "llvm/ADT/STLExtras.h"
3435
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
3536
#include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"
3637
#include "llvm/ExecutionEngine/RuntimeDyld.h"
@@ -2500,15 +2501,12 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
25002501
BC->getBinaryFunctionAtAddress(Address + 1)) {
25012502
// Do an extra check that the function was referenced previously.
25022503
// It's a linear search, but it should rarely happen.
2503-
bool Found = false;
2504-
for (const auto &RelKV : ContainingBF->Relocations) {
2505-
const Relocation &Rel = RelKV.second;
2506-
if (Rel.Symbol == RogueBF->getSymbol() &&
2507-
!Relocation::isPCRelative(Rel.Type)) {
2508-
Found = true;
2509-
break;
2510-
}
2511-
}
2504+
bool Found =
2505+
llvm::any_of(llvm::make_second_range(ContainingBF->Relocations),
2506+
[&](const Relocation &Rel) {
2507+
return Rel.Symbol == RogueBF->getSymbol() &&
2508+
!Relocation::isPCRelative(Rel.Type);
2509+
});
25122510

25132511
if (Found) {
25142512
errs() << "BOLT-WARNING: detected possible compiler de-virtualization "

bolt/utils/nfc-check-setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main():
5959
text=True).stdout
6060
if stash:
6161
# save local changes before checkout
62-
subprocess.run(shlex.split("git stash"), cwd=source_dir)
62+
subprocess.run(shlex.split("git stash push -u"), cwd=source_dir)
6363
# check out the previous commit
6464
subprocess.run(shlex.split("git checkout -f HEAD^"), cwd=source_dir)
6565
# get the parent commit hash for logging

clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ std::string getShortestQualifiedNameInNamespace(llvm::StringRef DeclName,
206206
llvm::StringRef NsName) {
207207
DeclName = DeclName.ltrim(':');
208208
NsName = NsName.ltrim(':');
209-
if (DeclName.find(':') == llvm::StringRef::npos)
209+
if (!DeclName.contains(':'))
210210
return std::string(DeclName);
211211

212212
auto NsNameSplitted = splitSymbolName(NsName);

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

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "AssignmentInIfConditionCheck.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/RecursiveASTVisitor.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213

1314
using namespace clang::ast_matchers;
@@ -17,30 +18,61 @@ namespace tidy {
1718
namespace bugprone {
1819

1920
void AssignmentInIfConditionCheck::registerMatchers(MatchFinder *Finder) {
20-
Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
21-
binaryOperator(isAssignmentOperator())
22-
.bind("assignment_in_if_statement")))),
23-
this);
24-
Finder->addMatcher(ifStmt(hasCondition(forEachDescendant(
25-
cxxOperatorCallExpr(isAssignmentOperator())
26-
.bind("assignment_in_if_statement")))),
27-
this);
21+
Finder->addMatcher(translationUnitDecl(), this);
2822
}
2923

3024
void AssignmentInIfConditionCheck::check(
31-
const MatchFinder::MatchResult &Result) {
32-
const auto *MatchedDecl =
33-
Result.Nodes.getNodeAs<clang::Stmt>("assignment_in_if_statement");
34-
if (!MatchedDecl) {
35-
return;
36-
}
37-
diag(MatchedDecl->getBeginLoc(),
38-
"an assignment within an 'if' condition is bug-prone");
39-
diag(MatchedDecl->getBeginLoc(),
25+
const ast_matchers::MatchFinder::MatchResult &Result) {
26+
class Visitor : public RecursiveASTVisitor<Visitor> {
27+
AssignmentInIfConditionCheck &Check;
28+
29+
public:
30+
explicit Visitor(AssignmentInIfConditionCheck &Check) : Check(Check) {}
31+
bool VisitIfStmt(IfStmt *If) {
32+
class ConditionVisitor : public RecursiveASTVisitor<ConditionVisitor> {
33+
AssignmentInIfConditionCheck &Check;
34+
35+
public:
36+
explicit ConditionVisitor(AssignmentInIfConditionCheck &Check)
37+
: Check(Check) {}
38+
39+
// Dont traverse into any lambda expressions.
40+
bool TraverseLambdaExpr(LambdaExpr *, DataRecursionQueue * = nullptr) {
41+
return true;
42+
}
43+
44+
bool VisitBinaryOperator(BinaryOperator *BO) {
45+
if (BO->isAssignmentOp())
46+
Check.report(BO);
47+
return true;
48+
}
49+
50+
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *OCE) {
51+
if (OCE->isAssignmentOp())
52+
Check.report(OCE);
53+
return true;
54+
}
55+
};
56+
57+
ConditionVisitor(Check).TraverseStmt(If->getCond());
58+
return true;
59+
}
60+
};
61+
Visitor(*this).TraverseAST(*Result.Context);
62+
}
63+
64+
void AssignmentInIfConditionCheck::report(const Expr *AssignmentExpr) {
65+
SourceLocation OpLoc =
66+
isa<BinaryOperator>(AssignmentExpr)
67+
? cast<BinaryOperator>(AssignmentExpr)->getOperatorLoc()
68+
: cast<CXXOperatorCallExpr>(AssignmentExpr)->getOperatorLoc();
69+
70+
diag(OpLoc, "an assignment within an 'if' condition is bug-prone")
71+
<< AssignmentExpr->getSourceRange();
72+
diag(OpLoc,
4073
"if it should be an assignment, move it out of the 'if' condition",
4174
DiagnosticIDs::Note);
42-
diag(MatchedDecl->getBeginLoc(),
43-
"if it is meant to be an equality check, change '=' to '=='",
75+
diag(OpLoc, "if it is meant to be an equality check, change '=' to '=='",
4476
DiagnosticIDs::Note);
4577
}
4678

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AssignmentInIfConditionCheck : public ClangTidyCheck {
2525
: ClangTidyCheck(Name, Context) {}
2626
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2727
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
void report(const Expr *AssignmentExpr);
2829
};
2930

3031
} // namespace bugprone

0 commit comments

Comments
 (0)