Skip to content

Commit c68b4d9

Browse files
committed
Merge remote-tracking branch 'origin/main' into midhun7/big-archive-recognition
2 parents 183197a + 6782346 commit c68b4d9

File tree

271 files changed

+6465
-4684
lines changed

Some content is hidden

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

271 files changed

+6465
-4684
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext(
207207
Twine("BOLT-ERROR: ", Error));
208208

209209
std::unique_ptr<const MCRegisterInfo> MRI(
210-
TheTarget->createMCRegInfo(TripleName));
210+
TheTarget->createMCRegInfo(TheTriple));
211211
if (!MRI)
212212
return createStringError(
213213
make_error_code(std::errc::not_supported),
214214
Twine("BOLT-ERROR: no register info for target ", TripleName));
215215

216216
// Set up disassembler.
217217
std::unique_ptr<MCAsmInfo> AsmInfo(
218-
TheTarget->createMCAsmInfo(*MRI, TripleName, MCTargetOptions()));
218+
TheTarget->createMCAsmInfo(*MRI, TheTriple, MCTargetOptions()));
219219
if (!AsmInfo)
220220
return createStringError(
221221
make_error_code(std::errc::not_supported),
@@ -227,7 +227,7 @@ Expected<std::unique_ptr<BinaryContext>> BinaryContext::createBinaryContext(
227227
AsmInfo->setAllowAtInName(true);
228228

229229
std::unique_ptr<const MCSubtargetInfo> STI(
230-
TheTarget->createMCSubtargetInfo(TripleName, "", FeaturesStr));
230+
TheTarget->createMCSubtargetInfo(TheTriple, "", FeaturesStr));
231231
if (!STI)
232232
return createStringError(
233233
make_error_code(std::errc::not_supported),

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

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
1313
#include "clang/Lex/Lexer.h"
14+
#include "llvm/Support/FormatVariadic.h"
1415

1516
using namespace clang::ast_matchers;
1617

@@ -22,105 +23,104 @@ AST_MATCHER(Expr, isMacroID) { return Node.getExprLoc().isMacroID(); }
2223

2324
void PreferIsaOrDynCastInConditionalsCheck::registerMatchers(
2425
MatchFinder *Finder) {
25-
auto Condition = hasCondition(implicitCastExpr(has(
26-
callExpr(unless(isMacroID()), unless(cxxMemberCallExpr()),
27-
anyOf(callee(namedDecl(hasName("cast"))),
28-
callee(namedDecl(hasName("dyn_cast")).bind("dyn_cast"))))
29-
.bind("call"))));
30-
31-
auto Any = anyOf(
32-
has(declStmt(containsDeclaration(
33-
0, varDecl(hasInitializer(callExpr(unless(isMacroID()),
34-
unless(cxxMemberCallExpr()),
35-
callee(namedDecl(hasName("cast"))))
36-
.bind("assign")))))),
37-
Condition);
38-
39-
auto CallExpression =
26+
auto AnyCalleeName = [](ArrayRef<StringRef> CalleeName) {
27+
return allOf(unless(isMacroID()), unless(cxxMemberCallExpr()),
28+
callee(expr(ignoringImpCasts(
29+
declRefExpr(to(namedDecl(hasAnyName(CalleeName))),
30+
hasAnyTemplateArgumentLoc(anything()))
31+
.bind("callee")))));
32+
};
33+
34+
auto CondExpr = hasCondition(implicitCastExpr(
35+
has(callExpr(AnyCalleeName({"cast", "dyn_cast"})).bind("cond"))));
36+
37+
auto CondExprOrCondVar =
38+
anyOf(hasConditionVariableStatement(containsDeclaration(
39+
0, varDecl(hasInitializer(callExpr(AnyCalleeName({"cast"}))))
40+
.bind("var"))),
41+
CondExpr);
42+
43+
auto CallWithBindedArg =
4044
callExpr(
41-
42-
unless(isMacroID()), unless(cxxMemberCallExpr()),
43-
callee(namedDecl(hasAnyName("isa", "cast", "cast_or_null", "dyn_cast",
44-
"dyn_cast_or_null"))
45-
.bind("func")),
45+
AnyCalleeName(
46+
{"isa", "cast", "cast_or_null", "dyn_cast", "dyn_cast_or_null"}),
4647
hasArgument(0, mapAnyOf(declRefExpr, cxxMemberCallExpr).bind("arg")))
4748
.bind("rhs");
4849

4950
Finder->addMatcher(
50-
traverse(
51-
TK_AsIs,
52-
stmt(anyOf(
53-
ifStmt(Any), whileStmt(Any), doStmt(Condition),
54-
binaryOperator(unless(isExpansionInFileMatching(
55-
"llvm/include/llvm/Support/Casting.h")),
56-
hasOperatorName("&&"),
57-
hasLHS(implicitCastExpr().bind("lhs")),
58-
hasRHS(anyOf(implicitCastExpr(has(CallExpression)),
59-
CallExpression)))
60-
.bind("and")))),
51+
stmt(anyOf(ifStmt(CondExprOrCondVar), forStmt(CondExprOrCondVar),
52+
whileStmt(CondExprOrCondVar), doStmt(CondExpr),
53+
binaryOperator(unless(isExpansionInFileMatching(
54+
"llvm/include/llvm/Support/Casting.h")),
55+
hasOperatorName("&&"),
56+
hasLHS(implicitCastExpr().bind("lhs")),
57+
hasRHS(ignoringImpCasts(CallWithBindedArg)))
58+
.bind("and"))),
6159
this);
6260
}
6361

6462
void PreferIsaOrDynCastInConditionalsCheck::check(
6563
const MatchFinder::MatchResult &Result) {
66-
if (const auto *MatchedDecl = Result.Nodes.getNodeAs<CallExpr>("assign")) {
67-
SourceLocation StartLoc = MatchedDecl->getCallee()->getExprLoc();
68-
SourceLocation EndLoc =
69-
StartLoc.getLocWithOffset(StringRef("cast").size() - 1);
64+
const auto *Callee = Result.Nodes.getNodeAs<DeclRefExpr>("callee");
65+
66+
assert(Callee && "Callee should be binded if anything is matched");
67+
68+
// The first and last letter of the identifier
69+
// llvm::cast<T>(x)
70+
// ^ ^
71+
// StartLoc EndLoc
72+
SourceLocation StartLoc = Callee->getLocation();
73+
SourceLocation EndLoc = Callee->getNameInfo().getEndLoc();
7074

71-
diag(MatchedDecl->getBeginLoc(),
75+
if (Result.Nodes.getNodeAs<VarDecl>("var")) {
76+
diag(StartLoc,
7277
"cast<> in conditional will assert rather than return a null pointer")
7378
<< FixItHint::CreateReplacement(SourceRange(StartLoc, EndLoc),
7479
"dyn_cast");
75-
} else if (const auto *MatchedDecl =
76-
Result.Nodes.getNodeAs<CallExpr>("call")) {
77-
SourceLocation StartLoc = MatchedDecl->getCallee()->getExprLoc();
78-
SourceLocation EndLoc =
79-
StartLoc.getLocWithOffset(StringRef("cast").size() - 1);
80-
80+
} else if (Result.Nodes.getNodeAs<CallExpr>("cond")) {
8181
StringRef Message =
8282
"cast<> in conditional will assert rather than return a null pointer";
83-
if (Result.Nodes.getNodeAs<NamedDecl>("dyn_cast"))
83+
if (Callee->getDecl()->getName() == "dyn_cast")
8484
Message = "return value from dyn_cast<> not used";
8585

86-
diag(MatchedDecl->getBeginLoc(), Message)
86+
diag(StartLoc, Message)
8787
<< FixItHint::CreateReplacement(SourceRange(StartLoc, EndLoc), "isa");
88-
} else if (const auto *MatchedDecl =
89-
Result.Nodes.getNodeAs<BinaryOperator>("and")) {
88+
} else if (Result.Nodes.getNodeAs<BinaryOperator>("and")) {
9089
const auto *LHS = Result.Nodes.getNodeAs<ImplicitCastExpr>("lhs");
9190
const auto *RHS = Result.Nodes.getNodeAs<CallExpr>("rhs");
9291
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
93-
const auto *Func = Result.Nodes.getNodeAs<NamedDecl>("func");
9492

9593
assert(LHS && "LHS is null");
9694
assert(RHS && "RHS is null");
9795
assert(Arg && "Arg is null");
98-
assert(Func && "Func is null");
9996

100-
StringRef LHSString(Lexer::getSourceText(
101-
CharSourceRange::getTokenRange(LHS->getSourceRange()),
102-
*Result.SourceManager, getLangOpts()));
97+
auto GetText = [&](SourceRange R) {
98+
return Lexer::getSourceText(CharSourceRange::getTokenRange(R),
99+
*Result.SourceManager, getLangOpts());
100+
};
103101

104-
StringRef ArgString(Lexer::getSourceText(
105-
CharSourceRange::getTokenRange(Arg->getSourceRange()),
106-
*Result.SourceManager, getLangOpts()));
102+
const StringRef LHSString = GetText(LHS->getSourceRange());
103+
const StringRef ArgString = GetText(Arg->getSourceRange());
107104

108105
if (ArgString != LHSString)
109106
return;
110107

111-
StringRef RHSString(Lexer::getSourceText(
112-
CharSourceRange::getTokenRange(RHS->getSourceRange()),
113-
*Result.SourceManager, getLangOpts()));
114-
115-
std::string Replacement("isa_and_nonnull");
116-
Replacement += RHSString.substr(Func->getName().size());
108+
// It is not clear which is preferred between `isa_and_nonnull` and
109+
// `isa_and_present`. See
110+
// https://discourse.llvm.org/t/psa-swapping-out-or-null-with-if-present/65018
111+
const std::string Replacement = llvm::formatv(
112+
"{}isa_and_nonnull{}",
113+
GetText(Callee->getQualifierLoc().getSourceRange()),
114+
GetText(SourceRange(Callee->getLAngleLoc(), RHS->getEndLoc())));
117115

118-
diag(MatchedDecl->getBeginLoc(),
116+
diag(LHS->getBeginLoc(),
119117
"isa_and_nonnull<> is preferred over an explicit test for null "
120118
"followed by calling isa<>")
121-
<< FixItHint::CreateReplacement(SourceRange(MatchedDecl->getBeginLoc(),
122-
MatchedDecl->getEndLoc()),
123-
Replacement);
119+
<< FixItHint::CreateReplacement(
120+
SourceRange(LHS->getBeginLoc(), RHS->getEndLoc()), Replacement);
121+
} else {
122+
llvm_unreachable(
123+
R"(One of "var", "cond" and "and" should be binded if anything is matched)");
124124
}
125125
}
126126

clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,53 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
3939
return FD ? FD->isMain() : false;
4040
}
4141

42+
template <typename TargetType, typename NodeType>
43+
const TargetType *getAs(const NodeType *Node) {
44+
if constexpr (std::is_same_v<NodeType, clang::DynTypedNode>)
45+
return Node->template get<TargetType>();
46+
else
47+
return llvm::dyn_cast<TargetType>(Node);
48+
}
49+
50+
AST_MATCHER(clang::TypeLoc, isWithinImplicitTemplateInstantiation) {
51+
const auto IsImplicitTemplateInstantiation = [](const auto *Node) {
52+
const auto IsImplicitInstantiation = [](const auto *Node) {
53+
return (Node != nullptr) && (Node->getTemplateSpecializationKind() ==
54+
TSK_ImplicitInstantiation);
55+
};
56+
return (IsImplicitInstantiation(getAs<clang::CXXRecordDecl>(Node)) ||
57+
IsImplicitInstantiation(getAs<clang::FunctionDecl>(Node)) ||
58+
IsImplicitInstantiation(getAs<clang::VarDecl>(Node)));
59+
};
60+
61+
DynTypedNodeList ParentNodes = Finder->getASTContext().getParents(Node);
62+
const clang::NamedDecl *ParentDecl = nullptr;
63+
while (!ParentNodes.empty()) {
64+
const DynTypedNode &ParentNode = ParentNodes[0];
65+
if (IsImplicitTemplateInstantiation(&ParentNode))
66+
return true;
67+
68+
// in case of a `NamedDecl` as parent node, it is more efficient to proceed
69+
// with the upward traversal via DeclContexts (see below) instead of via
70+
// parent nodes
71+
if ((ParentDecl = ParentNode.template get<clang::NamedDecl>()))
72+
break;
73+
74+
ParentNodes = Finder->getASTContext().getParents(ParentNode);
75+
}
76+
77+
if (ParentDecl != nullptr) {
78+
const clang::DeclContext *DeclContext = ParentDecl->getDeclContext();
79+
while (DeclContext != nullptr) {
80+
if (IsImplicitTemplateInstantiation(DeclContext))
81+
return true;
82+
DeclContext = DeclContext->getParent();
83+
}
84+
}
85+
86+
return false;
87+
}
88+
4289
} // namespace
4390

4491
AvoidCArraysCheck::AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
@@ -66,22 +113,38 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
66113
hasParent(varDecl(isExternC())),
67114
hasParent(fieldDecl(
68115
hasParent(recordDecl(isExternCContext())))),
69-
hasAncestor(functionDecl(isExternC())))),
116+
hasAncestor(functionDecl(isExternC())),
117+
isWithinImplicitTemplateInstantiation())),
70118
IgnoreStringArrayIfNeededMatcher)
71119
.bind("typeloc"),
72120
this);
121+
122+
Finder->addMatcher(
123+
templateArgumentLoc(hasTypeLoc(
124+
typeLoc(hasType(arrayType())).bind("template_arg_array_typeloc"))),
125+
this);
73126
}
74127

75128
void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
76-
const auto *ArrayType = Result.Nodes.getNodeAs<TypeLoc>("typeloc");
129+
TypeLoc ArrayTypeLoc{};
130+
131+
if (const auto *MatchedTypeLoc = Result.Nodes.getNodeAs<TypeLoc>("typeloc"))
132+
ArrayTypeLoc = *MatchedTypeLoc;
133+
134+
if (const auto *TemplateArgArrayTypeLoc =
135+
Result.Nodes.getNodeAs<TypeLoc>("template_arg_array_typeloc"))
136+
ArrayTypeLoc = *TemplateArgArrayTypeLoc;
137+
138+
assert(!ArrayTypeLoc.isNull());
139+
77140
const bool IsInParam =
78141
Result.Nodes.getNodeAs<ParmVarDecl>("param_decl") != nullptr;
79-
const bool IsVLA = ArrayType->getTypePtr()->isVariableArrayType();
142+
const bool IsVLA = ArrayTypeLoc.getTypePtr()->isVariableArrayType();
80143
enum class RecommendType { Array, Vector, Span };
81144
llvm::SmallVector<const char *> RecommendTypes{};
82145
if (IsVLA) {
83146
RecommendTypes.push_back("'std::vector'");
84-
} else if (ArrayType->getTypePtr()->isIncompleteArrayType() && IsInParam) {
147+
} else if (ArrayTypeLoc.getTypePtr()->isIncompleteArrayType() && IsInParam) {
85148
// in function parameter, we also don't know the size of
86149
// IncompleteArrayType.
87150
if (Result.Context->getLangOpts().CPlusPlus20)
@@ -93,9 +156,11 @@ void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
93156
} else {
94157
RecommendTypes.push_back("'std::array'");
95158
}
96-
diag(ArrayType->getBeginLoc(),
159+
160+
diag(ArrayTypeLoc.getBeginLoc(),
97161
"do not declare %select{C-style|C VLA}0 arrays, use %1 instead")
98-
<< IsVLA << llvm::join(RecommendTypes, " or ");
162+
<< IsVLA << llvm::join(RecommendTypes, " or ")
163+
<< ArrayTypeLoc.getSourceRange();
99164
}
100165

101166
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ def main():
258258
help="Upgrades clang-tidy warnings to errors. Same format as '-checks'.",
259259
default="",
260260
)
261+
parser.add_argument(
262+
"-hide-progress",
263+
action="store_true",
264+
help="Hide progress",
265+
)
261266

262267
clang_tidy_args = []
263268
argv = sys.argv[1:]
@@ -312,7 +317,8 @@ def main():
312317
if max_task_count == 0:
313318
max_task_count = multiprocessing.cpu_count()
314319
max_task_count = min(len(lines_by_file), max_task_count)
315-
print(f"Running clang-tidy in {max_task_count} threads...")
320+
if not args.hide_progress:
321+
print(f"Running clang-tidy in {max_task_count} threads...")
316322

317323
combine_fixes = False
318324
export_fixes_dir = None
@@ -408,7 +414,8 @@ def main():
408414
return_code = 1
409415

410416
if combine_fixes:
411-
print("Writing fixes to " + args.export_fixes + " ...")
417+
if not args.hide_progress:
418+
print(f"Writing fixes to {args.export_fixes} ...")
412419
try:
413420
merge_replacement_files(export_fixes_dir, args.export_fixes)
414421
except:

0 commit comments

Comments
 (0)