Skip to content

Commit 862939d

Browse files
committed
Merge branch 'main' of https://github.com/llvm/llvm-project into sb4-rosb
2 parents 5d628ee + 6ffefbb commit 862939d

File tree

2,431 files changed

+174654
-47910
lines changed

Some content is hidden

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

2,431 files changed

+174654
-47910
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/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()) {}

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ New checks
119119
Warns about code that tries to cast between pointers by means of
120120
``std::bit_cast`` or ``memcpy``.
121121

122+
- New :doc:`bugprone-nondeterministic-pointer-iteration-order
123+
<clang-tidy/checks/bugprone/nondeterministic-pointer-iteration-order>`
124+
check.
125+
126+
Finds nondeterministic usages of pointers in unordered containers.
127+
122128
- New :doc:`bugprone-tagged-union-member-count
123129
<clang-tidy/checks/bugprone/tagged-union-member-count>` check.
124130

@@ -210,6 +216,10 @@ Changes in existing checks
210216
a false positive when only an implicit conversion happened inside an
211217
initializer list.
212218

219+
- Improved :doc:`modernize-use-designated-initializers
220+
<clang-tidy/checks/modernize/use-designated-initializers>` check to fix a
221+
crash when a class is declared but not defined.
222+
213223
- Improved :doc:`modernize-use-nullptr
214224
<clang-tidy/checks/modernize/use-nullptr>` check to also recognize
215225
``NULL``/``__null`` (but not ``0``) when used with a templated type.
@@ -243,13 +253,15 @@ Changes in existing checks
243253

244254
- Improved :doc:`readability-enum-initial-value
245255
<clang-tidy/checks/readability/enum-initial-value>` check by only issuing
246-
diagnostics for the definition of an ``enum``, and by fixing a typo in the
256+
diagnostics for the definition of an ``enum``, by not emitting a redundant
257+
file path for anonymous enums in the diagnostic, and by fixing a typo in the
247258
diagnostic.
248259

249260
- Improved :doc:`readability-implicit-bool-conversion
250261
<clang-tidy/checks/readability/implicit-bool-conversion>` check
251262
by adding the option `UseUpperCaseLiteralSuffix` to select the
252-
case of the literal suffix in fixes.
263+
case of the literal suffix in fixes and fixing false positive for implicit
264+
conversion of comparison result in C23.
253265

254266
- Improved :doc:`readability-redundant-smartptr-get
255267
<clang-tidy/checks/readability/redundant-smartptr-get>` check to

0 commit comments

Comments
 (0)