Skip to content

Commit 42a34c1

Browse files
authored
Merge branch 'main' into fix-mmi-context-ownership
2 parents b7fc560 + 221f15f commit 42a34c1

File tree

1,524 files changed

+91958
-39038
lines changed

Some content is hidden

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

1,524 files changed

+91958
-39038
lines changed

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/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)) {

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

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "AvoidCArraysCheck.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

@@ -60,6 +61,7 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
6061

6162
Finder->addMatcher(
6263
typeLoc(hasValidBeginLoc(), hasType(arrayType()),
64+
optionally(hasParent(parmVarDecl().bind("param_decl"))),
6365
unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
6466
hasParent(varDecl(isExternC())),
6567
hasParent(fieldDecl(
@@ -72,11 +74,28 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
7274

7375
void AvoidCArraysCheck::check(const MatchFinder::MatchResult &Result) {
7476
const auto *ArrayType = Result.Nodes.getNodeAs<TypeLoc>("typeloc");
75-
77+
const bool IsInParam =
78+
Result.Nodes.getNodeAs<ParmVarDecl>("param_decl") != nullptr;
79+
const bool IsVLA = ArrayType->getTypePtr()->isVariableArrayType();
80+
enum class RecommendType { Array, Vector, Span };
81+
llvm::SmallVector<const char *> RecommendTypes{};
82+
if (IsVLA) {
83+
RecommendTypes.push_back("'std::vector'");
84+
} else if (ArrayType->getTypePtr()->isIncompleteArrayType() && IsInParam) {
85+
// in function parameter, we also don't know the size of
86+
// IncompleteArrayType.
87+
if (Result.Context->getLangOpts().CPlusPlus20)
88+
RecommendTypes.push_back("'std::span'");
89+
else {
90+
RecommendTypes.push_back("'std::array'");
91+
RecommendTypes.push_back("'std::vector'");
92+
}
93+
} else {
94+
RecommendTypes.push_back("'std::array'");
95+
}
7696
diag(ArrayType->getBeginLoc(),
77-
"do not declare %select{C-style|C VLA}0 arrays, use "
78-
"%select{std::array<>|std::vector<>}0 instead")
79-
<< ArrayType->getTypePtr()->isVariableArrayType();
97+
"do not declare %select{C-style|C VLA}0 arrays, use %1 instead")
98+
<< IsVLA << llvm::join(RecommendTypes, " or ");
8099
}
81100

82101
} // namespace clang::tidy::modernize

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
262262
/// EndVarName: 'j' (as a VarDecl)
263263
/// In the second example only:
264264
/// EndCallName: 'container.size()' (as a CXXMemberCallExpr) or
265-
/// 'size(contaner)' (as a CallExpr)
265+
/// 'size(container)' (as a CallExpr)
266266
///
267267
/// Client code will need to make sure that:
268268
/// - The containers on which 'size()' is called is the container indexed.
@@ -491,7 +491,7 @@ static bool isDirectMemberExpr(const Expr *E) {
491491
}
492492

493493
/// Given an expression that represents an usage of an element from the
494-
/// containter that we are iterating over, returns false when it can be
494+
/// container that we are iterating over, returns false when it can be
495495
/// guaranteed this element cannot be modified as a result of this usage.
496496
static bool canBeModified(ASTContext *Context, const Expr *E) {
497497
if (E->getType().isConstQualified())
@@ -922,7 +922,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
922922
const ast_matchers::BoundNodes &Nodes,
923923
const ForStmt *Loop,
924924
LoopFixerKind FixerKind) {
925-
// In self contained diagnosics mode we don't want dependancies on other
925+
// In self contained diagnostic mode we don't want dependencies on other
926926
// loops, otherwise, If we already modified the range of this for loop, don't
927927
// do any further updates on this iteration.
928928
if (areDiagsSelfContained())

0 commit comments

Comments
 (0)