Skip to content

Commit f1981b1

Browse files
Merge branch 'llvm:main' into varun-r-mallya/btfdebugfile
2 parents bc313ae + 1322e71 commit f1981b1

File tree

223 files changed

+5794
-902
lines changed

Some content is hidden

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

223 files changed

+5794
-902
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/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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
#include "clang/Sema/DeclSpec.h"
16+
17+
using namespace clang::ast_matchers;
18+
19+
namespace clang::tidy::readability {
20+
21+
void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
22+
Finder->addMatcher(typeLoc(unless(hasAncestor(decl(isInstantiated()))))
23+
.bind("nonDependentTypeLoc"),
24+
this);
25+
26+
if (!getLangOpts().CPlusPlus20)
27+
return;
28+
29+
const auto InImplicitTypenameContext = anyOf(
30+
hasParent(decl(anyOf(
31+
typedefNameDecl(), templateTypeParmDecl(), nonTypeTemplateParmDecl(),
32+
friendDecl(), fieldDecl(),
33+
varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())),
34+
unless(parmVarDecl())),
35+
parmVarDecl(hasParent(expr(requiresExpr()))),
36+
parmVarDecl(hasParent(typeLoc(hasParent(decl(
37+
anyOf(cxxMethodDecl(), hasParent(friendDecl()),
38+
functionDecl(has(nestedNameSpecifier())),
39+
cxxDeductionGuideDecl(hasDeclContext(recordDecl())))))))),
40+
// Match return types.
41+
functionDecl(unless(cxxConversionDecl()))))),
42+
hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
43+
Finder->addMatcher(
44+
typeLoc(InImplicitTypenameContext).bind("dependentTypeLoc"), this);
45+
}
46+
47+
void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
48+
const SourceLocation ElaboratedKeywordLoc = [&] {
49+
if (const auto *NonDependentTypeLoc =
50+
Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
51+
if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
52+
return TL.getElaboratedKeywordLoc();
53+
54+
if (const auto TL = NonDependentTypeLoc->getAs<TagTypeLoc>())
55+
return TL.getElaboratedKeywordLoc();
56+
57+
if (const auto TL = NonDependentTypeLoc
58+
->getAs<DeducedTemplateSpecializationTypeLoc>())
59+
return TL.getElaboratedKeywordLoc();
60+
61+
if (const auto TL =
62+
NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
63+
if (!TL.getType()->isDependentType())
64+
return TL.getElaboratedKeywordLoc();
65+
} else {
66+
TypeLoc InnermostTypeLoc =
67+
*Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");
68+
while (const TypeLoc Next = InnermostTypeLoc.getNextTypeLoc())
69+
InnermostTypeLoc = Next;
70+
71+
if (const auto TL = InnermostTypeLoc.getAs<DependentNameTypeLoc>())
72+
return TL.getElaboratedKeywordLoc();
73+
74+
if (const auto TL =
75+
InnermostTypeLoc.getAs<TemplateSpecializationTypeLoc>())
76+
return TL.getElaboratedKeywordLoc();
77+
}
78+
79+
return SourceLocation();
80+
}();
81+
82+
if (ElaboratedKeywordLoc.isInvalid())
83+
return;
84+
85+
if (Token ElaboratedKeyword;
86+
Lexer::getRawToken(ElaboratedKeywordLoc, ElaboratedKeyword,
87+
*Result.SourceManager, getLangOpts()) ||
88+
ElaboratedKeyword.getRawIdentifier() != "typename")
89+
return;
90+
91+
diag(ElaboratedKeywordLoc, "redundant 'typename'")
92+
<< FixItHint::CreateRemoval(ElaboratedKeywordLoc);
93+
}
94+
95+
} // 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

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ New checks
221221

222222
Detect redundant parentheses.
223223

224+
- New :doc:`readability-redundant-typename
225+
<clang-tidy/checks/readability/redundant-typename>` check.
226+
227+
Finds redundant uses of the ``typename`` keyword.
228+
224229
New check aliases
225230
^^^^^^^^^^^^^^^^^
226231

0 commit comments

Comments
 (0)