Skip to content

Commit 40f90ae

Browse files
author
z1.cciauto
committed
merge main into amd-staging
2 parents 5d0726a + a0b6cfd commit 40f90ae

File tree

193 files changed

+21192
-11324
lines changed

Some content is hidden

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

193 files changed

+21192
-11324
lines changed

clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,9 @@ const HeaderMapCollector::RegexHeaderMap *getSTLPostfixHeaderMap() {
606606
{"sys/xattr.h$", "<sys/xattr.h>"},
607607
{"bits/epoll.h$", "<sys/epoll.h>"},
608608
{"bits/eventfd.h$", "<sys/eventfd.h>"},
609+
{"bits/getopt_core.h$", "<getopt.h>"},
610+
{"bits/getopt_ext.h$", "<getopt.h>"},
611+
{"bits/getopt_posix.h$", "<getopt.h>"},
609612
{"bits/inotify.h$", "<sys/inotify.h>"},
610613
{"bits/ipc.h$", "<sys/ipc.h>"},
611614
{"bits/ipctypes.h$", "<sys/ipc.h>"},

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
5959
: ClangTidyCheck(Name, Context),
6060
IgnoreHeaders(
6161
utils::options::parseStringList(Options.get("IgnoreHeaders", ""))),
62-
DeduplicateFindings(Options.get("DeduplicateFindings", true)) {
62+
DeduplicateFindings(Options.get("DeduplicateFindings", true)),
63+
UnusedIncludes(Options.get("UnusedIncludes", true)),
64+
MissingIncludes(Options.get("MissingIncludes", true)) {
6365
for (const auto &Header : IgnoreHeaders) {
6466
if (!llvm::Regex{Header}.isValid())
6567
configurationDiag("Invalid ignore headers regex '%0'") << Header;
@@ -68,12 +70,19 @@ IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
6870
HeaderSuffix += "$";
6971
IgnoreHeadersRegex.emplace_back(HeaderSuffix);
7072
}
73+
74+
if (UnusedIncludes == false && MissingIncludes == false)
75+
this->configurationDiag("The check 'misc-include-cleaner' will not "
76+
"perform any analysis because 'UnusedIncludes' and "
77+
"'MissingIncludes' are both false.");
7178
}
7279

7380
void IncludeCleanerCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7481
Options.store(Opts, "IgnoreHeaders",
7582
utils::options::serializeStringList(IgnoreHeaders));
7683
Options.store(Opts, "DeduplicateFindings", DeduplicateFindings);
84+
Options.store(Opts, "UnusedIncludes", UnusedIncludes);
85+
Options.store(Opts, "MissingIncludes", MissingIncludes);
7786
}
7887

7988
bool IncludeCleanerCheck::isLanguageVersionSupported(
@@ -200,39 +209,43 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
200209
if (!FileStyle)
201210
FileStyle = format::getLLVMStyle();
202211

203-
for (const auto *Inc : Unused) {
204-
diag(Inc->HashLocation, "included header %0 is not used directly")
205-
<< llvm::sys::path::filename(Inc->Spelled,
206-
llvm::sys::path::Style::posix)
207-
<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(
208-
SM->translateLineCol(SM->getMainFileID(), Inc->Line, 1),
209-
SM->translateLineCol(SM->getMainFileID(), Inc->Line + 1, 1)));
212+
if (UnusedIncludes) {
213+
for (const auto *Inc : Unused) {
214+
diag(Inc->HashLocation, "included header %0 is not used directly")
215+
<< llvm::sys::path::filename(Inc->Spelled,
216+
llvm::sys::path::Style::posix)
217+
<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(
218+
SM->translateLineCol(SM->getMainFileID(), Inc->Line, 1),
219+
SM->translateLineCol(SM->getMainFileID(), Inc->Line + 1, 1)));
220+
}
210221
}
211222

212-
tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
213-
FileStyle->IncludeStyle);
214-
// Deduplicate insertions when running in bulk fix mode.
215-
llvm::StringSet<> InsertedHeaders{};
216-
for (const auto &Inc : Missing) {
217-
std::string Spelling = include_cleaner::spellHeader(
218-
{Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
219-
bool Angled = llvm::StringRef{Spelling}.starts_with("<");
220-
// We might suggest insertion of an existing include in edge cases, e.g.,
221-
// include is present in a PP-disabled region, or spelling of the header
222-
// turns out to be the same as one of the unresolved includes in the
223-
// main file.
224-
if (auto Replacement =
225-
HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
226-
Angled, tooling::IncludeDirective::Include)) {
227-
DiagnosticBuilder DB =
228-
diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
229-
"no header providing \"%0\" is directly included")
230-
<< Inc.SymRef.Target.name();
231-
if (areDiagsSelfContained() ||
232-
InsertedHeaders.insert(Replacement->getReplacementText()).second) {
233-
DB << FixItHint::CreateInsertion(
234-
SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
235-
Replacement->getReplacementText());
223+
if (MissingIncludes) {
224+
tooling::HeaderIncludes HeaderIncludes(getCurrentMainFile(), Code,
225+
FileStyle->IncludeStyle);
226+
// Deduplicate insertions when running in bulk fix mode.
227+
llvm::StringSet<> InsertedHeaders{};
228+
for (const auto &Inc : Missing) {
229+
std::string Spelling = include_cleaner::spellHeader(
230+
{Inc.Missing, PP->getHeaderSearchInfo(), MainFile});
231+
bool Angled = llvm::StringRef{Spelling}.starts_with("<");
232+
// We might suggest insertion of an existing include in edge cases, e.g.,
233+
// include is present in a PP-disabled region, or spelling of the header
234+
// turns out to be the same as one of the unresolved includes in the
235+
// main file.
236+
if (auto Replacement = HeaderIncludes.insert(
237+
llvm::StringRef{Spelling}.trim("\"<>"), Angled,
238+
tooling::IncludeDirective::Include)) {
239+
DiagnosticBuilder DB =
240+
diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
241+
"no header providing \"%0\" is directly included")
242+
<< Inc.SymRef.Target.name();
243+
if (areDiagsSelfContained() ||
244+
InsertedHeaders.insert(Replacement->getReplacementText()).second) {
245+
DB << FixItHint::CreateInsertion(
246+
SM->getComposedLoc(SM->getMainFileID(), Replacement->getOffset()),
247+
Replacement->getReplacementText());
248+
}
236249
}
237250
}
238251
}

clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class IncludeCleanerCheck : public ClangTidyCheck {
4747
std::vector<StringRef> IgnoreHeaders;
4848
// Whether emit only one finding per usage of a symbol.
4949
const bool DeduplicateFindings;
50+
// Whether to report unused includes.
51+
const bool UnusedIncludes;
52+
// Whether to report missing includes.
53+
const bool MissingIncludes;
5054
llvm::SmallVector<llvm::Regex> IgnoreHeadersRegex;
5155
bool shouldIgnore(const include_cleaner::Header &H);
5256
};

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ static bool hasRValueOverload(const CXXConstructorDecl *Ctor,
166166
};
167167

168168
for (const auto *Candidate : Record->ctors()) {
169-
if (IsRValueOverload(Candidate)) {
169+
if (IsRValueOverload(Candidate))
170170
return true;
171-
}
172171
}
173172
return false;
174173
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "../ClangTidyCheck.h"
1313
#include "../utils/IncludeInserter.h"
1414

15-
#include <memory>
16-
1715
namespace clang::tidy::modernize {
1816

1917
class PassByValueCheck : public ClangTidyCheck {

clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,9 @@ const std::pair<llvm::StringRef, llvm::StringRef> IncludeMappings[] = {
621621
{"sys/xattr.h", "<sys/xattr.h>"},
622622
{"bits/epoll.h", "<sys/epoll.h>"},
623623
{"bits/eventfd.h", "<sys/eventfd.h>"},
624+
{"bits/getopt_core.h", "<getopt.h>"},
625+
{"bits/getopt_ext.h", "<getopt.h>"},
626+
{"bits/getopt_posix.h", "<getopt.h>"},
624627
{"bits/inotify.h", "<sys/inotify.h>"},
625628
{"bits/ipc.h", "<sys/ipc.h>"},
626629
{"bits/ipctypes.h", "<sys/ipc.h>"},

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ Changes in existing checks
184184
`AnalyzePointers` option and fixing false positives when using const array
185185
type.
186186

187+
- Improved :doc:`misc-include-cleaner
188+
<clang-tidy/checks/misc/include-cleaner>` check by adding the options
189+
`UnusedIncludes` and `MissingIncludes`, which specify whether the check should
190+
report unused or missing includes respectively.
191+
187192
- Improved :doc:`misc-redundant-expression
188193
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
189194
examples and fixing some macro related false positives.
@@ -208,7 +213,7 @@ Changes in existing checks
208213
diagnosing designated initializers for ``std::array`` initializations.
209214

210215
- Improved :doc:`modernize-use-ranges
211-
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress
216+
<clang-tidy/checks/modernize/use-ranges>` check by updating suppress
212217
warnings logic for ``nullptr`` in ``std::find``.
213218

214219
- Improved :doc:`modernize-use-starts-ends-with

clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ Options
3838

3939
A boolean that controls whether the check should deduplicate findings for the
4040
same symbol. Defaults to `true`.
41+
42+
.. option:: UnusedIncludes
43+
44+
A boolean that controls whether the check should report unused includes
45+
(includes that are not used directly). Defaults to `true`.
46+
47+
.. option:: MissingIncludes
48+
49+
A boolean that controls whether the check should report missing includes
50+
(header files from which symbols are used but which are not directly included).
51+
Defaults to `true`.

clang-tools-extra/include-cleaner/lib/WalkAST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class ASTWalker : public RecursiveASTVisitor<ASTWalker> {
322322
}
323323

324324
bool VisitCleanupAttr(CleanupAttr *attr) {
325-
report(attr->getLocation(), attr->getFunctionDecl());
325+
report(attr->getArgLoc(), attr->getFunctionDecl());
326326
return true;
327327
}
328328

clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ TEST(WalkAST, OperatorNewDelete) {
573573

574574
TEST(WalkAST, CleanupAttr) {
575575
testWalk("void* $explicit^freep(void *p);",
576-
"void foo() { __attribute__((^__cleanup__(freep))) char* x = 0; }");
576+
"void foo() { __attribute__((__cleanup__(^freep))) char* x = 0; }");
577577
}
578578

579579
} // namespace

0 commit comments

Comments
 (0)