Skip to content

Commit b9f2fa9

Browse files
committed
Merge from 'main' to 'sycl-web' (167 commits)
2 parents 479e133 + 898320d commit b9f2fa9

File tree

470 files changed

+34274
-16802
lines changed

Some content is hidden

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

470 files changed

+34274
-16802
lines changed

.github/workflows/libcxx-build-and-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ jobs:
185185
std_modules: 'OFF'
186186
# Use a larger machine for MSAN to avoid timeout and memory allocation issues.
187187
- config: 'generic-msan'
188-
machine: libcxx-runners-32-set
188+
machine: libcxx-runners-8-set
189189
std_modules: 'OFF'
190190
runs-on: ${{ matrix.machine }}
191191
steps:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "UnhandledSelfAssignmentCheck.h"
8484
#include "UniquePtrArrayMismatchCheck.h"
8585
#include "UnsafeFunctionsCheck.h"
86+
#include "UnusedLocalNonTrivialVariableCheck.h"
8687
#include "UnusedRaiiCheck.h"
8788
#include "UnusedReturnValueCheck.h"
8889
#include "UseAfterMoveCheck.h"
@@ -235,6 +236,8 @@ class BugproneModule : public ClangTidyModule {
235236
"bugprone-unique-ptr-array-mismatch");
236237
CheckFactories.registerCheck<UnsafeFunctionsCheck>(
237238
"bugprone-unsafe-functions");
239+
CheckFactories.registerCheck<UnusedLocalNonTrivialVariableCheck>(
240+
"bugprone-unused-local-non-trivial-variable");
238241
CheckFactories.registerCheck<UnusedRaiiCheck>("bugprone-unused-raii");
239242
CheckFactories.registerCheck<UnusedReturnValueCheck>(
240243
"bugprone-unused-return-value");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ add_clang_library(clangTidyBugproneModule
7979
UnhandledSelfAssignmentCheck.cpp
8080
UniquePtrArrayMismatchCheck.cpp
8181
UnsafeFunctionsCheck.cpp
82+
UnusedLocalNonTrivialVariableCheck.cpp
8283
UnusedRaiiCheck.cpp
8384
UnusedReturnValueCheck.cpp
8485
UseAfterMoveCheck.cpp
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//===--- UnusedLocalNonTrivialVariableCheck.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 "UnusedLocalNonTrivialVariableCheck.h"
10+
#include "../utils/Matchers.h"
11+
#include "../utils/OptionsUtils.h"
12+
#include "clang/AST/ASTContext.h"
13+
#include "clang/AST/ASTTypeTraits.h"
14+
#include "clang/AST/Type.h"
15+
#include "clang/ASTMatchers/ASTMatchFinder.h"
16+
#include "clang/ASTMatchers/ASTMatchers.h"
17+
#include "clang/ASTMatchers/ASTMatchersMacros.h"
18+
19+
using namespace clang::ast_matchers;
20+
using namespace clang::tidy::matchers;
21+
22+
namespace clang::tidy::bugprone {
23+
24+
namespace {
25+
static constexpr StringRef DefaultIncludeTypeRegex =
26+
"::std::.*mutex;::std::future;::std::basic_string;::std::basic_regex;"
27+
"::std::basic_istringstream;::std::basic_stringstream;::std::bitset;"
28+
"::std::filesystem::path";
29+
30+
AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
31+
AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
32+
AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
33+
AST_MATCHER(QualType, isTrivial) {
34+
return Node.isTrivialType(Finder->getASTContext()) ||
35+
Node.isTriviallyCopyableType(Finder->getASTContext());
36+
}
37+
} // namespace
38+
39+
UnusedLocalNonTrivialVariableCheck::UnusedLocalNonTrivialVariableCheck(
40+
StringRef Name, ClangTidyContext *Context)
41+
: ClangTidyCheck(Name, Context),
42+
IncludeTypes(utils::options::parseStringList(
43+
Options.get("IncludeTypes", DefaultIncludeTypeRegex))),
44+
ExcludeTypes(
45+
utils::options::parseStringList(Options.get("ExcludeTypes", ""))) {}
46+
47+
void UnusedLocalNonTrivialVariableCheck::storeOptions(
48+
ClangTidyOptions::OptionMap &Opts) {
49+
Options.store(Opts, "IncludeTypes",
50+
utils::options::serializeStringList(IncludeTypes));
51+
Options.store(Opts, "ExcludeTypes",
52+
utils::options::serializeStringList(ExcludeTypes));
53+
}
54+
55+
void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) {
56+
if (IncludeTypes.empty())
57+
return;
58+
59+
Finder->addMatcher(
60+
varDecl(isLocalVarDecl(), unless(isReferenced()),
61+
unless(isExceptionVariable()), hasLocalStorage(), isDefinition(),
62+
unless(hasType(isReferenceType())), unless(hasType(isTrivial())),
63+
hasType(hasUnqualifiedDesugaredType(
64+
anyOf(recordType(hasDeclaration(namedDecl(
65+
matchesAnyListedName(IncludeTypes),
66+
unless(matchesAnyListedName(ExcludeTypes))))),
67+
templateSpecializationType(hasDeclaration(namedDecl(
68+
matchesAnyListedName(IncludeTypes),
69+
unless(matchesAnyListedName(ExcludeTypes)))))))))
70+
.bind("var"),
71+
this);
72+
}
73+
74+
void UnusedLocalNonTrivialVariableCheck::check(
75+
const MatchFinder::MatchResult &Result) {
76+
const auto *MatchedDecl = Result.Nodes.getNodeAs<VarDecl>("var");
77+
diag(MatchedDecl->getLocation(), "unused local variable %0 of type %1")
78+
<< MatchedDecl << MatchedDecl->getType();
79+
}
80+
81+
bool UnusedLocalNonTrivialVariableCheck::isLanguageVersionSupported(
82+
const LangOptions &LangOpts) const {
83+
return LangOpts.CPlusPlus;
84+
}
85+
86+
std::optional<TraversalKind>
87+
UnusedLocalNonTrivialVariableCheck::getCheckTraversalKind() const {
88+
return TK_IgnoreUnlessSpelledInSource;
89+
}
90+
91+
} // namespace clang::tidy::bugprone
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===--- UnusedLocalNonTrivialVariableCheck.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_UNUSEDLOCALNONTRIVIALVARIABLECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNUSEDLOCALNONTRIVIALVARIABLECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Warns when a local non trivial variable is unused within a function. By
17+
/// default std::.*mutex and std::future are included.
18+
///
19+
/// The check supports these options:
20+
/// - 'IncludeTypes': a semicolon-separated list of regular expressions
21+
/// matching types to ensure must be used.
22+
/// - 'ExcludeTypes': a semicolon-separated list of regular expressions
23+
/// matching types that are excluded from the
24+
/// 'IncludeTypes' matches.
25+
///
26+
/// For the user-facing documentation see:
27+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.html
28+
class UnusedLocalNonTrivialVariableCheck : public ClangTidyCheck {
29+
public:
30+
UnusedLocalNonTrivialVariableCheck(StringRef Name, ClangTidyContext *Context);
31+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33+
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
34+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
35+
std::optional<TraversalKind> getCheckTraversalKind() const override;
36+
37+
private:
38+
const std::vector<StringRef> IncludeTypes;
39+
const std::vector<StringRef> ExcludeTypes;
40+
};
41+
42+
} // namespace clang::tidy::bugprone
43+
44+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNUSEDLOCALNONTRIVIALVARIABLECHECK_H

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,39 @@
1111
#include "clang/Lex/Lexer.h"
1212

1313
using namespace clang::ast_matchers;
14+
namespace {
15+
16+
AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
17+
return Node.getLanguage() == clang::LinkageSpecLanguageIDs::C;
18+
}
19+
} // namespace
1420

1521
namespace clang::tidy::modernize {
1622

23+
static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
1724
static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
1825
static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
1926
static constexpr llvm::StringLiteral TypedefName = "typedef";
2027

2128
UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
2229
: ClangTidyCheck(Name, Context),
23-
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
30+
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
31+
IgnoreExternC(Options.get("IgnoreExternC", false)) {}
2432

2533
void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
2634
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
35+
Options.store(Opts, "IgnoreExternC", IgnoreExternC);
2736
}
2837

2938
void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
30-
Finder->addMatcher(typedefDecl(unless(isInstantiated()),
31-
hasParent(decl().bind(ParentDeclName)))
32-
.bind(TypedefName),
33-
this);
39+
Finder->addMatcher(
40+
typedefDecl(
41+
unless(isInstantiated()),
42+
optionally(hasAncestor(
43+
linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
44+
hasParent(decl().bind(ParentDeclName)))
45+
.bind(TypedefName),
46+
this);
3447

3548
// This matcher is used to find tag declarations in source code within
3649
// typedefs. They appear in the AST just *prior* to the typedefs.
@@ -70,6 +83,11 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
7083
if (MatchedDecl->getLocation().isInvalid())
7184
return;
7285

86+
const auto *ExternCDecl =
87+
Result.Nodes.getNodeAs<LinkageSpecDecl>(ExternCDeclName);
88+
if (ExternCDecl && IgnoreExternC)
89+
return;
90+
7391
SourceLocation StartLoc = MatchedDecl->getBeginLoc();
7492

7593
if (StartLoc.isMacroID() && IgnoreMacros)
@@ -122,7 +140,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
122140
Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
123141
}
124142
if (!ReplaceRange.getEnd().isMacroID()) {
125-
const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : Name.size();
143+
const SourceLocation::IntTy Offset =
144+
MatchedDecl->getFunctionType() ? 0 : Name.size();
126145
LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
127146
}
128147

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace clang::tidy::modernize {
2020
class UseUsingCheck : public ClangTidyCheck {
2121

2222
const bool IgnoreMacros;
23+
const bool IgnoreExternC;
2324
SourceLocation LastReplacementEnd;
2425
llvm::DenseMap<const Decl *, SourceRange> LastTagDeclRanges;
2526

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void InefficientAlgorithmCheck::check(const MatchFinder::MatchResult &Result) {
9797
if (!AlgDecl)
9898
return;
9999

100-
if (Unordered && AlgDecl->getName().find("bound") != llvm::StringRef::npos)
100+
if (Unordered && AlgDecl->getName().contains("bound"))
101101
return;
102102

103103
const auto *AlgParam = Result.Nodes.getNodeAs<Expr>("AlgParam");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ using namespace clang::ast_matchers;
1616
namespace clang::tidy::readability {
1717

1818
static const char KDefaultTypes[] =
19-
"::std::basic_string;::std::basic_string_view;::std::vector;::std::array";
19+
"::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::"
20+
"std::span";
2021

2122
SimplifySubscriptExprCheck::SimplifySubscriptExprCheck(
2223
StringRef Name, ClangTidyContext *Context)

clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ def main():
173173
help="checks filter, when not specified, use clang-tidy " "default",
174174
default="",
175175
)
176+
parser.add_argument(
177+
"-config-file",
178+
dest="config_file",
179+
help="Specify the path of .clang-tidy or custom config file",
180+
default="",
181+
)
176182
parser.add_argument("-use-color", action="store_true", help="Use colors in output")
177183
parser.add_argument(
178184
"-path", dest="build_path", help="Path used to read a compile command database."
@@ -313,6 +319,8 @@ def main():
313319
common_clang_tidy_args.append("-fix")
314320
if args.checks != "":
315321
common_clang_tidy_args.append("-checks=" + args.checks)
322+
if args.config_file != "":
323+
common_clang_tidy_args.append("-config-file=" + args.config_file)
316324
if args.quiet:
317325
common_clang_tidy_args.append("-quiet")
318326
if args.build_path is not None:

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,22 @@ Improvements to clang-tidy
119119

120120
- Improved `--dump-config` to print check options in alphabetical order.
121121

122-
- Improved :program:`clang-tidy-diff.py` script. It now returns exit code `1`
123-
if any :program:`clang-tidy` subprocess exits with a non-zero code or if
124-
exporting fixes fails. It now accepts a directory as a value for
125-
`-export-fixes` to export individual yaml files for each compilation unit.
122+
- Improved :program:`clang-tidy-diff.py` script.
123+
* Return exit code `1` if any :program:`clang-tidy` subprocess exits with
124+
a non-zero code or if exporting fixes fails.
125+
126+
* Accept a directory as a value for `-export-fixes` to export individual
127+
yaml files for each compilation unit.
128+
129+
* Introduce a `-config-file` option that forwards a configuration file to
130+
:program:`clang-tidy`. Corresponds to the `--config-file` option in
131+
:program:`clang-tidy`.
126132

127133
- Improved :program:`run-clang-tidy.py` script. It now accepts a directory
128134
as a value for `-export-fixes` to export individual yaml files for each
129135
compilation unit.
130136

137+
131138
New checks
132139
^^^^^^^^^^
133140

@@ -168,6 +175,11 @@ New checks
168175
extracted from an optional-like type and then used to create a new instance
169176
of the same optional-like type.
170177

178+
- New :doc:`bugprone-unused-local-non-trivial-variable
179+
<clang-tidy/checks/bugprone/unused-local-non-trivial-variable>` check.
180+
181+
Warns when a local non trivial variable is unused within a function.
182+
171183
- New :doc:`cppcoreguidelines-no-suspend-with-lock
172184
<clang-tidy/checks/cppcoreguidelines/no-suspend-with-lock>` check.
173185

@@ -396,7 +408,8 @@ Changes in existing checks
396408

397409
- Improved :doc:`modernize-use-using
398410
<clang-tidy/checks/modernize/use-using>` check to fix function pointer and
399-
forward declared ``typedef`` correctly.
411+
forward declared ``typedef`` correctly. Added option `IgnoreExternC` to ignore ``typedef``
412+
declaration in ``extern "C"`` scope.
400413

401414
- Improved :doc:`performance-faster-string-find
402415
<clang-tidy/checks/performance/faster-string-find>` check to properly escape
@@ -453,6 +466,10 @@ Changes in existing checks
453466
<clang-tidy/checks/readability/non-const-parameter>` check to ignore
454467
false-positives in initializer list of record.
455468

469+
- Improved :doc:`readability-simplify-subscript-expr
470+
<clang-tidy/checks/readability/simplify-subscript-expr>` check by extending
471+
the default value of the `Types` option to include ``std::span``.
472+
456473
- Improved :doc:`readability-static-accessed-through-instance
457474
<clang-tidy/checks/readability/static-accessed-through-instance>` check to
458475
identify calls to static member functions with out-of-class inline definitions.

0 commit comments

Comments
 (0)