Skip to content

Commit b8f69ab

Browse files
author
z1_cciauto
authored
merge main into amd-staging (llvm#2346)
2 parents 920616f + 1a8e060 commit b8f69ab

File tree

115 files changed

+7418
-6749
lines changed

Some content is hidden

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

115 files changed

+7418
-6749
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void CrtpConstructorAccessibilityCheck::check(
157157
}
158158

159159
for (auto &&Ctor : CRTPDeclaration->ctors()) {
160-
if (Ctor->getAccess() == AS_private)
160+
if (Ctor->getAccess() == AS_private || Ctor->isDeleted())
161161
continue;
162162

163163
const bool IsPublic = Ctor->getAccess() == AS_public;

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "QualifiedAutoCheck.h"
1010
#include "../utils/LexerUtils.h"
11+
#include "../utils/Matchers.h"
12+
#include "../utils/OptionsUtils.h"
1113
#include "clang/ASTMatchers/ASTMatchers.h"
1214
#include "llvm/ADT/SmallVector.h"
1315
#include <optional>
@@ -100,8 +102,17 @@ bool isAutoPointerConst(QualType QType) {
100102

101103
} // namespace
102104

105+
QualifiedAutoCheck::QualifiedAutoCheck(StringRef Name,
106+
ClangTidyContext *Context)
107+
: ClangTidyCheck(Name, Context),
108+
AddConstToQualified(Options.get("AddConstToQualified", true)),
109+
AllowedTypes(
110+
utils::options::parseStringList(Options.get("AllowedTypes", ""))) {}
111+
103112
void QualifiedAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
104113
Options.store(Opts, "AddConstToQualified", AddConstToQualified);
114+
Options.store(Opts, "AllowedTypes",
115+
utils::options::serializeStringList(AllowedTypes));
105116
}
106117

107118
void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
@@ -124,20 +135,26 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
124135

125136
auto IsBoundToType = refersToType(equalsBoundNode("type"));
126137
auto UnlessFunctionType = unless(hasUnqualifiedDesugaredType(functionType()));
127-
auto IsAutoDeducedToPointer = [](const auto &...InnerMatchers) {
138+
auto IsAutoDeducedToPointer = [](const std::vector<StringRef> &AllowedTypes,
139+
const auto &...InnerMatchers) {
128140
return autoType(hasDeducedType(
129-
hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...)))));
141+
hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...))),
142+
unless(hasUnqualifiedType(
143+
matchers::matchesAnyListedTypeName(AllowedTypes, false))),
144+
unless(pointerType(pointee(hasUnqualifiedType(
145+
matchers::matchesAnyListedTypeName(AllowedTypes, false)))))));
130146
};
131147

132148
Finder->addMatcher(
133-
ExplicitSingleVarDecl(hasType(IsAutoDeducedToPointer(UnlessFunctionType)),
134-
"auto"),
149+
ExplicitSingleVarDecl(
150+
hasType(IsAutoDeducedToPointer(AllowedTypes, UnlessFunctionType)),
151+
"auto"),
135152
this);
136153

137154
Finder->addMatcher(
138155
ExplicitSingleVarDeclInTemplate(
139156
allOf(hasType(IsAutoDeducedToPointer(
140-
hasUnqualifiedType(qualType().bind("type")),
157+
AllowedTypes, hasUnqualifiedType(qualType().bind("type")),
141158
UnlessFunctionType)),
142159
anyOf(hasAncestor(
143160
functionDecl(hasAnyTemplateArgument(IsBoundToType))),

clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ namespace clang::tidy::readability {
2121
/// http://clang.llvm.org/extra/clang-tidy/checks/readability/qualified-auto.html
2222
class QualifiedAutoCheck : public ClangTidyCheck {
2323
public:
24-
QualifiedAutoCheck(StringRef Name, ClangTidyContext *Context)
25-
: ClangTidyCheck(Name, Context),
26-
AddConstToQualified(Options.get("AddConstToQualified", true)) {}
24+
QualifiedAutoCheck(StringRef Name, ClangTidyContext *Context);
2725
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
2826
return LangOpts.CPlusPlus11;
2927
}
@@ -33,6 +31,7 @@ class QualifiedAutoCheck : public ClangTidyCheck {
3331

3432
private:
3533
const bool AddConstToQualified;
34+
const std::vector<StringRef> AllowedTypes;
3635
};
3736

3837
} // namespace clang::tidy::readability

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
591591
{"save", true},
592592
}},
593593
{"documentFormattingProvider", true},
594-
{"documentRangeFormattingProvider", true},
594+
{"documentRangeFormattingProvider",
595+
llvm::json::Object{
596+
{"rangesSupport", true},
597+
}},
595598
{"documentOnTypeFormattingProvider",
596599
llvm::json::Object{
597600
{"firstTriggerCharacter", "\n"},
@@ -952,9 +955,17 @@ void ClangdLSPServer::onDocumentOnTypeFormatting(
952955
void ClangdLSPServer::onDocumentRangeFormatting(
953956
const DocumentRangeFormattingParams &Params,
954957
Callback<std::vector<TextEdit>> Reply) {
958+
onDocumentRangesFormatting(
959+
DocumentRangesFormattingParams{Params.textDocument, {Params.range}},
960+
std::move(Reply));
961+
}
962+
963+
void ClangdLSPServer::onDocumentRangesFormatting(
964+
const DocumentRangesFormattingParams &Params,
965+
Callback<std::vector<TextEdit>> Reply) {
955966
auto File = Params.textDocument.uri.file();
956967
auto Code = Server->getDraft(File);
957-
Server->formatFile(File, Params.range,
968+
Server->formatFile(File, Params.ranges,
958969
[Code = std::move(Code), Reply = std::move(Reply)](
959970
llvm::Expected<tooling::Replacements> Result) mutable {
960971
if (Result)
@@ -970,7 +981,7 @@ void ClangdLSPServer::onDocumentFormatting(
970981
auto File = Params.textDocument.uri.file();
971982
auto Code = Server->getDraft(File);
972983
Server->formatFile(File,
973-
/*Rng=*/std::nullopt,
984+
/*Rngs=*/{},
974985
[Code = std::move(Code), Reply = std::move(Reply)](
975986
llvm::Expected<tooling::Replacements> Result) mutable {
976987
if (Result)
@@ -1666,6 +1677,7 @@ void ClangdLSPServer::bindMethods(LSPBinder &Bind,
16661677
Bind.method("shutdown", this, &ClangdLSPServer::onShutdown);
16671678
Bind.method("sync", this, &ClangdLSPServer::onSync);
16681679
Bind.method("textDocument/rangeFormatting", this, &ClangdLSPServer::onDocumentRangeFormatting);
1680+
Bind.method("textDocument/rangesFormatting", this, &ClangdLSPServer::onDocumentRangesFormatting);
16691681
Bind.method("textDocument/onTypeFormatting", this, &ClangdLSPServer::onDocumentOnTypeFormatting);
16701682
Bind.method("textDocument/formatting", this, &ClangdLSPServer::onDocumentFormatting);
16711683
Bind.method("textDocument/codeAction", this, &ClangdLSPServer::onCodeAction);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
110110
Callback<std::vector<TextEdit>>);
111111
void onDocumentRangeFormatting(const DocumentRangeFormattingParams &,
112112
Callback<std::vector<TextEdit>>);
113+
void onDocumentRangesFormatting(const DocumentRangesFormattingParams &,
114+
Callback<std::vector<TextEdit>>);
113115
void onDocumentFormatting(const DocumentFormattingParams &,
114116
Callback<std::vector<TextEdit>>);
115117
// The results are serialized 'vector<DocumentSymbol>' if

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -521,29 +521,32 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
521521
std::move(Action));
522522
}
523523

524-
void ClangdServer::formatFile(PathRef File, std::optional<Range> Rng,
524+
void ClangdServer::formatFile(PathRef File, const std::vector<Range> &Rngs,
525525
Callback<tooling::Replacements> CB) {
526526
auto Code = getDraft(File);
527527
if (!Code)
528528
return CB(llvm::make_error<LSPError>("trying to format non-added document",
529529
ErrorCode::InvalidParams));
530-
tooling::Range RequestedRange;
531-
if (Rng) {
532-
llvm::Expected<size_t> Begin = positionToOffset(*Code, Rng->start);
533-
if (!Begin)
534-
return CB(Begin.takeError());
535-
llvm::Expected<size_t> End = positionToOffset(*Code, Rng->end);
536-
if (!End)
537-
return CB(End.takeError());
538-
RequestedRange = tooling::Range(*Begin, *End - *Begin);
530+
std::vector<tooling::Range> RequestedRanges;
531+
if (!Rngs.empty()) {
532+
RequestedRanges.reserve(Rngs.size());
533+
for (const auto &Rng : Rngs) {
534+
llvm::Expected<size_t> Begin = positionToOffset(*Code, Rng.start);
535+
if (!Begin)
536+
return CB(Begin.takeError());
537+
llvm::Expected<size_t> End = positionToOffset(*Code, Rng.end);
538+
if (!End)
539+
return CB(End.takeError());
540+
RequestedRanges.emplace_back(*Begin, *End - *Begin);
541+
}
539542
} else {
540-
RequestedRange = tooling::Range(0, Code->size());
543+
RequestedRanges = {tooling::Range(0, Code->size())};
541544
}
542545

543546
// Call clang-format.
544547
auto Action = [File = File.str(), Code = std::move(*Code),
545-
Ranges = std::vector<tooling::Range>{RequestedRange},
546-
CB = std::move(CB), this]() mutable {
548+
Ranges = std::move(RequestedRanges), CB = std::move(CB),
549+
this]() mutable {
547550
format::FormatStyle Style = getFormatStyleForFile(File, Code, TFS, true);
548551
tooling::Replacements IncludeReplaces =
549552
format::sortIncludes(Style, Code, Ranges, File);

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ class ClangdServer {
329329
bool AddContainer, Callback<ReferencesResult> CB);
330330

331331
/// Run formatting for the \p File with content \p Code.
332-
/// If \p Rng is non-null, formats only that region.
333-
void formatFile(PathRef File, std::optional<Range> Rng,
332+
/// If \p Rng is non-empty, formats only those regions.
333+
void formatFile(PathRef File, const std::vector<Range> &Rngs,
334334
Callback<tooling::Replacements> CB);
335335

336336
/// Run formatting after \p TriggerText was typed at \p Pos in \p File with

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,15 @@ bool fromJSON(const llvm::json::Value &Params, DocumentRangeFormattingParams &R,
672672
llvm::json::Path P) {
673673
llvm::json::ObjectMapper O(Params, P);
674674
return O && O.map("textDocument", R.textDocument) && O.map("range", R.range);
675+
;
676+
}
677+
678+
bool fromJSON(const llvm::json::Value &Params,
679+
DocumentRangesFormattingParams &R, llvm::json::Path P) {
680+
llvm::json::ObjectMapper O(Params, P);
681+
return O && O.map("textDocument", R.textDocument) &&
682+
O.map("ranges", R.ranges);
683+
;
675684
}
676685

677686
bool fromJSON(const llvm::json::Value &Params,

clang-tools-extra/clangd/Protocol.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,16 @@ struct DocumentRangeFormattingParams {
858858
bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &,
859859
llvm::json::Path);
860860

861+
struct DocumentRangesFormattingParams {
862+
/// The document to format.
863+
TextDocumentIdentifier textDocument;
864+
865+
/// The list of ranges to format
866+
std::vector<Range> ranges;
867+
};
868+
bool fromJSON(const llvm::json::Value &, DocumentRangesFormattingParams &,
869+
llvm::json::Path);
870+
861871
struct DocumentOnTypeFormattingParams {
862872
/// The document to format.
863873
TextDocumentIdentifier textDocument;

clang-tools-extra/clangd/test/formatting.test

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,65 @@
135135
# CHECK-NEXT: "jsonrpc": "2.0",
136136
# CHECK-NEXT: "result": []
137137
---
138+
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":9},"contentChanges":[{"text":"int foo( int x){\n x=x+1;\nreturn x;\n}"}]}}
139+
---
140+
{"jsonrpc":"2.0","id":5,"method":"textDocument/rangesFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"ranges":[{"start":{"line":0,"character":0},"end":{"line":0,"character":15}}, {"start":{"line":2,"character":0},"end":{"line":2,"character":5}}]}}
141+
---
142+
# CHECK: "id": 5,
143+
# CHECK-NEXT: "jsonrpc": "2.0",
144+
# CHECK-NEXT: "result": [
145+
# CHECK-NEXT: {
146+
# CHECK-NEXT: "newText": "",
147+
# CHECK-NEXT: "range": {
148+
# CHECK-NEXT: "end": {
149+
# CHECK-NEXT: "character": 10,
150+
# CHECK-NEXT: "line": 0
151+
# CHECK-NEXT: },
152+
# CHECK-NEXT: "start": {
153+
# CHECK-NEXT: "character": 8,
154+
# CHECK-NEXT: "line": 0
155+
# CHECK-NEXT: }
156+
# CHECK-NEXT: }
157+
# CHECK-NEXT: },
158+
# CHECK-NEXT: {
159+
# CHECK-NEXT: "newText": " ",
160+
# CHECK-NEXT: "range": {
161+
# CHECK-NEXT: "end": {
162+
# CHECK-NEXT: "character": 16,
163+
# CHECK-NEXT: "line": 0
164+
# CHECK-NEXT: },
165+
# CHECK-NEXT: "start": {
166+
# CHECK-NEXT: "character": 16,
167+
# CHECK-NEXT: "line": 0
168+
# CHECK-NEXT: }
169+
# CHECK-NEXT: }
170+
# CHECK-NEXT: },
171+
# CHECK-NEXT: {
172+
# CHECK-NEXT: "newText": "\n ",
173+
# CHECK-NEXT: "range": {
174+
# CHECK-NEXT: "end": {
175+
# CHECK-NEXT: "character": 0,
176+
# CHECK-NEXT: "line": 2
177+
# CHECK-NEXT: },
178+
# CHECK-NEXT: "start": {
179+
# CHECK-NEXT: "character": 8,
180+
# CHECK-NEXT: "line": 1
181+
# CHECK-NEXT: }
182+
# CHECK-NEXT: }
183+
# CHECK-NEXT: }
184+
# CHECK-NEXT: ]
185+
---
186+
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":9},"contentChanges":[{"text":"int foo(int x) {\n x=x+1;\n return x;\n}"}]}}
187+
---
188+
{"jsonrpc":"2.0","id":6,"method":"textDocument/rangesFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"ranges":[{"start":{"line":0,"character":0},"end":{"line":0,"character":15}}, {"start":{"line":2,"character":0},"end":{"line":2,"character":5}}]}}
189+
# CHECK: "id": 6,
190+
# CHECK-NEXT: "jsonrpc": "2.0",
191+
# CHECK-NEXT: "result": []
192+
---
138193
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":5},"contentChanges":[{"text":"int x=\n"}]}}
139194
---
140-
{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":1,"character":0},"ch":"\n"}}
141-
# CHECK: "id": 5,
195+
{"jsonrpc":"2.0","id":7,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":1,"character":0},"ch":"\n"}}
196+
# CHECK: "id": 7,
142197
# CHECK-NEXT: "jsonrpc": "2.0",
143198
# CHECK-NEXT: "result": [
144199
# CHECK-NEXT: {

clang-tools-extra/clangd/test/initialize-params.test

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
# CHECK-NEXT: "firstTriggerCharacter": "\n",
3636
# CHECK-NEXT: "moreTriggerCharacter": []
3737
# CHECK-NEXT: },
38-
# CHECK-NEXT: "documentRangeFormattingProvider": true,
38+
# CHECK-NEXT: "documentRangeFormattingProvider": {
39+
# CHECK-NEXT: "rangesSupport": true
40+
# CHECK-NEXT: },
3941
# CHECK-NEXT: "documentSymbolProvider": true,
4042
# CHECK-NEXT: "executeCommandProvider": {
4143
# CHECK-NEXT: "commands": [

clang-tools-extra/clangd/unittests/ClangdTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ void f() {}
944944
FS.Files[Path] = Code;
945945
runAddDocument(Server, Path, Code);
946946

947-
auto Replaces = runFormatFile(Server, Path, /*Rng=*/std::nullopt);
947+
auto Replaces = runFormatFile(Server, Path, /*Rngs=*/{});
948948
EXPECT_TRUE(static_cast<bool>(Replaces));
949949
auto Changed = tooling::applyAllReplacements(Code, *Replaces);
950950
EXPECT_TRUE(static_cast<bool>(Changed));

clang-tools-extra/clangd/unittests/SyncAPI.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,10 @@ runPrepareRename(ClangdServer &Server, PathRef File, Position Pos,
116116
}
117117

118118
llvm::Expected<tooling::Replacements>
119-
runFormatFile(ClangdServer &Server, PathRef File, std::optional<Range> Rng) {
119+
runFormatFile(ClangdServer &Server, PathRef File,
120+
const std::vector<Range> &Rngs) {
120121
std::optional<llvm::Expected<tooling::Replacements>> Result;
121-
Server.formatFile(File, Rng, capture(Result));
122+
Server.formatFile(File, Rngs, capture(Result));
122123
return std::move(*Result);
123124
}
124125

clang-tools-extra/clangd/unittests/SyncAPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ runPrepareRename(ClangdServer &Server, PathRef File, Position Pos,
5353
const clangd::RenameOptions &RenameOpts);
5454

5555
llvm::Expected<tooling::Replacements>
56-
runFormatFile(ClangdServer &Server, PathRef File, std::optional<Range>);
56+
runFormatFile(ClangdServer &Server, PathRef File, const std::vector<Range> &);
5757

5858
SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
5959
SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ New check aliases
148148
Changes in existing checks
149149
^^^^^^^^^^^^^^^^^^^^^^^^^^
150150

151+
- Improved :doc:`bugprone-crtp-constructor-accessibility
152+
<clang-tidy/checks/bugprone/crtp-constructor-accessibility>` check by fixing
153+
false positives on deleted constructors that cannot be used to construct
154+
objects, even if they have public or protected access.
155+
151156
- Improved :doc:`bugprone-optional-value-conversion
152157
<clang-tidy/checks/bugprone/optional-value-conversion>` check to detect
153158
conversion in argument of ``std::make_optional``.
@@ -234,6 +239,10 @@ Changes in existing checks
234239
tolerating fix-it breaking compilation when functions is used as pointers
235240
to avoid matching usage of functions within the current compilation unit.
236241

242+
- Improved :doc:`readability-qualified-auto
243+
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
244+
`AllowedTypes`, that excludes specified types from adding qualifiers.
245+
237246
Removed checks
238247
^^^^^^^^^^^^^^
239248

clang-tools-extra/docs/clang-tidy/checks/bugprone/crtp-constructor-accessibility.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ Example:
6565
To ensure that no accidental instantiation happens, the best practice is to
6666
make the constructor private and declare the derived class as friend. Note
6767
that as a tradeoff, this also gives the derived class access to every other
68-
private members of the CRTP.
68+
private members of the CRTP. However, constructors can still be public or
69+
protected if they are deleted.
6970

7071
Example:
7172

clang-tools-extra/docs/clang-tidy/checks/readability/qualified-auto.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,17 @@ Otherwise it will be transformed into:
8282
const auto &Foo3 = cast<const int &>(Bar3);
8383
8484
Note in the LLVM alias, the default value is `false`.
85+
86+
.. option:: AllowedTypes
87+
88+
A semicolon-separated list of names of types to ignore when ``auto`` is
89+
deduced to that type or a pointer to that type. Note that this distinguishes
90+
type aliases from the original type, so specifying e.g. ``my_int`` will not
91+
suppress reports about ``int`` even if it is defined as a ``typedef`` alias
92+
for ``int``. Regular expressions are accepted, e.g. ``[Rr]ef(erence)?$``
93+
matches every type with suffix ``Ref``, ``ref``, ``Reference`` and
94+
``reference``. If a name in the list contains the sequence `::` it is matched
95+
against the qualified type name (i.e. ``namespace::Type``), otherwise it is
96+
matched against only the type name (i.e. ``Type``). E.g. to suppress reports
97+
for ``std::array`` iterators use `std::array<.*>::(const_)?iterator` string.
98+
The default is an empty string.

0 commit comments

Comments
 (0)