Skip to content

Commit 0b48b3b

Browse files
authored
Merge branch 'main' into users/vhscampos/smallset-simplify
2 parents 3d83c54 + 57b12e8 commit 0b48b3b

File tree

3,234 files changed

+177518
-79964
lines changed

Some content is hidden

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

3,234 files changed

+177518
-79964
lines changed

.github/new-prs-labeler.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,8 @@ bazel:
10081008

10091009
offload:
10101010
- offload/**
1011+
1012+
tablegen:
1013+
- llvm/include/TableGen/**
1014+
- llvm/lib/TableGen/**
1015+
- llvm/utils/TableGen/**

.github/workflows/commit-access-review.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,10 @@ def main():
358358
gh = github.Github(login_or_token=token)
359359
org = gh.get_organization("llvm")
360360
repo = org.get_repo("llvm-project")
361-
team = org.get_team_by_slug("llvm-committers")
362361
one_year_ago = datetime.datetime.now() - datetime.timedelta(days=365)
363362
triage_list = {}
364-
for member in team.get_members():
365-
triage_list[member.login] = User(member.login, triage_list)
363+
for collaborator in repo.get_collaborators(permission="push"):
364+
triage_list[collaborator.login] = User(collaborator.login, triage_list)
366365

367366
print("Start:", len(triage_list), "triagers")
368367
# Step 0 Check if users have requested commit access in the last year.

bolt/lib/Passes/ADRRelaxationPass.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
5959
// Don't relax adr if it points to the same function and it is not split
6060
// and BF initial size is < 1MB.
6161
const unsigned OneMB = 0x100000;
62-
if (!BF.isSplit() && BF.getSize() < OneMB) {
62+
if (BF.getSize() < OneMB) {
6363
BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
64-
if (TargetBF && TargetBF == &BF)
64+
if (TargetBF == &BF && !BF.isSplit())
6565
continue;
66+
// No relaxation needed if ADR references a basic block in the same
67+
// fragment.
68+
if (BinaryBasicBlock *TargetBB = BF.getBasicBlockForLabel(Symbol))
69+
if (BB.getFragmentNum() == TargetBB->getFragmentNum())
70+
continue;
6671
}
6772

6873
MCPhysReg Reg;

bolt/test/lit.local.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
host_linux_triple = config.target_triple.split("-")[0] + "-unknown-linux-gnu"
2-
common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all"
3-
flags = f"--target={host_linux_triple} {common_linker_flags}"
2+
common_linker_flags = "-fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -pie"
3+
flags = f"--target={host_linux_triple} -fPIE {common_linker_flags}"
44

55
config.substitutions.insert(0, ("%cflags", f"%cflags {flags}"))
66
config.substitutions.insert(0, ("%cxxflags", f"%cxxflags {flags}"))

bolt/test/perf2bolt/lit.local.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import shutil
2+
import subprocess
23

3-
if shutil.which("perf") is not None:
4-
config.available_features.add("perf")
4+
if shutil.which("perf") is not None and subprocess.run(["perf", "record", "-e", "cycles:u", "-o", "/dev/null", "--", "perf", "--version"], capture_output=True).returncode == 0:
5+
config.available_features.add("perf")

clang-tools-extra/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ add_subdirectory(clang-move)
2727
add_subdirectory(clang-query)
2828
add_subdirectory(include-cleaner)
2929
add_subdirectory(pp-trace)
30-
add_subdirectory(pseudo)
3130
add_subdirectory(tool-template)
3231

3332
option(CLANG_TOOLS_EXTRA_INCLUDE_DOCS "Generate build targets for the Clang Extra Tools docs."

clang-tools-extra/CODE_OWNERS.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ D: clang-tidy
2323

2424
N: Manuel Klimek
2525
26-
D: clang-rename, all parts of clang-tools-extra not covered by someone else
26+
D: all parts of clang-tools-extra not covered by someone else
2727

2828
N: Sam McCall
2929

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
380380
++Context.Stats.ErrorsIgnoredNOLINT;
381381
// Ignored a warning, should ignore related notes as well
382382
LastErrorWasIgnored = true;
383-
Context.DiagEngine->Clear();
384383
for (const auto &Error : SuppressionErrors)
385384
Context.diag(Error);
386385
return;
@@ -457,7 +456,6 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
457456
if (Info.hasSourceManager())
458457
checkFilters(Info.getLocation(), Info.getSourceManager());
459458

460-
Context.DiagEngine->Clear();
461459
for (const auto &Error : SuppressionErrors)
462460
Context.diag(Error);
463461
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "ForwardingReferenceOverloadCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12-
#include <algorithm>
1312

1413
using namespace clang::ast_matchers;
1514

@@ -19,14 +18,14 @@ namespace {
1918
// Check if the given type is related to std::enable_if.
2019
AST_MATCHER(QualType, isEnableIf) {
2120
auto CheckTemplate = [](const TemplateSpecializationType *Spec) {
22-
if (!Spec || !Spec->getTemplateName().getAsTemplateDecl()) {
21+
if (!Spec)
2322
return false;
24-
}
25-
const NamedDecl *TypeDecl =
26-
Spec->getTemplateName().getAsTemplateDecl()->getTemplatedDecl();
27-
return TypeDecl->isInStdNamespace() &&
28-
(TypeDecl->getName() == "enable_if" ||
29-
TypeDecl->getName() == "enable_if_t");
23+
24+
const TemplateDecl *TDecl = Spec->getTemplateName().getAsTemplateDecl();
25+
26+
return TDecl && TDecl->isInStdNamespace() &&
27+
(TDecl->getName() == "enable_if" ||
28+
TDecl->getName() == "enable_if_t");
3029
};
3130
const Type *BaseType = Node.getTypePtr();
3231
// Case: pointer or reference to enable_if.

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

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,
4848
return false;
4949
}
5050

51+
AST_MATCHER(Expr, offsetOfExpr) { return isa<OffsetOfExpr>(Node); }
52+
5153
CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
5254
if (!Ty || Ty->isIncompleteType() || Ty->isDependentType() ||
5355
isa<DependentSizedArrayType>(Ty) || !Ty->isConstantSizeType())
@@ -221,17 +223,15 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
221223
const auto ElemType =
222224
arrayType(hasElementType(recordType().bind("elem-type")));
223225
const auto ElemPtrType = pointerType(pointee(type().bind("elem-ptr-type")));
226+
const auto SizeofDivideExpr = binaryOperator(
227+
hasOperatorName("/"),
228+
hasLHS(
229+
ignoringParenImpCasts(sizeOfExpr(hasArgumentOfType(hasCanonicalType(
230+
type(anyOf(ElemType, ElemPtrType, type())).bind("num-type")))))),
231+
hasRHS(ignoringParenImpCasts(sizeOfExpr(
232+
hasArgumentOfType(hasCanonicalType(type().bind("denom-type")))))));
224233

225-
Finder->addMatcher(
226-
binaryOperator(
227-
hasOperatorName("/"),
228-
hasLHS(ignoringParenImpCasts(sizeOfExpr(hasArgumentOfType(
229-
hasCanonicalType(type(anyOf(ElemType, ElemPtrType, type()))
230-
.bind("num-type")))))),
231-
hasRHS(ignoringParenImpCasts(sizeOfExpr(
232-
hasArgumentOfType(hasCanonicalType(type().bind("denom-type")))))))
233-
.bind("sizeof-divide-expr"),
234-
this);
234+
Finder->addMatcher(SizeofDivideExpr.bind("sizeof-divide-expr"), this);
235235

236236
// Detect expression like: sizeof(...) * sizeof(...)); most likely an error.
237237
Finder->addMatcher(binaryOperator(hasOperatorName("*"),
@@ -257,8 +257,9 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
257257
.bind("sizeof-sizeof-expr"),
258258
this);
259259

260-
// Detect sizeof in pointer arithmetic like: N * sizeof(S) == P1 - P2 or
261-
// (P1 - P2) / sizeof(S) where P1 and P2 are pointers to type S.
260+
// Detect sizeof usage in comparisons involving pointer arithmetics, such as
261+
// N * sizeof(T) == P1 - P2 or (P1 - P2) / sizeof(T), where P1 and P2 are
262+
// pointers to a type T.
262263
const auto PtrDiffExpr = binaryOperator(
263264
hasOperatorName("-"),
264265
hasLHS(hasType(hasUnqualifiedDesugaredType(pointerType(pointee(
@@ -285,6 +286,47 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
285286
hasRHS(ignoringParenImpCasts(SizeOfExpr.bind("sizeof-ptr-div-expr"))))
286287
.bind("sizeof-in-ptr-arithmetic-div"),
287288
this);
289+
290+
// SEI CERT ARR39-C. Do not add or subtract a scaled integer to a pointer.
291+
// Detect sizeof, alignof and offsetof usage in pointer arithmetics where
292+
// they are used to scale the numeric distance, which is scaled again by
293+
// the pointer arithmetic operator. This can result in forming invalid
294+
// offsets.
295+
//
296+
// Examples, where P is a pointer, N is some integer (both compile-time and
297+
// run-time): P + sizeof(T), P + sizeof(*P), P + N * sizeof(*P).
298+
//
299+
// This check does not warn on cases where the pointee type is "1 byte",
300+
// as those cases can often come from generics and also do not constitute a
301+
// problem because the size does not affect the scale used.
302+
const auto InterestingPtrTyForPtrArithmetic =
303+
pointerType(pointee(qualType().bind("pointee-type")));
304+
const auto SizeofLikeScaleExpr =
305+
expr(anyOf(unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)),
306+
unaryExprOrTypeTraitExpr(ofKind(UETT_AlignOf)),
307+
offsetOfExpr()))
308+
.bind("sizeof-in-ptr-arithmetic-scale-expr");
309+
const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
310+
hasAnyOperatorName("*", "/"),
311+
// sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
312+
// by this check on another path.
313+
hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),
314+
SizeofLikeScaleExpr));
315+
const auto PtrArithmeticScaledIntegerExpr =
316+
expr(anyOf(SizeofLikeScaleExpr, PtrArithmeticIntegerScaleExpr),
317+
unless(SizeofDivideExpr));
318+
319+
Finder->addMatcher(
320+
expr(anyOf(
321+
binaryOperator(hasAnyOperatorName("+", "-"),
322+
hasOperands(hasType(InterestingPtrTyForPtrArithmetic),
323+
PtrArithmeticScaledIntegerExpr))
324+
.bind("sizeof-in-ptr-arithmetic-plusminus"),
325+
binaryOperator(hasAnyOperatorName("+=", "-="),
326+
hasLHS(hasType(InterestingPtrTyForPtrArithmetic)),
327+
hasRHS(PtrArithmeticScaledIntegerExpr))
328+
.bind("sizeof-in-ptr-arithmetic-plusminus"))),
329+
this);
288330
}
289331

290332
void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
@@ -409,6 +451,43 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
409451
<< SizeOfExpr->getSourceRange() << E->getOperatorLoc()
410452
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
411453
}
454+
} else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
455+
"sizeof-in-ptr-arithmetic-plusminus")) {
456+
const auto *PointeeTy = Result.Nodes.getNodeAs<QualType>("pointee-type");
457+
const auto *ScaleExpr =
458+
Result.Nodes.getNodeAs<Expr>("sizeof-in-ptr-arithmetic-scale-expr");
459+
const CharUnits PointeeSize = getSizeOfType(Ctx, PointeeTy->getTypePtr());
460+
const int ScaleKind = [ScaleExpr]() {
461+
if (const auto *UTTE = dyn_cast<UnaryExprOrTypeTraitExpr>(ScaleExpr))
462+
switch (UTTE->getKind()) {
463+
case UETT_SizeOf:
464+
return 0;
465+
case UETT_AlignOf:
466+
return 1;
467+
default:
468+
return -1;
469+
}
470+
471+
if (isa<OffsetOfExpr>(ScaleExpr))
472+
return 2;
473+
474+
return -1;
475+
}();
476+
477+
if (ScaleKind != -1 && PointeeSize > CharUnits::One()) {
478+
diag(E->getExprLoc(),
479+
"suspicious usage of '%select{sizeof|alignof|offsetof}0(...)' in "
480+
"pointer arithmetic; this scaled value will be scaled again by the "
481+
"'%1' operator")
482+
<< ScaleKind << E->getOpcodeStr() << ScaleExpr->getSourceRange();
483+
diag(E->getExprLoc(),
484+
"'%0' in pointer arithmetic internally scales with 'sizeof(%1)' == "
485+
"%2",
486+
DiagnosticIDs::Note)
487+
<< E->getOpcodeStr()
488+
<< PointeeTy->getAsString(Ctx.getPrintingPolicy())
489+
<< PointeeSize.getQuantity();
490+
}
412491
}
413492
}
414493

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace clang::tidy::bugprone {
1515

16-
/// Find suspicious usages of sizeof expression.
16+
/// Find suspicious usages of sizeof expressions.
1717
///
1818
/// For the user-facing documentation see:
1919
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/sizeof-expression.html

clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "../bugprone/ReservedIdentifierCheck.h"
1515
#include "../bugprone/SignalHandlerCheck.h"
1616
#include "../bugprone/SignedCharMisuseCheck.h"
17+
#include "../bugprone/SizeofExpressionCheck.h"
1718
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
1819
#include "../bugprone/SuspiciousMemoryComparisonCheck.h"
1920
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
@@ -281,6 +282,9 @@ class CERTModule : public ClangTidyModule {
281282
"cert-oop58-cpp");
282283

283284
// C checkers
285+
// ARR
286+
CheckFactories.registerCheck<bugprone::SizeofExpressionCheck>(
287+
"cert-arr39-c");
284288
// CON
285289
CheckFactories.registerCheck<bugprone::SpuriouslyWakeUpFunctionsCheck>(
286290
"cert-con36-c");
@@ -332,6 +336,12 @@ class CERTModule : public ClangTidyModule {
332336
ClangTidyOptions getModuleOptions() override {
333337
ClangTidyOptions Options;
334338
ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
339+
Opts["cert-arr39-c.WarnOnSizeOfConstant"] = "false";
340+
Opts["cert-arr39-c.WarnOnSizeOfIntegerExpression"] = "false";
341+
Opts["cert-arr39-c.WarnOnSizeOfThis"] = "false";
342+
Opts["cert-arr39-c.WarnOnSizeOfCompareToConstant"] = "false";
343+
Opts["cert-arr39-c.WarnOnSizeOfPointer"] = "false";
344+
Opts["cert-arr39-c.WarnOnSizeOfPointerToAggregate"] = "false";
335345
Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
336346
Opts["cert-err33-c.CheckedFunctions"] = CertErr33CCheckedFunctions;
337347
Opts["cert-err33-c.AllowCastToVoid"] = "true";

clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,38 @@
99
#include "FloatLoopCounter.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/ASTMatchers/ASTMatchers.h"
1213

1314
using namespace clang::ast_matchers;
1415

1516
namespace clang::tidy::cert {
1617

1718
void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
1819
Finder->addMatcher(
19-
forStmt(hasIncrement(expr(hasType(realFloatingPointType())))).bind("for"),
20+
forStmt(hasIncrement(forEachDescendant(
21+
declRefExpr(hasType(realFloatingPointType()),
22+
to(varDecl().bind("var")))
23+
.bind("inc"))),
24+
hasCondition(forEachDescendant(
25+
declRefExpr(hasType(realFloatingPointType()),
26+
to(varDecl(equalsBoundNode("var"))))
27+
.bind("cond"))))
28+
.bind("for"),
2029
this);
2130
}
2231

2332
void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
2433
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
2534

26-
diag(FS->getInc()->getExprLoc(), "loop induction expression should not have "
27-
"floating-point type");
35+
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
36+
"floating-point type")
37+
<< Result.Nodes.getNodeAs<DeclRefExpr>("inc")->getSourceRange()
38+
<< Result.Nodes.getNodeAs<DeclRefExpr>("cond")->getSourceRange();
39+
40+
if (!FS->getInc()->getType()->isRealFloatingType())
41+
if (const auto *V = Result.Nodes.getNodeAs<VarDecl>("var"))
42+
diag(V->getBeginLoc(), "floating-point type loop induction variable",
43+
DiagnosticIDs::Note);
2844
}
2945

3046
} // namespace clang::tidy::cert

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void updateAssignmentLevel(
8383
memberExpr(hasObjectExpression(cxxThisExpr()),
8484
member(fieldDecl(indexNotLessThan(Field->getFieldIndex()))));
8585
auto DeclMatcher = declRefExpr(
86-
to(varDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
86+
to(valueDecl(unless(parmVarDecl()), hasDeclContext(equalsNode(Ctor)))));
8787
const bool HasDependence = !match(expr(anyOf(MemberMatcher, DeclMatcher,
8888
hasDescendant(MemberMatcher),
8989
hasDescendant(DeclMatcher))),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void DefinitionsInHeadersCheck::check(const MatchFinder::MatchResult &Result) {
102102
// inline is not allowed for main function.
103103
if (FD->isMain())
104104
return;
105-
diag(FD->getLocation(), /*Description=*/"make as 'inline'",
105+
diag(FD->getLocation(), "mark the definition as 'inline'",
106106
DiagnosticIDs::Note)
107107
<< FixItHint::CreateInsertion(FD->getInnerLocStart(), "inline ");
108108
} else if (const auto *VD = dyn_cast<VarDecl>(ND)) {

0 commit comments

Comments
 (0)