Skip to content

Commit b2a2273

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: I12d10f81a146b7339f831c912502e3bbd31b5da8
2 parents ff94646 + 4ed696c commit b2a2273

31 files changed

+166
-134
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ AST_MATCHER(FunctionDecl, isExplicitThrow) {
2828
Node.getExceptionSpecSourceRange().isValid();
2929
}
3030

31+
AST_MATCHER(FunctionDecl, hasAtLeastOneParameter) {
32+
return Node.getNumParams() > 0;
33+
}
34+
3135
} // namespace
3236

3337
ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
@@ -58,14 +62,16 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
5862

5963
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
6064
Finder->addMatcher(
61-
functionDecl(isDefinition(),
62-
anyOf(isNoThrow(),
63-
allOf(anyOf(cxxDestructorDecl(),
64-
cxxConstructorDecl(isMoveConstructor()),
65-
cxxMethodDecl(isMoveAssignmentOperator()),
66-
isMain(), hasName("swap")),
67-
unless(isExplicitThrow())),
68-
isEnabled(FunctionsThatShouldNotThrow)))
65+
functionDecl(
66+
isDefinition(),
67+
anyOf(isNoThrow(),
68+
allOf(anyOf(cxxDestructorDecl(),
69+
cxxConstructorDecl(isMoveConstructor()),
70+
cxxMethodDecl(isMoveAssignmentOperator()), isMain(),
71+
allOf(hasAnyName("swap", "iter_swap", "iter_move"),
72+
hasAtLeastOneParameter())),
73+
unless(isExplicitThrow())),
74+
isEnabled(FunctionsThatShouldNotThrow)))
6975
.bind("thrower"),
7076
this);
7177
}

clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
3939
.bind("type"))))),
4040
hasParameter(1, hasType(qualType(hasCanonicalType(
4141
qualType(equalsBoundNode("type")))))));
42-
Finder->addMatcher(functionDecl(unless(isDeleted()), hasName("swap"),
42+
Finder->addMatcher(functionDecl(unless(isDeleted()),
43+
hasAnyName("swap", "iter_swap"),
4344
anyOf(MethodMatcher, FunctionMatcher))
4445
.bind(BindFuncDeclName),
4546
this);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,18 @@ New checks
224224
Recommends the smallest possible underlying type for an ``enum`` or ``enum``
225225
class based on the range of its enumerators.
226226

227-
- New :doc:`readability-reference-to-constructed-temporary
228-
<clang-tidy/checks/readability/reference-to-constructed-temporary>` check.
229-
230-
Detects C++ code where a reference variable is used to extend the lifetime
231-
of a temporary object that has just been constructed.
232-
233227
- New :doc:`readability-avoid-return-with-void-value
234228
<clang-tidy/checks/readability/avoid-return-with-void-value>` check.
235229

236230
Finds return statements with ``void`` values used within functions with
237231
``void`` result types.
238232

233+
- New :doc:`readability-reference-to-constructed-temporary
234+
<clang-tidy/checks/readability/reference-to-constructed-temporary>` check.
235+
236+
Detects C++ code where a reference variable is used to extend the lifetime
237+
of a temporary object that has just been constructed.
238+
239239
New check aliases
240240
^^^^^^^^^^^^^^^^^
241241

@@ -260,6 +260,10 @@ Changes in existing checks
260260
casting during type conversions at variable initialization, now with improved
261261
compatibility for C++17 and later versions.
262262

263+
- Improved :doc:`bugprone-exception-escape
264+
<clang-tidy/checks/bugprone/exception-escape>` check by extending the default
265+
check function names to include ``iter_swap`` and ``iter_move``.
266+
263267
- Improved :doc:`bugprone-implicit-widening-of-multiplication-result
264268
<clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result>` check
265269
to correctly emit fixes.
@@ -391,7 +395,7 @@ Changes in existing checks
391395

392396
- Improved :doc:`misc-unused-using-decls
393397
<clang-tidy/checks/misc/unused-using-decls>` check to avoid false positive when
394-
using in elaborated type and only check cpp files.
398+
using in elaborated type and only check C++ files.
395399

396400
- Improved :doc:`modernize-avoid-bind
397401
<clang-tidy/checks/modernize/avoid-bind>` check to
@@ -431,33 +435,34 @@ Changes in existing checks
431435

432436
- Improved :doc:`modernize-use-using
433437
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
434-
forward declared ``typedef`` correctly. Added option `IgnoreExternC` to ignore ``typedef``
435-
declaration in ``extern "C"`` scope.
438+
forward declared ``typedef`` correctly. Added option `IgnoreExternC` to ignore
439+
``typedef`` declaration in ``extern "C"`` scope.
436440

437441
- Improved :doc:`performance-faster-string-find
438442
<clang-tidy/checks/performance/faster-string-find>` check to properly escape
439443
single quotes.
440444

441445
- Improved :doc:`performance-noexcept-move-constructor
442446
<clang-tidy/checks/performance/noexcept-move-constructor>` to better handle
443-
conditional noexcept expressions, eliminating false-positives.
447+
conditional ``noexcept`` expressions, eliminating false-positives.
444448

445449
- Improved :doc:`performance-noexcept-swap
446450
<clang-tidy/checks/performance/noexcept-swap>` check to enforce a stricter
447451
match with the swap function signature and better handling of condition
448-
noexcept expressions, eliminating false-positives.
452+
``noexcept`` expressions, eliminating false-positives. ``iter_swap`` function
453+
name is checked by default.
449454

450455
- Improved :doc:`readability-braces-around-statements
451456
<clang-tidy/checks/readability/braces-around-statements>` check to
452457
ignore false-positive for ``if constexpr`` in lambda expression.
453458

454459
- Improved :doc:`readability-avoid-const-params-in-decls
455-
<clang-tidy/checks/readability/avoid-const-params-in-decls>` diagnositics to
456-
highlight the const location
460+
<clang-tidy/checks/readability/avoid-const-params-in-decls>` diagnostics to
461+
highlight the ``const`` location
457462

458463
- Improved :doc:`readability-container-contains
459464
<clang-tidy/checks/readability/container-contains>` to correctly handle
460-
interger literals with suffixes in fix-its.
465+
integer literals with suffixes in fix-its.
461466

462467
- Improved :doc:`readability-container-size-empty
463468
<clang-tidy/checks/readability/container-size-empty>` check to
@@ -480,7 +485,7 @@ Changes in existing checks
480485
``camel_Snake_Case`` now detect more invalid identifier names. Fields in
481486
anonymous records (i.e. anonymous structs and unions) now can be checked with
482487
the naming rules associated with their enclosing scopes rather than the naming
483-
rules of public struct/union members.
488+
rules of public ``struct``/``union`` members.
484489

485490
- Improved :doc:`readability-implicit-bool-conversion
486491
<clang-tidy/checks/readability/implicit-bool-conversion>` check to take

clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ should not. The functions which should not throw exceptions are the following:
1111
* Move assignment operators
1212
* The ``main()`` functions
1313
* ``swap()`` functions
14+
* ``iter_swap()`` functions
15+
* ``iter_move()`` functions
1416
* Functions marked with ``throw()`` or ``noexcept``
1517
* Other functions given as option
1618

clang-tools-extra/docs/clang-tidy/checks/performance/noexcept-swap.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
performance-noexcept-swap
44
=========================
55

6-
The check flags user-defined swap functions not marked with ``noexcept`` or
6+
The check flags user-defined swap and iter_swap functions not marked with ``noexcept`` or
77
marked with ``noexcept(expr)`` where ``expr`` evaluates to ``false``
88
(but is not a ``false`` literal itself).
99

10-
When a swap function is marked as ``noexcept``, it assures the compiler that
10+
When a swap or iter_swap function is marked as ``noexcept``, it assures the compiler that
1111
no exceptions will be thrown during the swapping of two objects, which allows
1212
the compiler to perform certain optimizations such as omitting exception
1313
handling code.

clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,16 @@ void swap(int&, int&) {
586586
throw 1;
587587
}
588588

589+
void iter_swap(int&, int&) {
590+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'iter_swap' which should not throw exceptions
591+
throw 1;
592+
}
593+
594+
void iter_move(int&) {
595+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'iter_move' which should not throw exceptions
596+
throw 1;
597+
}
598+
589599
namespace std {
590600
class bad_alloc {};
591601
}

clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-swap.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ void swap(A &, A &);
3232
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
3333
// CHECK-FIXES: void swap(A &, A &) noexcept ;
3434

35+
void iter_swap(A &, A &);
36+
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: swap functions should be marked noexcept [performance-noexcept-swap]
37+
// CHECK-FIXES: void iter_swap(A &, A &) noexcept ;
38+
3539
struct B {
3640
static constexpr bool kFalse = false;
3741
void swap(B &) noexcept(kFalse);

clang/test/Format/clang-format-ignore.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,45 @@
77
// RUN: echo "level*/*.c*" >> .clang-format-ignore
88
// RUN: echo "*/*2/foo.*" >> .clang-format-ignore
99
// RUN: touch foo.cc
10-
// RUN: clang-format -verbose .clang-format-ignore foo.cc 2> %t.stderr
11-
// RUN: not grep Formatting %t.stderr
10+
// RUN: clang-format -verbose .clang-format-ignore foo.cc 2>&1 \
11+
// RUN: | FileCheck %s -allow-empty
1212

1313
// RUN: cd level1
1414
// RUN: touch bar.cc baz.c
15-
// RUN: clang-format -verbose bar.cc baz.c 2> %t.stderr
16-
// RUN: not grep Formatting %t.stderr
15+
// RUN: clang-format -verbose bar.cc baz.c 2>&1 | FileCheck %s -allow-empty
1716

1817
// RUN: cd level2
1918
// RUN: touch foo.c foo.js
20-
// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
21-
// RUN: not grep Formatting %t.stderr
19+
// RUN: clang-format -verbose foo.c foo.js 2>&1 | FileCheck %s -allow-empty
20+
21+
// CHECK-NOT: Formatting
2222

2323
// RUN: touch .clang-format-ignore
24-
// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
25-
// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
26-
// RUN: grep -Fx "Formatting [2/2] foo.js" %t.stderr
24+
// RUN: clang-format -verbose foo.c foo.js 2>&1 \
25+
// RUN: | FileCheck %s -check-prefix=CHECK2 -match-full-lines
26+
// CHECK2: Formatting [1/2] foo.c
27+
// CHECK2-NEXT: Formatting [2/2] foo.js
2728

2829
// RUN: echo "*.js" > .clang-format-ignore
29-
// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
30-
// RUN: grep -Fx "Formatting [1/2] foo.c" %t.stderr
31-
// RUN: not grep -F foo.js %t.stderr
30+
// RUN: clang-format -verbose foo.c foo.js 2>&1 \
31+
// RUN: | FileCheck %s -check-prefix=CHECK3 -match-full-lines
32+
// CHECK3: Formatting [1/2] foo.c
33+
// CHECK3-NOT: foo.js
3234

3335
// RUN: cd ../..
34-
// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
35-
// RUN: grep -x "Formatting \[1/5] .*foo\.c" %t.stderr
36-
// RUN: not grep -F foo.js %t.stderr
36+
// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
37+
// RUN: | FileCheck %s -check-prefix=CHECK4 -match-full-lines
38+
// CHECK4: {{Formatting \[1/5] .*foo\.c}}
39+
// CHECK4-NOT: foo.js
3740

3841
// RUN: rm .clang-format-ignore
39-
// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2> %t.stderr
40-
// RUN: grep -x "Formatting \[1/5] .*foo\.cc" %t.stderr
41-
// RUN: grep -x "Formatting \[2/5] .*bar\.cc" %t.stderr
42-
// RUN: grep -x "Formatting \[3/5] .*baz\.c" %t.stderr
43-
// RUN: grep -x "Formatting \[4/5] .*foo\.c" %t.stderr
44-
// RUN: not grep -F foo.js %t.stderr
42+
// RUN: clang-format -verbose *.cc level1/*.c* level1/level2/foo.* 2>&1 \
43+
// RUN: | FileCheck %s -check-prefix=CHECK5 -match-full-lines
44+
// CHECK5: {{Formatting \[1/5] .*foo\.cc}}
45+
// CHECK5-NEXT: {{Formatting \[2/5] .*bar\.cc}}
46+
// CHECK5-NEXT: {{Formatting \[3/5] .*baz\.c}}
47+
// CHECK5-NEXT: {{Formatting \[4/5] .*foo\.c}}
48+
// CHECK5-NOT: foo.js
4549

4650
// RUN: cd ..
4751
// RUN: rm -r %t.dir

clang/tools/libclang/linker-script-to-export-list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
output_file = open(sys.argv[2], "w")
77

88
for line in input_file:
9-
m = re.search("^\s+(clang_[^;]+)", line)
9+
m = re.search(r"^\s+(clang_[^;]+)", line)
1010
if m:
1111
output_file.write(m.group(1) + "\n")

llvm/lib/Bitcode/Writer/ValueEnumerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,8 @@ void ValueEnumerator::purgeFunction() {
11271127
/// Remove purged values from the ValueMap.
11281128
for (unsigned i = NumModuleValues, e = Values.size(); i != e; ++i)
11291129
ValueMap.erase(Values[i].first);
1130-
for (unsigned i = NumModuleMDs, e = MDs.size(); i != e; ++i)
1131-
MetadataMap.erase(MDs[i]);
1130+
for (const Metadata *MD : llvm::drop_begin(MDs, NumModuleMDs))
1131+
MetadataMap.erase(MD);
11321132
for (const BasicBlock *BB : BasicBlocks)
11331133
ValueMap.erase(BB);
11341134

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3534,8 +3534,7 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) {
35343534
Results.push_back(ExpandFABS(Node));
35353535
break;
35363536
case ISD::IS_FPCLASS: {
3537-
auto CNode = cast<ConstantSDNode>(Node->getOperand(1));
3538-
auto Test = static_cast<FPClassTest>(CNode->getZExtValue());
3537+
auto Test = static_cast<FPClassTest>(Node->getConstantOperandVal(1));
35393538
if (SDValue Expanded =
35403539
TLI.expandIS_FPCLASS(Node->getValueType(0), Node->getOperand(0),
35413540
Test, Node->getFlags(), SDLoc(Node), DAG))

llvm/lib/IR/AutoUpgrade.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,18 +2351,10 @@ void llvm::UpgradeIntrinsicCall(CallBase *CI, Function *NewFn) {
23512351
assert(Name.starts_with("llvm.") && "Intrinsic doesn't start with 'llvm.'");
23522352
Name = Name.substr(5);
23532353

2354-
bool IsX86 = Name.starts_with("x86.");
2355-
if (IsX86)
2356-
Name = Name.substr(4);
2357-
bool IsNVVM = Name.starts_with("nvvm.");
2358-
if (IsNVVM)
2359-
Name = Name.substr(5);
2360-
bool IsARM = Name.starts_with("arm.");
2361-
if (IsARM)
2362-
Name = Name.substr(4);
2363-
bool IsAMDGCN = Name.starts_with("amdgcn.");
2364-
if (IsAMDGCN)
2365-
Name = Name.substr(7);
2354+
bool IsX86 = Name.consume_front("x86.");
2355+
bool IsNVVM = Name.consume_front("nvvm.");
2356+
bool IsARM = Name.consume_front("arm.");
2357+
bool IsAMDGCN = Name.consume_front("amdgcn.");
23662358

23672359
if (IsX86 && Name.starts_with("sse4a.movnt.")) {
23682360
SmallVector<Metadata *, 1> Elts;

llvm/lib/IR/Dominators.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ static constexpr bool ExpensiveChecksEnabled = false;
4949
#endif
5050

5151
bool BasicBlockEdge::isSingleEdge() const {
52-
const Instruction *TI = Start->getTerminator();
5352
unsigned NumEdgesToEnd = 0;
54-
for (unsigned int i = 0, n = TI->getNumSuccessors(); i < n; ++i) {
55-
if (TI->getSuccessor(i) == End)
53+
for (const BasicBlock *Succ : successors(Start)) {
54+
if (Succ == End)
5655
++NumEdgesToEnd;
5756
if (NumEdgesToEnd >= 2)
5857
return false;

llvm/lib/IR/Globals.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ std::string GlobalValue::getGlobalIdentifier(StringRef Name,
147147
// Value names may be prefixed with a binary '1' to indicate
148148
// that the backend should not modify the symbols due to any platform
149149
// naming convention. Do not include that '1' in the PGO profile name.
150-
if (Name[0] == '\1')
151-
Name = Name.substr(1);
150+
Name.consume_front("\1");
152151

153152
std::string GlobalName;
154153
if (llvm::GlobalValue::isLocalLinkage(Linkage)) {

llvm/lib/IR/StructuralHash.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,9 @@ class StructuralHashImpl {
125125
for (auto &Inst : *BB)
126126
updateInstruction(Inst, DetailedHash);
127127

128-
const Instruction *Term = BB->getTerminator();
129-
for (unsigned i = 0, e = Term->getNumSuccessors(); i != e; ++i) {
130-
if (!VisitedBBs.insert(Term->getSuccessor(i)).second)
131-
continue;
132-
BBs.push_back(Term->getSuccessor(i));
133-
}
128+
for (const BasicBlock *Succ : successors(BB))
129+
if (VisitedBBs.insert(Succ).second)
130+
BBs.push_back(Succ);
134131
}
135132
}
136133

llvm/lib/Support/CommandLine.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,10 +1630,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
16301630
// otherwise feed it to the eating positional.
16311631
ArgName = StringRef(argv[i] + 1);
16321632
// Eat second dash.
1633-
if (!ArgName.empty() && ArgName[0] == '-') {
1633+
if (ArgName.consume_front("-"))
16341634
HaveDoubleDash = true;
1635-
ArgName = ArgName.substr(1);
1636-
}
16371635

16381636
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
16391637
LongOptionsUseDoubleDash, HaveDoubleDash);
@@ -1644,10 +1642,8 @@ bool CommandLineParser::ParseCommandLineOptions(int argc,
16441642
} else { // We start with a '-', must be an argument.
16451643
ArgName = StringRef(argv[i] + 1);
16461644
// Eat second dash.
1647-
if (!ArgName.empty() && ArgName[0] == '-') {
1645+
if (ArgName.consume_front("-"))
16481646
HaveDoubleDash = true;
1649-
ArgName = ArgName.substr(1);
1650-
}
16511647

16521648
Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
16531649
LongOptionsUseDoubleDash, HaveDoubleDash);

llvm/lib/Support/FormatVariadic.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ formatv_object_base::parseReplacementItem(StringRef Spec) {
7272
return ReplacementItem{};
7373
}
7474
RepString = RepString.trim();
75-
if (!RepString.empty() && RepString.front() == ',') {
76-
RepString = RepString.drop_front();
75+
if (RepString.consume_front(",")) {
7776
if (!consumeFieldLayout(RepString, Where, Align, Pad))
7877
assert(false && "Invalid replacement field layout specification!");
7978
}

0 commit comments

Comments
 (0)