Skip to content

Commit 22ee53f

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#3710)
2 parents 88034e3 + 369462c commit 22ee53f

File tree

159 files changed

+4611
-496
lines changed

Some content is hidden

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

159 files changed

+4611
-496
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ using namespace clang::ast_matchers;
1414

1515
namespace clang::tidy::cppcoreguidelines {
1616

17+
ProBoundsPointerArithmeticCheck::ProBoundsPointerArithmeticCheck(
18+
StringRef Name, ClangTidyContext *Context)
19+
: ClangTidyCheck(Name, Context),
20+
AllowIncrementDecrementOperators(
21+
Options.get("AllowIncrementDecrementOperators", false)) {}
22+
23+
void ProBoundsPointerArithmeticCheck::storeOptions(
24+
ClangTidyOptions::OptionMap &Opts) {
25+
Options.store(Opts, "AllowIncrementDecrementOperators",
26+
AllowIncrementDecrementOperators);
27+
}
28+
1729
void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
1830
const auto AllPointerTypes =
1931
anyOf(hasType(hasUnqualifiedDesugaredType(pointerType())),
@@ -30,13 +42,14 @@ void ProBoundsPointerArithmeticCheck::registerMatchers(MatchFinder *Finder) {
3042
this);
3143

3244
// Flag all operators ++, -- that result in a pointer
33-
Finder->addMatcher(
34-
unaryOperator(hasAnyOperatorName("++", "--"),
35-
hasType(hasUnqualifiedDesugaredType(pointerType())),
36-
unless(hasUnaryOperand(
37-
ignoringImpCasts(declRefExpr(to(isImplicit()))))))
38-
.bind("expr"),
39-
this);
45+
if (!AllowIncrementDecrementOperators)
46+
Finder->addMatcher(
47+
unaryOperator(hasAnyOperatorName("++", "--"),
48+
hasType(hasUnqualifiedDesugaredType(pointerType())),
49+
unless(hasUnaryOperand(
50+
ignoringImpCasts(declRefExpr(to(isImplicit()))))))
51+
.bind("expr"),
52+
this);
4053

4154
// Array subscript on a pointer (not an array) is also pointer arithmetic
4255
Finder->addMatcher(

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsPointerArithmeticCheck.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@ namespace clang::tidy::cppcoreguidelines {
2121
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.html
2222
class ProBoundsPointerArithmeticCheck : public ClangTidyCheck {
2323
public:
24-
ProBoundsPointerArithmeticCheck(StringRef Name, ClangTidyContext *Context)
25-
: ClangTidyCheck(Name, Context) {}
24+
ProBoundsPointerArithmeticCheck(StringRef Name, ClangTidyContext *Context);
2625
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2726
return LangOpts.CPlusPlus;
2827
}
2928
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
3030
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31+
32+
private:
33+
const bool AllowIncrementDecrementOperators;
3134
};
3235

3336
} // namespace clang::tidy::cppcoreguidelines

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

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

99
#include "UseConstraintsCheck.h"
1010
#include "clang/AST/ASTContext.h"
11+
#include "clang/AST/DeclTemplate.h"
1112
#include "clang/ASTMatchers/ASTMatchFinder.h"
1213
#include "clang/Lex/Lexer.h"
1314

@@ -80,6 +81,13 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
8081
if (!TD || TD->getName() != "enable_if")
8182
return std::nullopt;
8283

84+
assert(!TD->getTemplateParameters()->empty() &&
85+
"found template with no template parameters?");
86+
const auto *FirstParam = dyn_cast<NonTypeTemplateParmDecl>(
87+
TD->getTemplateParameters()->getParam(0));
88+
if (!FirstParam || !FirstParam->getType()->isBooleanType())
89+
return std::nullopt;
90+
8391
int NumArgs = SpecializationLoc.getNumArgs();
8492
if (NumArgs != 1 && NumArgs != 2)
8593
return std::nullopt;
@@ -107,6 +115,13 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
107115
if (!Specialization->isTypeAlias())
108116
return std::nullopt;
109117

118+
assert(!TD->getTemplateParameters()->empty() &&
119+
"found template with no template parameters?");
120+
const auto *FirstParam = dyn_cast<NonTypeTemplateParmDecl>(
121+
TD->getTemplateParameters()->getParam(0));
122+
if (!FirstParam || !FirstParam->getType()->isBooleanType())
123+
return std::nullopt;
124+
110125
if (const auto *AliasedType =
111126
dyn_cast<DependentNameType>(Specialization->getAliasedType())) {
112127
ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ Improvements to clang-query
104104
Improvements to clang-tidy
105105
--------------------------
106106

107+
- The :program:`check_clang_tidy.py` tool now recognizes the ``-std`` argument
108+
when run over C files. If ``-std`` is not specified, it defaults to
109+
``c99-or-later``.
110+
107111
- :program:`clang-tidy` no longer attemps to analyze code from system headers
108112
by default, greatly improving performance. This behavior is disabled if the
109113
`SystemHeaders` option is enabled.
@@ -180,9 +184,19 @@ Changes in existing checks
180184
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>` check to
181185
avoid false positives on inherited members in class templates.
182186

187+
- Improved :doc:`cppcoreguidelines-pro-bounds-pointer-arithmetic
188+
<clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic>` check
189+
adding an option to allow pointer arithmetic via prefix/postfix increment or
190+
decrement operators.
191+
183192
- Improved :doc:`misc-header-include-cycle
184193
<clang-tidy/checks/misc/header-include-cycle>` check performance.
185194

195+
- Improved :doc:`modernize-use-constraints
196+
<clang-tidy/checks/modernize/use-constraints>` check by fixing a crash on
197+
uses of non-standard ``enable_if`` with a signature different from
198+
``std::enable_if`` (such as ``boost::enable_if``).
199+
186200
- Improved :doc:`modernize-use-designated-initializers
187201
<clang-tidy/checks/modernize/use-designated-initializers>` check to
188202
suggest using designated initializers for aliased aggregate types.

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/pro-bounds-pointer-arithmetic.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ arrays of data.
1313
This rule is part of the `Bounds safety (Bounds 1)
1414
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Pro-bounds-arithmetic>`_
1515
profile from the C++ Core Guidelines.
16+
17+
Options
18+
-------
19+
20+
.. option:: AllowIncrementDecrementOperators
21+
22+
When enabled, the check will allow using the prefix/postfix increment or
23+
decrement operators on pointers. Default is ``false``.

clang-tools-extra/test/clang-tidy/check_clang_tidy.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
135135
"-fblocks",
136136
] + self.clang_extra_args
137137

138-
if extension in [".cpp", ".hpp", ".mm"]:
139-
self.clang_extra_args.append("-std=" + self.std)
138+
self.clang_extra_args.append("-std=" + self.std)
140139

141140
# Tests should not rely on STL being available, and instead provide mock
142141
# implementations of relevant APIs.
@@ -374,15 +373,23 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
374373
parser.add_argument(
375374
"-std",
376375
type=csv,
377-
default=["c++11-or-later"],
376+
default=None,
378377
help="Passed to clang. Special -or-later values are expanded.",
379378
)
380379
parser.add_argument(
381380
"--match-partial-fixes",
382381
action="store_true",
383382
help="allow partial line matches for fixes",
384383
)
385-
return parser.parse_known_args()
384+
385+
args, extra_args = parser.parse_known_args()
386+
if args.std is None:
387+
_, extension = os.path.splitext(args.assume_filename or args.input_file_name)
388+
args.std = [
389+
"c++11-or-later" if extension in [".cpp", ".hpp", ".mm"] else "c99-or-later"
390+
]
391+
392+
return (args, extra_args)
386393

387394

388395
def main() -> None:

clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/system-other.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
// Special system calls.
1313

14+
#if __STDC_VERSION__ < 202311L
1415
void other_call();
16+
#endif
1517

1618
#endif // _SYSTEM_OTHER_H_

clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry-custom-macro.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define MY_TEMP_FAILURE_RETRY(x) \
44
({ \
5-
typeof(x) __z; \
5+
__typeof__(x) __z; \
66
do \
77
__z = (x); \
88
while (__z == -1); \
@@ -11,7 +11,7 @@
1111

1212
#define MY_OTHER_TEMP_FAILURE_RETRY(x) \
1313
({ \
14-
typeof(x) __z; \
14+
__typeof__(x) __z; \
1515
do \
1616
__z = (x); \
1717
while (__z == -1); \

clang-tools-extra/test/clang-tidy/checkers/android/comparison-in-temp-failure-retry.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#define TEMP_FAILURE_RETRY(x) \
44
({ \
5-
typeof(x) __z; \
5+
__typeof__(x) __z; \
66
do \
77
__z = (x); \
88
while (__z == -1); \
@@ -130,7 +130,7 @@ void obscured_temp_failure_retry(void) {
130130
#undef TEMP_FAILURE_RETRY
131131
#define IMPL(x) \
132132
({ \
133-
typeof(x) __z; \
133+
__typeof__(x) __z; \
134134
do \
135135
__z = (x); \
136136
while (__z == -1); \

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// RUN: %check_clang_tidy %s bugprone-branch-clone %t
22
int x = 0;
33
int y = 1;
4-
#define a(b, c) \
5-
typeof(b) d; \
6-
if (b) \
7-
d = b; \
8-
else if (c) \
4+
#define a(b, c) \
5+
__typeof__(b) d; \
6+
if (b) \
7+
d = b; \
8+
else if (c) \
99
d = b;
1010

1111
void f(void) {

0 commit comments

Comments
 (0)