Skip to content

Commit 938dad3

Browse files
author
Jenkins
committed
merge main into amd-staging
Change-Id: Iee9b10f8b77db6b0f78e2adbc3e2318204ba7876
2 parents 5bd76b2 + 577e0ef commit 938dad3

File tree

204 files changed

+6586
-2367
lines changed

Some content is hidden

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

204 files changed

+6586
-2367
lines changed

clang-tools-extra/clang-tidy/google/IntegerTypesCheck.cpp

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ namespace {
4040
AST_MATCHER(FunctionDecl, isUserDefineLiteral) {
4141
return Node.getLiteralIdentifier() != nullptr;
4242
}
43+
44+
AST_MATCHER(TypeLoc, isValidAndNotInMacro) {
45+
const SourceLocation Loc = Node.getBeginLoc();
46+
return Loc.isValid() && !Loc.isMacroID();
47+
}
48+
49+
AST_MATCHER(TypeLoc, isBuiltinType) {
50+
TypeLoc TL = Node;
51+
if (auto QualLoc = Node.getAs<QualifiedTypeLoc>())
52+
TL = QualLoc.getUnqualifiedLoc();
53+
54+
const auto BuiltinLoc = TL.getAs<BuiltinTypeLoc>();
55+
if (!BuiltinLoc)
56+
return false;
57+
58+
switch (BuiltinLoc.getTypePtr()->getKind()) {
59+
case BuiltinType::Short:
60+
case BuiltinType::Long:
61+
case BuiltinType::LongLong:
62+
case BuiltinType::UShort:
63+
case BuiltinType::ULong:
64+
case BuiltinType::ULongLong:
65+
return true;
66+
default:
67+
return false;
68+
}
69+
}
70+
4371
} // namespace
4472

4573
namespace tidy::google::runtime {
@@ -63,11 +91,11 @@ void IntegerTypesCheck::registerMatchers(MatchFinder *Finder) {
6391
// "Where possible, avoid passing arguments of types specified by
6492
// bitwidth typedefs to printf-based APIs."
6593
Finder->addMatcher(
66-
typeLoc(loc(isInteger()),
67-
unless(anyOf(hasAncestor(callExpr(
68-
callee(functionDecl(hasAttr(attr::Format))))),
69-
hasParent(parmVarDecl(hasAncestor(
70-
functionDecl(isUserDefineLiteral())))))))
94+
typeLoc(loc(isInteger()), isValidAndNotInMacro(), isBuiltinType(),
95+
unless(hasAncestor(
96+
callExpr(callee(functionDecl(hasAttr(attr::Format)))))),
97+
unless(hasParent(parmVarDecl(
98+
hasAncestor(functionDecl(isUserDefineLiteral()))))))
7199
.bind("tl"),
72100
this);
73101
IdentTable = std::make_unique<IdentifierTable>(getLangOpts());
@@ -77,9 +105,6 @@ void IntegerTypesCheck::check(const MatchFinder::MatchResult &Result) {
77105
auto TL = *Result.Nodes.getNodeAs<TypeLoc>("tl");
78106
SourceLocation Loc = TL.getBeginLoc();
79107

80-
if (Loc.isInvalid() || Loc.isMacroID())
81-
return;
82-
83108
// Look through qualification.
84109
if (auto QualLoc = TL.getAs<QualifiedTypeLoc>())
85110
TL = QualLoc.getUnqualifiedLoc();

clang-tools-extra/clang-tidy/google/IntegerTypesCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class IntegerTypesCheck : public ClangTidyCheck {
3535
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3636
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3737
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
38+
std::optional<TraversalKind> getCheckTraversalKind() const override {
39+
return TK_IgnoreUnlessSpelledInSource;
40+
}
3841

3942
private:
4043
const StringRef UnsignedTypePrefix;

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "UseUsingCheck.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/DeclGroup.h"
1112
#include "clang/Lex/Lexer.h"
1213

1314
using namespace clang::ast_matchers;
@@ -24,6 +25,7 @@ static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
2425
static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
2526
static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
2627
static constexpr llvm::StringLiteral TypedefName = "typedef";
28+
static constexpr llvm::StringLiteral DeclStmtName = "decl-stmt";
2729

2830
UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
2931
: ClangTidyCheck(Name, Context),
@@ -41,7 +43,8 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
4143
unless(isInstantiated()),
4244
optionally(hasAncestor(
4345
linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
44-
hasParent(decl().bind(ParentDeclName)))
46+
anyOf(hasParent(decl().bind(ParentDeclName)),
47+
hasParent(declStmt().bind(DeclStmtName))))
4548
.bind(TypedefName),
4649
this);
4750

@@ -51,17 +54,32 @@ void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
5154
tagDecl(
5255
anyOf(allOf(unless(anyOf(isImplicit(),
5356
classTemplateSpecializationDecl())),
54-
hasParent(decl().bind(ParentDeclName))),
57+
anyOf(hasParent(decl().bind(ParentDeclName)),
58+
hasParent(declStmt().bind(DeclStmtName)))),
5559
// We want the parent of the ClassTemplateDecl, not the parent
5660
// of the specialization.
5761
classTemplateSpecializationDecl(hasAncestor(classTemplateDecl(
58-
hasParent(decl().bind(ParentDeclName)))))))
62+
anyOf(hasParent(decl().bind(ParentDeclName)),
63+
hasParent(declStmt().bind(DeclStmtName))))))))
5964
.bind(TagDeclName),
6065
this);
6166
}
6267

6368
void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
6469
const auto *ParentDecl = Result.Nodes.getNodeAs<Decl>(ParentDeclName);
70+
71+
if (!ParentDecl) {
72+
const auto *ParentDeclStmt = Result.Nodes.getNodeAs<DeclStmt>(DeclStmtName);
73+
if (ParentDeclStmt) {
74+
if (ParentDeclStmt->isSingleDecl())
75+
ParentDecl = ParentDeclStmt->getSingleDecl();
76+
else
77+
ParentDecl =
78+
ParentDeclStmt->getDeclGroup().getDeclGroup()
79+
[ParentDeclStmt->getDeclGroup().getDeclGroup().size() - 1];
80+
}
81+
}
82+
6583
if (!ParentDecl)
6684
return;
6785

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ Changes in existing checks
180180
<clang-tidy/checks/cppcoreguidelines/owning-memory>` check to properly handle
181181
return type in lambdas and in nested functions.
182182

183-
- Cleaned up :doc:`cppcoreguidelines-prefer-member-initializer
184-
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>`
183+
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
184+
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check
185185
by removing enforcement of rule `C.48
186186
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_,
187187
which was deprecated since :program:`clang-tidy` 17. This rule is now covered
188188
by :doc:`cppcoreguidelines-use-default-member-init
189-
<clang-tidy/checks/cppcoreguidelines/use-default-member-init>` and fixes
189+
<clang-tidy/checks/cppcoreguidelines/use-default-member-init>`. Fixed
190190
incorrect hints when using list-initialization.
191191

192192
- Improved :doc:`google-build-namespaces
@@ -201,6 +201,9 @@ Changes in existing checks
201201
<clang-tidy/checks/google/global-names-in-headers>` check by replacing the local
202202
option `HeaderFileExtensions` by the global option of the same name.
203203

204+
- Improved :doc:`google-runtime-int <clang-tidy/checks/google/runtime-int>`
205+
check performance through optimizations.
206+
204207
- Improved :doc:`llvm-header-guard
205208
<clang-tidy/checks/llvm/header-guard>` check by replacing the local
206209
option `HeaderFileExtensions` by the global option of the same name.
@@ -233,12 +236,20 @@ Changes in existing checks
233236
<clang-tidy/checks/modernize/use-override>` check to also remove any trailing
234237
whitespace when deleting the ``virtual`` keyword.
235238

239+
- Improved :doc:`modernize-use-using <clang-tidy/checks/modernize/use-using>`
240+
check by adding support for detection of typedefs declared on function level.
241+
236242
- Improved :doc:`performance-unnecessary-copy-initialization
237243
<clang-tidy/checks/performance/unnecessary-copy-initialization>` check by
238244
detecting more cases of constant access. In particular, pointers can be
239245
analyzed, se the check now handles the common patterns
240246
`const auto e = (*vector_ptr)[i]` and `const auto e = vector_ptr->at(i);`.
241247

248+
- Improved :doc:`readability-identifier-naming
249+
<clang-tidy/checks/readability/identifier-naming>` check in `GetConfigPerFile`
250+
mode by resolving symbolic links to header files. Fixed handling of Hungarian
251+
Prefix when configured to `LowerCase`.
252+
242253
- Improved :doc:`readability-implicit-bool-conversion
243254
<clang-tidy/checks/readability/implicit-bool-conversion>` check to provide
244255
valid fix suggestions for ``static_cast`` without a preceding space and
@@ -248,11 +259,6 @@ Changes in existing checks
248259
<clang-tidy/checks/readability/redundant-inline-specifier>` check to properly
249260
emit warnings for static data member with an in-class initializer.
250261

251-
- Improved :doc:`readability-identifier-naming
252-
<clang-tidy/checks/readability/identifier-naming>` check in `GetConfigPerFile`
253-
mode by resolving symbolic links to header files. Fixed handling of Hungarian
254-
Prefix when configured to `LowerCase`.
255-
256262
- Improved :doc:`readability-static-definition-in-anonymous-namespace
257263
<clang-tidy/checks/readability/static-definition-in-anonymous-namespace>`
258264
check by resolving fix-it overlaps in template code by disregarding implicit
@@ -267,9 +273,9 @@ Removed checks
267273
Miscellaneous
268274
^^^^^^^^^^^^^
269275

270-
- Fixed incorrect formatting in ``clang-apply-replacements`` when no ``--format``
271-
option is specified. Now ``clang-apply-replacements`` applies formatting only with
272-
the option.
276+
- Fixed incorrect formatting in :program:`clang-apply-replacements` when no
277+
``--format`` option is specified. Now :program:`clang-apply-replacements`
278+
applies formatting only with the option.
273279

274280
Improvements to include-fixer
275281
-----------------------------

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -I %S/Inputs/use-using/
1+
// RUN: %check_clang_tidy %s modernize-use-using %t -- -- -fno-delayed-template-parsing -I %S/Inputs/use-using/
22

33
typedef int Type;
44
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' [modernize-use-using]
@@ -342,3 +342,44 @@ typedef int InExternCPP;
342342
// CHECK-FIXES: using InExternCPP = int;
343343

344344
}
345+
346+
namespace ISSUE_72179
347+
{
348+
void foo()
349+
{
350+
typedef int a;
351+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
352+
// CHECK-FIXES: using a = int;
353+
354+
}
355+
356+
void foo2()
357+
{
358+
typedef struct { int a; union { int b; }; } c;
359+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
360+
// CHECK-FIXES: using c = struct { int a; union { int b; }; };
361+
}
362+
363+
template <typename T>
364+
void foo3()
365+
{
366+
typedef T b;
367+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use 'using' instead of 'typedef' [modernize-use-using]
368+
// CHECK-FIXES: using b = T;
369+
}
370+
371+
template <typename T>
372+
class MyClass
373+
{
374+
void foo()
375+
{
376+
typedef MyClass c;
377+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use 'using' instead of 'typedef' [modernize-use-using]
378+
// CHECK-FIXES: using c = MyClass;
379+
}
380+
};
381+
382+
const auto foo4 = [](int a){typedef int d;};
383+
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use 'using' instead of 'typedef' [modernize-use-using]
384+
// CHECK-FIXES: const auto foo4 = [](int a){using d = int;};
385+
}

clang/docs/LanguageExtensions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5420,10 +5420,12 @@ The following builtin intrinsics can be used in constant expressions:
54205420
* ``__builtin_clzl``
54215421
* ``__builtin_clzll``
54225422
* ``__builtin_clzs``
5423+
* ``__builtin_clzg``
54235424
* ``__builtin_ctz``
54245425
* ``__builtin_ctzl``
54255426
* ``__builtin_ctzll``
54265427
* ``__builtin_ctzs``
5428+
* ``__builtin_ctzg``
54275429
* ``__builtin_ffs``
54285430
* ``__builtin_ffsl``
54295431
* ``__builtin_ffsll``

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ Non-comprehensive list of changes in this release
193193

194194
- Lambda expressions are now accepted in C++03 mode as an extension.
195195

196+
- Added ``__builtin_clzg`` and ``__builtin_ctzg`` as type-generic alternatives
197+
to ``__builtin_clz{,s,l,ll}`` and ``__builtin_ctz{,s,l,ll}`` respectively,
198+
with support for any unsigned integer type. Like the previous builtins, these
199+
new builtins are constexpr and may be used in constant expressions.
200+
196201
New Compiler Flags
197202
------------------
198203

@@ -611,6 +616,10 @@ Sanitizers
611616
manually disable potentially noisy signed integer overflow checks with
612617
``-fno-sanitize=signed-integer-overflow``
613618

619+
- ``-fsanitize=cfi -fsanitize-cfi-cross-dso`` (cross-DSO CFI instrumentation)
620+
now generates the ``__cfi_check`` function with proper target-specific
621+
attributes, for example allowing unwind table generation.
622+
614623
Python Binding Changes
615624
----------------------
616625

0 commit comments

Comments
 (0)