Skip to content

Commit 0499aab

Browse files
committed
Merge branch 'main' into users/kovdan01/pauth-signed-got-codegen
2 parents a5688e5 + 61a6439 commit 0499aab

File tree

3,894 files changed

+231785
-66497
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,894 files changed

+231785
-66497
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ struct CFISnapshot {
25772577
case MCCFIInstruction::OpAdjustCfaOffset:
25782578
case MCCFIInstruction::OpWindowSave:
25792579
case MCCFIInstruction::OpNegateRAState:
2580+
case MCCFIInstruction::OpNegateRAStateWithPC:
25802581
case MCCFIInstruction::OpLLVMDefAspaceCfa:
25812582
case MCCFIInstruction::OpLabel:
25822583
llvm_unreachable("unsupported CFI opcode");
@@ -2715,6 +2716,7 @@ struct CFISnapshotDiff : public CFISnapshot {
27152716
case MCCFIInstruction::OpAdjustCfaOffset:
27162717
case MCCFIInstruction::OpWindowSave:
27172718
case MCCFIInstruction::OpNegateRAState:
2719+
case MCCFIInstruction::OpNegateRAStateWithPC:
27182720
case MCCFIInstruction::OpLLVMDefAspaceCfa:
27192721
case MCCFIInstruction::OpLabel:
27202722
llvm_unreachable("unsupported CFI opcode");
@@ -2864,6 +2866,7 @@ BinaryFunction::unwindCFIState(int32_t FromState, int32_t ToState,
28642866
case MCCFIInstruction::OpAdjustCfaOffset:
28652867
case MCCFIInstruction::OpWindowSave:
28662868
case MCCFIInstruction::OpNegateRAState:
2869+
case MCCFIInstruction::OpNegateRAStateWithPC:
28672870
case MCCFIInstruction::OpLLVMDefAspaceCfa:
28682871
case MCCFIInstruction::OpLabel:
28692872
llvm_unreachable("unsupported CFI opcode");

bolt/test/X86/pre-aggregated-perf.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ REQUIRES: system-linux
1111

1212
RUN: yaml2obj %p/Inputs/blarge.yaml &> %t.exe
1313
RUN: perf2bolt %t.exe -o %t --pa -p %p/Inputs/pre-aggregated.txt -w %t.new \
14+
RUN: --show-density \
1415
RUN: --profile-density-threshold=9 --profile-density-cutoff-hot=970000 \
1516
RUN: --profile-use-dfs | FileCheck %s --check-prefix=CHECK-P2B
1617

1718
CHECK-P2B: BOLT-INFO: 4 out of 7 functions in the binary (57.1%) have non-empty execution profile
1819
CHECK-P2B: BOLT-INFO: Functions with density >= 21.7 account for 97.00% total sample counts.
1920

2021
RUN: perf2bolt %t.exe -o %t --pa -p %p/Inputs/pre-aggregated.txt -w %t.new \
22+
RUN: --show-density \
2123
RUN: --profile-density-cutoff-hot=970000 \
2224
RUN: --profile-use-dfs 2>&1 | FileCheck %s --check-prefix=CHECK-WARNING
2325

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "MultipleStatementMacroCheck.h"
5050
#include "NoEscapeCheck.h"
5151
#include "NonZeroEnumToBoolConversionCheck.h"
52+
#include "NondeterministicPointerIterationOrderCheck.h"
5253
#include "NotNullTerminatedResultCheck.h"
5354
#include "OptionalValueConversionCheck.h"
5455
#include "ParentVirtualCallCheck.h"
@@ -174,6 +175,8 @@ class BugproneModule : public ClangTidyModule {
174175
"bugprone-multiple-new-in-one-expression");
175176
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
176177
"bugprone-multiple-statement-macro");
178+
CheckFactories.registerCheck<NondeterministicPointerIterationOrderCheck>(
179+
"bugprone-nondeterministic-pointer-iteration-order");
177180
CheckFactories.registerCheck<OptionalValueConversionCheck>(
178181
"bugprone-optional-value-conversion");
179182
CheckFactories.registerCheck<PointerArithmeticOnPolymorphicObjectCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ add_clang_library(clangTidyBugproneModule STATIC
4545
MultipleNewInOneExpressionCheck.cpp
4646
MultipleStatementMacroCheck.cpp
4747
NoEscapeCheck.cpp
48+
NondeterministicPointerIterationOrderCheck.cpp
4849
NonZeroEnumToBoolConversionCheck.cpp
4950
NotNullTerminatedResultCheck.cpp
5051
OptionalValueConversionCheck.cpp
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===----- NondeterministicPointerIterationOrderCheck.cpp - clang-tidy ----===//
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 "NondeterministicPointerIterationOrderCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/Lex/Lexer.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang::tidy::bugprone {
16+
17+
void NondeterministicPointerIterationOrderCheck::registerMatchers(
18+
MatchFinder *Finder) {
19+
20+
auto LoopVariable = varDecl(hasType(
21+
qualType(hasCanonicalType(anyOf(referenceType(), pointerType())))));
22+
23+
auto RangeInit = declRefExpr(to(varDecl(
24+
hasType(recordDecl(hasAnyName("std::unordered_set", "std::unordered_map",
25+
"std::unordered_multiset",
26+
"std::unordered_multimap"))
27+
.bind("recorddecl")))));
28+
29+
Finder->addMatcher(cxxForRangeStmt(hasLoopVariable(LoopVariable),
30+
hasRangeInit(RangeInit.bind("rangeinit")))
31+
.bind("cxxForRangeStmt"),
32+
this);
33+
34+
auto SortFuncM = callee(functionDecl(hasAnyName(
35+
"std::is_sorted", "std::nth_element", "std::sort", "std::partial_sort",
36+
"std::partition", "std::stable_partition", "std::stable_sort")));
37+
38+
auto IteratesPointerEltsM = hasArgument(
39+
0,
40+
cxxMemberCallExpr(on(hasType(cxxRecordDecl(has(fieldDecl(hasType(qualType(
41+
hasCanonicalType(pointsTo(hasCanonicalType(pointerType()))))))))))));
42+
43+
Finder->addMatcher(
44+
callExpr(allOf(SortFuncM, IteratesPointerEltsM)).bind("sortsemantic"),
45+
this);
46+
}
47+
48+
void NondeterministicPointerIterationOrderCheck::check(
49+
const MatchFinder::MatchResult &Result) {
50+
const auto *ForRangePointers =
51+
Result.Nodes.getNodeAs<CXXForRangeStmt>("cxxForRangeStmt");
52+
53+
if ((ForRangePointers) && !(ForRangePointers->getBeginLoc().isMacroID())) {
54+
const auto *RangeInit = Result.Nodes.getNodeAs<Stmt>("rangeinit");
55+
if (const auto *ClassTemplate =
56+
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>(
57+
"recorddecl")) {
58+
const TemplateArgumentList &TemplateArgs =
59+
ClassTemplate->getTemplateArgs();
60+
const bool IsAlgoArgPointer =
61+
TemplateArgs[0].getAsType()->isPointerType();
62+
63+
if (IsAlgoArgPointer) {
64+
SourceRange R = RangeInit->getSourceRange();
65+
diag(R.getBegin(), "iteration of pointers is nondeterministic") << R;
66+
}
67+
}
68+
return;
69+
}
70+
const auto *SortPointers = Result.Nodes.getNodeAs<Stmt>("sortsemantic");
71+
72+
if ((SortPointers) && !(SortPointers->getBeginLoc().isMacroID())) {
73+
SourceRange R = SortPointers->getSourceRange();
74+
diag(R.getBegin(), "sorting pointers is nondeterministic") << R;
75+
}
76+
}
77+
78+
} // namespace clang::tidy::bugprone
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//=== NondeterministicPointerIterationOrderCheck.h - clang-tidy -*- C++ -*-===//
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_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Finds nondeterministic usages of pointers in unordered containers. The
17+
/// check also finds calls to sorting-like algorithms on a container of
18+
/// pointers.
19+
///
20+
/// For the user-facing documentation see:
21+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/nondeterministic-pointer-iteration-order.html
22+
class NondeterministicPointerIterationOrderCheck : public ClangTidyCheck {
23+
public:
24+
NondeterministicPointerIterationOrderCheck(StringRef Name,
25+
ClangTidyContext *Context)
26+
: ClangTidyCheck(Name, Context) {}
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
return LangOpts.CPlusPlus;
29+
}
30+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
31+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
32+
std::optional<TraversalKind> getCheckTraversalKind() const override {
33+
return TK_IgnoreUnlessSpelledInSource;
34+
}
35+
};
36+
37+
} // namespace clang::tidy::bugprone
38+
39+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ReturnConstRefFromParameterCheck.h"
10+
#include "clang/AST/Expr.h"
1011
#include "clang/ASTMatchers/ASTMatchFinder.h"
1112
#include "clang/ASTMatchers/ASTMatchers.h"
1213

@@ -15,19 +16,24 @@ using namespace clang::ast_matchers;
1516
namespace clang::tidy::bugprone {
1617

1718
void ReturnConstRefFromParameterCheck::registerMatchers(MatchFinder *Finder) {
19+
const auto DRef = ignoringParens(
20+
declRefExpr(
21+
to(parmVarDecl(hasType(hasCanonicalType(
22+
qualType(lValueReferenceType(pointee(
23+
qualType(isConstQualified()))))
24+
.bind("type"))))
25+
.bind("param")))
26+
.bind("dref"));
27+
const auto Func =
28+
functionDecl(hasReturnTypeLoc(loc(
29+
qualType(hasCanonicalType(equalsBoundNode("type"))))))
30+
.bind("func");
31+
32+
Finder->addMatcher(returnStmt(hasReturnValue(DRef), hasAncestor(Func)), this);
1833
Finder->addMatcher(
19-
returnStmt(
20-
hasReturnValue(declRefExpr(
21-
to(parmVarDecl(hasType(hasCanonicalType(
22-
qualType(lValueReferenceType(pointee(
23-
qualType(isConstQualified()))))
24-
.bind("type"))))
25-
.bind("param")))),
26-
hasAncestor(
27-
functionDecl(hasReturnTypeLoc(loc(qualType(
28-
hasCanonicalType(equalsBoundNode("type"))))))
29-
.bind("func")))
30-
.bind("ret"),
34+
returnStmt(hasReturnValue(ignoringParens(conditionalOperator(
35+
eachOf(hasTrueExpression(DRef), hasFalseExpression(DRef)),
36+
hasAncestor(Func))))),
3137
this);
3238
}
3339

@@ -85,8 +91,8 @@ void ReturnConstRefFromParameterCheck::check(
8591
const MatchFinder::MatchResult &Result) {
8692
const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>("func");
8793
const auto *PD = Result.Nodes.getNodeAs<ParmVarDecl>("param");
88-
const auto *R = Result.Nodes.getNodeAs<ReturnStmt>("ret");
89-
const SourceRange Range = R->getRetValue()->getSourceRange();
94+
const auto *DRef = Result.Nodes.getNodeAs<DeclRefExpr>("dref");
95+
const SourceRange Range = DRef->getSourceRange();
9096
if (Range.isInvalid())
9197
return;
9298

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,13 @@ unsigned getNumberOfDesignated(const InitListExpr *SyntacticInitList) {
8080
});
8181
}
8282

83-
AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
83+
AST_MATCHER(CXXRecordDecl, isAggregate) {
84+
return Node.hasDefinition() && Node.isAggregate();
85+
}
8486

85-
AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
87+
AST_MATCHER(CXXRecordDecl, isPOD) {
88+
return Node.hasDefinition() && Node.isPOD();
89+
}
8690

8791
AST_MATCHER(InitListExpr, isFullyDesignated) {
8892
if (const InitListExpr *SyntacticForm =

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ AST_MATCHER(EnumDecl, hasSequentialInitialValues) {
123123
return !AllEnumeratorsArePowersOfTwo;
124124
}
125125

126+
std::string getName(const EnumDecl *Decl) {
127+
if (!Decl->getDeclName())
128+
return "<unnamed>";
129+
130+
return Decl->getQualifiedNameAsString();
131+
}
132+
126133
} // namespace
127134

128135
EnumInitialValueCheck::EnumInitialValueCheck(StringRef Name,
@@ -160,10 +167,11 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder *Finder) {
160167
void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
161168
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("inconsistent")) {
162169
DiagnosticBuilder Diag =
163-
diag(Enum->getBeginLoc(),
164-
"initial values in enum %0 are not consistent, consider explicit "
165-
"initialization of all, none or only the first enumerator")
166-
<< Enum;
170+
diag(
171+
Enum->getBeginLoc(),
172+
"initial values in enum '%0' are not consistent, consider explicit "
173+
"initialization of all, none or only the first enumerator")
174+
<< getName(Enum);
167175
for (const EnumConstantDecl *ECD : Enum->enumerators())
168176
if (ECD->getInitExpr() == nullptr) {
169177
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
@@ -183,16 +191,16 @@ void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
183191
if (Loc.isInvalid() || Loc.isMacroID())
184192
return;
185193
DiagnosticBuilder Diag = diag(Loc, "zero initial value for the first "
186-
"enumerator in %0 can be disregarded")
187-
<< Enum;
194+
"enumerator in '%0' can be disregarded")
195+
<< getName(Enum);
188196
cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
189197
return;
190198
}
191199
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("sequential")) {
192200
DiagnosticBuilder Diag =
193201
diag(Enum->getBeginLoc(),
194-
"sequential initial value in %0 can be ignored")
195-
<< Enum;
202+
"sequential initial value in '%0' can be ignored")
203+
<< getName(Enum);
196204
for (const EnumConstantDecl *ECD : llvm::drop_begin(Enum->enumerators()))
197205
cleanInitialValue(Diag, ECD, *Result.SourceManager, getLangOpts());
198206
return;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "../utils/FixItHintUtils.h"
1111
#include "clang/AST/ASTContext.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Lex/Lexer.h"
1415
#include "clang/Tooling/FixIt.h"
1516
#include <queue>
@@ -26,6 +27,8 @@ AST_MATCHER(Stmt, isMacroExpansion) {
2627
return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
2728
}
2829

30+
AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
31+
2932
bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
3033
SourceManager &SM = Context.getSourceManager();
3134
const LangOptions &LO = Context.getLangOpts();
@@ -298,6 +301,11 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
298301
hasCastKind(CK_FloatingToBoolean),
299302
hasCastKind(CK_PointerToBoolean),
300303
hasCastKind(CK_MemberPointerToBoolean)),
304+
// Exclude cases of C23 comparison result.
305+
unless(allOf(isC23(),
306+
hasSourceExpression(ignoringParens(
307+
binaryOperator(hasAnyOperatorName(
308+
">", ">=", "==", "!=", "<", "<=")))))),
301309
// Exclude case of using if or while statements with variable
302310
// declaration, e.g.:
303311
// if (int var = functionCall()) {}

0 commit comments

Comments
 (0)