Skip to content

Commit 87ce81e

Browse files
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.7 [skip ci]
2 parents 49264cc + f80b273 commit 87ce81e

File tree

545 files changed

+9691
-2174
lines changed

Some content is hidden

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

545 files changed

+9691
-2174
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,11 @@ class BinaryFunction {
620620
}
621621

622622
/// Return a label at a given \p Address in the function. If the label does
623-
/// not exist - create it. Assert if the \p Address does not belong to
624-
/// the function. If \p CreatePastEnd is true, then return the function
625-
/// end label when the \p Address points immediately past the last byte
626-
/// of the function.
623+
/// not exist - create it.
624+
///
627625
/// NOTE: the function always returns a local (temp) symbol, even if there's
628626
/// a global symbol that corresponds to an entry at this address.
629-
MCSymbol *getOrCreateLocalLabel(uint64_t Address, bool CreatePastEnd = false);
627+
MCSymbol *getOrCreateLocalLabel(uint64_t Address);
630628

631629
/// Register an data entry at a given \p Offset into the function.
632630
void markDataAtOffset(uint64_t Offset) {

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,9 @@ BinaryFunction::processIndirectBranch(MCInst &Instruction, unsigned Size,
10351035
return BranchType;
10361036
}
10371037

1038-
MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
1039-
bool CreatePastEnd) {
1038+
MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address) {
10401039
const uint64_t Offset = Address - getAddress();
10411040

1042-
if ((Offset == getSize()) && CreatePastEnd)
1043-
return getFunctionEndLabel();
1044-
10451041
auto LI = Labels.find(Offset);
10461042
if (LI != Labels.end())
10471043
return LI->second;
@@ -1052,6 +1048,9 @@ MCSymbol *BinaryFunction::getOrCreateLocalLabel(uint64_t Address,
10521048
return IslandSym;
10531049
}
10541050

1051+
if (Offset == getSize())
1052+
return getFunctionEndLabel();
1053+
10551054
MCSymbol *Label = BC.Ctx->createNamedTempSymbol();
10561055
Labels[Offset] = Label;
10571056

@@ -1994,7 +1993,7 @@ void BinaryFunction::postProcessJumpTables() {
19941993
if (IsBuiltinUnreachable) {
19951994
BinaryFunction *TargetBF = BC.getBinaryFunctionAtAddress(EntryAddress);
19961995
MCSymbol *Label = TargetBF ? TargetBF->getSymbol()
1997-
: getOrCreateLocalLabel(EntryAddress, true);
1996+
: getOrCreateLocalLabel(EntryAddress);
19981997
JT.Entries.push_back(Label);
19991998
continue;
20001999
}
@@ -2005,7 +2004,7 @@ void BinaryFunction::postProcessJumpTables() {
20052004
BC.getBinaryFunctionContainingAddress(EntryAddress);
20062005
MCSymbol *Label;
20072006
if (HasOneParent && TargetBF == this) {
2008-
Label = getOrCreateLocalLabel(EntryAddress, true);
2007+
Label = getOrCreateLocalLabel(EntryAddress);
20092008
} else {
20102009
const uint64_t Offset = EntryAddress - TargetBF->getAddress();
20112010
Label = Offset ? TargetBF->addEntryPointAtOffset(Offset)

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,16 @@ void EliminateUnreachableBlocks::runOnFunction(BinaryFunction &Function) {
346346
uint64_t Bytes;
347347
Function.markUnreachableBlocks();
348348
LLVM_DEBUG({
349+
bool HasInvalidBB = false;
349350
for (BinaryBasicBlock &BB : Function) {
350351
if (!BB.isValid()) {
352+
HasInvalidBB = true;
351353
dbgs() << "BOLT-INFO: UCE found unreachable block " << BB.getName()
352354
<< " in function " << Function << "\n";
353-
Function.dump();
354355
}
355356
}
357+
if (HasInvalidBB)
358+
Function.dump();
356359
});
357360
BinaryContext::IndependentCodeEmitter Emitter =
358361
BC.createIndependentMCCodeEmitter();

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2949,9 +2949,7 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
29492949
ReferencedSymbol =
29502950
ReferencedBF->addEntryPointAtOffset(RefFunctionOffset);
29512951
} else {
2952-
ReferencedSymbol =
2953-
ReferencedBF->getOrCreateLocalLabel(Address,
2954-
/*CreatePastEnd =*/true);
2952+
ReferencedSymbol = ReferencedBF->getOrCreateLocalLabel(Address);
29552953

29562954
// If ContainingBF != nullptr, it equals ReferencedBF (see
29572955
// if-condition above) so we're handling a relocation from a function

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
9090
return std::nullopt;
9191
}
9292

93-
static std::optional<bool> getAsBool(StringRef Value,
94-
const llvm::Twine &LookupName) {
95-
93+
static std::optional<bool> getAsBool(StringRef Value) {
9694
if (std::optional<bool> Parsed = llvm::yaml::parseBool(Value))
9795
return Parsed;
98-
// To maintain backwards compatability, we support parsing numbers as
96+
// To maintain backwards compatibility, we support parsing numbers as
9997
// booleans, even though its not supported in YAML.
10098
long long Number = 0;
10199
if (!Value.getAsInteger(10, Number))
@@ -107,7 +105,7 @@ template <>
107105
std::optional<bool>
108106
ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const {
109107
if (std::optional<StringRef> ValueOr = get(LocalName)) {
110-
if (auto Result = getAsBool(*ValueOr, NamePrefix + LocalName))
108+
if (auto Result = getAsBool(*ValueOr))
111109
return Result;
112110
diagnoseBadBooleanOption(NamePrefix + LocalName, *ValueOr);
113111
}
@@ -119,7 +117,7 @@ std::optional<bool>
119117
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
120118
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context);
121119
if (Iter != CheckOptions.end()) {
122-
if (auto Result = getAsBool(Iter->getValue().Value, Iter->getKey()))
120+
if (auto Result = getAsBool(Iter->getValue().Value))
123121
return Result;
124122
diagnoseBadBooleanOption(Iter->getKey(), Iter->getValue().Value);
125123
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static StringRef getReplacementFor(StringRef FunctionName,
4949
// Try to find a better replacement from Annex K first.
5050
StringRef AnnexKReplacementFunction =
5151
StringSwitch<StringRef>(FunctionName)
52-
.Cases("asctime", "asctime_r", "asctime_s")
52+
.Cases({"asctime", "asctime_r"}, "asctime_s")
5353
.Case("gets", "gets_s")
5454
.Default({});
5555
if (!AnnexKReplacementFunction.empty())
@@ -59,7 +59,7 @@ static StringRef getReplacementFor(StringRef FunctionName,
5959
// FIXME: Some of these functions are available in C++ under "std::", and
6060
// should be matched and suggested.
6161
return StringSwitch<StringRef>(FunctionName)
62-
.Cases("asctime", "asctime_r", "strftime")
62+
.Cases({"asctime", "asctime_r"}, "strftime")
6363
.Case("gets", "fgets")
6464
.Case("rewind", "fseek")
6565
.Case("setbuf", "setvbuf");
@@ -90,13 +90,13 @@ static StringRef getReplacementForAdditional(StringRef FunctionName,
9090
/// safer alternative.
9191
static StringRef getRationaleFor(StringRef FunctionName) {
9292
return StringSwitch<StringRef>(FunctionName)
93-
.Cases("asctime", "asctime_r", "ctime",
93+
.Cases({"asctime", "asctime_r", "ctime"},
9494
"is not bounds-checking and non-reentrant")
95-
.Cases("bcmp", "bcopy", "bzero", "is deprecated")
96-
.Cases("fopen", "freopen", "has no exclusive access to the opened file")
95+
.Cases({"bcmp", "bcopy", "bzero"}, "is deprecated")
96+
.Cases({"fopen", "freopen"}, "has no exclusive access to the opened file")
9797
.Case("gets", "is insecure, was deprecated and removed in C11 and C++14")
9898
.Case("getpw", "is dangerous as it may overflow the provided buffer")
99-
.Cases("rewind", "setbuf", "has no error detection")
99+
.Cases({"rewind", "setbuf"}, "has no error detection")
100100
.Case("vfork", "is insecure as it can lead to denial of service "
101101
"situations in the parent process")
102102
.Default("is not bounds-checking");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_clang_library(clangTidyReadabilityModule STATIC
4949
RedundantSmartptrGetCheck.cpp
5050
RedundantStringCStrCheck.cpp
5151
RedundantStringInitCheck.cpp
52+
RedundantTypenameCheck.cpp
5253
ReferenceToConstructedTemporaryCheck.cpp
5354
SimplifyBooleanExprCheck.cpp
5455
SimplifySubscriptExprCheck.cpp

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "RedundantSmartptrGetCheck.h"
5353
#include "RedundantStringCStrCheck.h"
5454
#include "RedundantStringInitCheck.h"
55+
#include "RedundantTypenameCheck.h"
5556
#include "ReferenceToConstructedTemporaryCheck.h"
5657
#include "SimplifyBooleanExprCheck.h"
5758
#include "SimplifySubscriptExprCheck.h"
@@ -143,6 +144,8 @@ class ReadabilityModule : public ClangTidyModule {
143144
"readability-redundant-parentheses");
144145
CheckFactories.registerCheck<RedundantPreprocessorCheck>(
145146
"readability-redundant-preprocessor");
147+
CheckFactories.registerCheck<RedundantTypenameCheck>(
148+
"readability-redundant-typename");
146149
CheckFactories.registerCheck<ReferenceToConstructedTemporaryCheck>(
147150
"readability-reference-to-constructed-temporary");
148151
CheckFactories.registerCheck<SimplifySubscriptExprCheck>(
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//===----------------------------------------------------------------------===//
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 "RedundantTypenameCheck.h"
10+
#include "clang/AST/TypeLoc.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
13+
#include "clang/Basic/Diagnostic.h"
14+
#include "clang/Lex/Lexer.h"
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang::tidy::readability {
19+
20+
void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
21+
Finder->addMatcher(typeLoc(unless(hasAncestor(decl(isInstantiated()))))
22+
.bind("nonDependentTypeLoc"),
23+
this);
24+
25+
if (!getLangOpts().CPlusPlus20)
26+
return;
27+
28+
const auto InImplicitTypenameContext = anyOf(
29+
hasParent(decl(anyOf(
30+
typedefNameDecl(), templateTypeParmDecl(), nonTypeTemplateParmDecl(),
31+
friendDecl(), fieldDecl(),
32+
varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())),
33+
unless(parmVarDecl())),
34+
parmVarDecl(hasParent(expr(requiresExpr()))),
35+
parmVarDecl(hasParent(typeLoc(hasParent(decl(
36+
anyOf(cxxMethodDecl(), hasParent(friendDecl()),
37+
functionDecl(has(nestedNameSpecifier())),
38+
cxxDeductionGuideDecl(hasDeclContext(recordDecl())))))))),
39+
// Match return types.
40+
functionDecl(unless(cxxConversionDecl()))))),
41+
hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
42+
Finder->addMatcher(
43+
typeLoc(InImplicitTypenameContext).bind("dependentTypeLoc"), this);
44+
}
45+
46+
void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
47+
const SourceLocation ElaboratedKeywordLoc = [&] {
48+
if (const auto *NonDependentTypeLoc =
49+
Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
50+
if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
51+
return TL.getElaboratedKeywordLoc();
52+
53+
if (const auto TL = NonDependentTypeLoc->getAs<TagTypeLoc>())
54+
return TL.getElaboratedKeywordLoc();
55+
56+
if (const auto TL = NonDependentTypeLoc
57+
->getAs<DeducedTemplateSpecializationTypeLoc>())
58+
return TL.getElaboratedKeywordLoc();
59+
60+
if (const auto TL =
61+
NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
62+
if (!TL.getType()->isDependentType())
63+
return TL.getElaboratedKeywordLoc();
64+
} else {
65+
TypeLoc InnermostTypeLoc =
66+
*Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");
67+
while (const TypeLoc Next = InnermostTypeLoc.getNextTypeLoc())
68+
InnermostTypeLoc = Next;
69+
70+
if (const auto TL = InnermostTypeLoc.getAs<DependentNameTypeLoc>())
71+
return TL.getElaboratedKeywordLoc();
72+
73+
if (const auto TL =
74+
InnermostTypeLoc.getAs<TemplateSpecializationTypeLoc>())
75+
return TL.getElaboratedKeywordLoc();
76+
}
77+
78+
return SourceLocation();
79+
}();
80+
81+
if (ElaboratedKeywordLoc.isInvalid())
82+
return;
83+
84+
if (Token ElaboratedKeyword;
85+
Lexer::getRawToken(ElaboratedKeywordLoc, ElaboratedKeyword,
86+
*Result.SourceManager, getLangOpts()) ||
87+
ElaboratedKeyword.getRawIdentifier() != "typename")
88+
return;
89+
90+
diag(ElaboratedKeywordLoc, "redundant 'typename'")
91+
<< FixItHint::CreateRemoval(ElaboratedKeywordLoc);
92+
}
93+
94+
} // namespace clang::tidy::readability
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===----------------------------------------------------------------------===//
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_READABILITY_REDUNDANTTYPENAMECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTTYPENAMECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::readability {
15+
16+
/// Finds redundant uses of the `typename` keyword.
17+
///
18+
/// For the user-facing documentation see:
19+
/// https://clang.llvm.org/extra/clang-tidy/checks/readability/redundant-typename.html
20+
class RedundantTypenameCheck : public ClangTidyCheck {
21+
public:
22+
RedundantTypenameCheck(StringRef Name, ClangTidyContext *Context)
23+
: ClangTidyCheck(Name, Context) {}
24+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
25+
return LangOpts.CPlusPlus;
26+
}
27+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29+
std::optional<TraversalKind> getCheckTraversalKind() const override {
30+
return TK_IgnoreUnlessSpelledInSource;
31+
}
32+
};
33+
34+
} // namespace clang::tidy::readability
35+
36+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTTYPENAMECHECK_H

0 commit comments

Comments
 (0)