Skip to content

Commit 2e95c33

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:e45fc5140df7bb60242a989ac7fc5cd0c0563234 into amd-gfx:ba271becfbe2
Local branch amd-gfx ba271be Merged main:b44da2446b17aaa847bf76f81a01870917f8736b into amd-gfx:b625170ac5f7 Remote branch main e45fc51 [Linalg][Vectorization] Add support for linalg vectorization of a tensor.extract case (llvm#107922)
2 parents ba271be + e45fc51 commit 2e95c33

File tree

204 files changed

+4789
-2666
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

+4789
-2666
lines changed

clang-tools-extra/clang-query/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
146146
TD.emitDiagnostic(
147147
FullSourceLoc(R.getBegin(), AST->getSourceManager()),
148148
DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
149-
CharSourceRange::getTokenRange(R), std::nullopt);
149+
CharSourceRange::getTokenRange(R), {});
150150
}
151151
}
152152
if (QS.PrintOutput) {

clang-tools-extra/clangd/index/Symbol.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ struct Symbol {
145145
ImplementationDetail = 1 << 2,
146146
/// Symbol is visible to other files (not e.g. a static helper function).
147147
VisibleOutsideFile = 1 << 3,
148+
/// Symbol has an attached documentation comment.
149+
HasDocComment = 1 << 4
148150
};
149-
150151
SymbolFlag Flags = SymbolFlag::None;
152+
151153
/// FIXME: also add deprecation message and fixit?
152154
};
153155

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -635,17 +635,21 @@ bool SymbolCollector::handleDeclOccurrence(
635635
return true;
636636

637637
const Symbol *BasicSymbol = Symbols.find(ID);
638-
if (isPreferredDeclaration(*OriginalDecl, Roles))
638+
bool SkipDocCheckInDef = false;
639+
if (isPreferredDeclaration(*OriginalDecl, Roles)) {
639640
// If OriginalDecl is preferred, replace/create the existing canonical
640641
// declaration (e.g. a class forward declaration). There should be at most
641642
// one duplicate as we expect to see only one preferred declaration per
642643
// TU, because in practice they are definitions.
643644
BasicSymbol = addDeclaration(*OriginalDecl, std::move(ID), IsMainFileOnly);
644-
else if (!BasicSymbol || DeclIsCanonical)
645+
SkipDocCheckInDef = true;
646+
} else if (!BasicSymbol || DeclIsCanonical) {
645647
BasicSymbol = addDeclaration(*ND, std::move(ID), IsMainFileOnly);
648+
SkipDocCheckInDef = true;
649+
}
646650

647651
if (Roles & static_cast<unsigned>(index::SymbolRole::Definition))
648-
addDefinition(*OriginalDecl, *BasicSymbol);
652+
addDefinition(*OriginalDecl, *BasicSymbol, SkipDocCheckInDef);
649653

650654
return true;
651655
}
@@ -1025,16 +1029,28 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
10251029
*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
10261030
*CompletionTUInfo,
10271031
/*IncludeBriefComments*/ false);
1028-
std::string Documentation =
1029-
formatDocumentation(*CCS, getDocComment(Ctx, SymbolCompletion,
1030-
/*CommentsFromHeaders=*/true));
1032+
std::string DocComment;
1033+
std::string Documentation;
1034+
bool AlreadyHasDoc = S.Flags & Symbol::HasDocComment;
1035+
if (!AlreadyHasDoc) {
1036+
DocComment = getDocComment(Ctx, SymbolCompletion,
1037+
/*CommentsFromHeaders=*/true);
1038+
Documentation = formatDocumentation(*CCS, DocComment);
1039+
}
1040+
const auto UpdateDoc = [&] {
1041+
if (!AlreadyHasDoc) {
1042+
if (!DocComment.empty())
1043+
S.Flags |= Symbol::HasDocComment;
1044+
S.Documentation = Documentation;
1045+
}
1046+
};
10311047
if (!(S.Flags & Symbol::IndexedForCodeCompletion)) {
10321048
if (Opts.StoreAllDocumentation)
1033-
S.Documentation = Documentation;
1049+
UpdateDoc();
10341050
Symbols.insert(S);
10351051
return Symbols.find(S.ID);
10361052
}
1037-
S.Documentation = Documentation;
1053+
UpdateDoc();
10381054
std::string Signature;
10391055
std::string SnippetSuffix;
10401056
getSignature(*CCS, &Signature, &SnippetSuffix, SymbolCompletion.Kind,
@@ -1058,8 +1074,8 @@ const Symbol *SymbolCollector::addDeclaration(const NamedDecl &ND, SymbolID ID,
10581074
return Symbols.find(S.ID);
10591075
}
10601076

1061-
void SymbolCollector::addDefinition(const NamedDecl &ND,
1062-
const Symbol &DeclSym) {
1077+
void SymbolCollector::addDefinition(const NamedDecl &ND, const Symbol &DeclSym,
1078+
bool SkipDocCheck) {
10631079
if (DeclSym.Definition)
10641080
return;
10651081
const auto &SM = ND.getASTContext().getSourceManager();
@@ -1074,6 +1090,27 @@ void SymbolCollector::addDefinition(const NamedDecl &ND,
10741090
Symbol S = DeclSym;
10751091
// FIXME: use the result to filter out symbols.
10761092
S.Definition = *DefLoc;
1093+
1094+
std::string DocComment;
1095+
std::string Documentation;
1096+
if (!SkipDocCheck && !(S.Flags & Symbol::HasDocComment) &&
1097+
(llvm::isa<FunctionDecl>(ND) || llvm::isa<CXXMethodDecl>(ND))) {
1098+
CodeCompletionResult SymbolCompletion(&getTemplateOrThis(ND), 0);
1099+
const auto *CCS = SymbolCompletion.CreateCodeCompletionString(
1100+
*ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
1101+
*CompletionTUInfo,
1102+
/*IncludeBriefComments*/ false);
1103+
DocComment = getDocComment(ND.getASTContext(), SymbolCompletion,
1104+
/*CommentsFromHeaders=*/true);
1105+
if (!S.Documentation.empty())
1106+
Documentation = S.Documentation.str() + '\n' + DocComment;
1107+
else
1108+
Documentation = formatDocumentation(*CCS, DocComment);
1109+
if (!DocComment.empty())
1110+
S.Flags |= Symbol::HasDocComment;
1111+
S.Documentation = Documentation;
1112+
}
1113+
10771114
Symbols.insert(S);
10781115
}
10791116

clang-tools-extra/clangd/index/SymbolCollector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class SymbolCollector : public index::IndexDataConsumer {
161161
private:
162162
const Symbol *addDeclaration(const NamedDecl &, SymbolID,
163163
bool IsMainFileSymbol);
164-
void addDefinition(const NamedDecl &, const Symbol &DeclSymbol);
164+
void addDefinition(const NamedDecl &, const Symbol &DeclSymbol,
165+
bool SkipDocCheck);
165166
void processRelations(const NamedDecl &ND, const SymbolID &ID,
166167
ArrayRef<index::SymbolRelation> Relations);
167168

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,58 @@ TEST_F(SymbolCollectorTest, Documentation) {
14771477
forCodeCompletion(false))));
14781478
}
14791479

1480+
TEST_F(SymbolCollectorTest, DocumentationInMain) {
1481+
const std::string Header = R"(
1482+
// doc Foo
1483+
class Foo {
1484+
void f();
1485+
};
1486+
)";
1487+
const std::string Main = R"(
1488+
// doc f
1489+
void Foo::f() {}
1490+
)";
1491+
CollectorOpts.StoreAllDocumentation = true;
1492+
runSymbolCollector(Header, Main);
1493+
EXPECT_THAT(Symbols,
1494+
UnorderedElementsAre(
1495+
AllOf(qName("Foo"), doc("doc Foo"), forCodeCompletion(true)),
1496+
AllOf(qName("Foo::f"), doc("doc f"), returnType(""),
1497+
forCodeCompletion(false))));
1498+
}
1499+
1500+
TEST_F(SymbolCollectorTest, DocumentationAtDeclThenDef) {
1501+
const std::string Header = R"(
1502+
class Foo {
1503+
// doc f decl
1504+
void f();
1505+
};
1506+
)";
1507+
const std::string Main = R"(
1508+
// doc f def
1509+
void Foo::f() {}
1510+
)";
1511+
CollectorOpts.StoreAllDocumentation = true;
1512+
runSymbolCollector(Header, Main);
1513+
EXPECT_THAT(Symbols,
1514+
UnorderedElementsAre(AllOf(qName("Foo")),
1515+
AllOf(qName("Foo::f"), doc("doc f decl"))));
1516+
}
1517+
1518+
TEST_F(SymbolCollectorTest, DocumentationAtDefThenDecl) {
1519+
const std::string Header = R"(
1520+
// doc f def
1521+
void f() {}
1522+
1523+
// doc f decl
1524+
void f();
1525+
)";
1526+
CollectorOpts.StoreAllDocumentation = true;
1527+
runSymbolCollector(Header, "" /*Main*/);
1528+
EXPECT_THAT(Symbols,
1529+
UnorderedElementsAre(AllOf(qName("f"), doc("doc f def"))));
1530+
}
1531+
14801532
TEST_F(SymbolCollectorTest, ClassMembers) {
14811533
const std::string Header = R"(
14821534
class Foo {

clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ template <typename... CheckTypes>
8686
std::string
8787
runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
8888
const Twine &Filename = "input.cc",
89-
ArrayRef<std::string> ExtraArgs = std::nullopt,
89+
ArrayRef<std::string> ExtraArgs = {},
9090
const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
9191
std::map<StringRef, StringRef> PathsToContent =
9292
std::map<StringRef, StringRef>()) {

clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
4949
std::vector<ClangTidyError> Errors;
5050
EXPECT_EQ(PostCode,
5151
runCheckOnCode<IncludeCleanerCheck>(
52-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
52+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
5353
{{"bar.h", "#pragma once"}, {"vector", "#pragma once"}}));
5454
}
5555

@@ -78,7 +78,7 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
7878
EXPECT_EQ(
7979
PostCode,
8080
runCheckOnCode<IncludeCleanerCheck>(
81-
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
81+
PreCode, &Errors, "file.cpp", {}, Opts,
8282
{{"bar.h", "#pragma once"},
8383
{"vector", "#pragma once"},
8484
{"list", "#pragma once"},
@@ -103,14 +103,13 @@ int BazResult = baz();
103103
)";
104104

105105
std::vector<ClangTidyError> Errors;
106-
EXPECT_EQ(PostCode,
107-
runCheckOnCode<IncludeCleanerCheck>(
108-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
109-
{{"bar.h", R"(#pragma once
106+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
107+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
108+
{{"bar.h", R"(#pragma once
110109
#include "baz.h"
111110
int bar();
112111
)"},
113-
{"baz.h", R"(#pragma once
112+
{"baz.h", R"(#pragma once
114113
int baz();
115114
)"}}));
116115
}
@@ -124,8 +123,8 @@ int BarResult2 = $diag2^bar();)");
124123

125124
{
126125
std::vector<ClangTidyError> Errors;
127-
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
128-
std::nullopt, ClangTidyOptions(),
126+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp", {},
127+
ClangTidyOptions(),
129128
{{"baz.h", R"(#pragma once
130129
#include "bar.h"
131130
)"},
@@ -141,8 +140,8 @@ int BarResult2 = $diag2^bar();)");
141140
std::vector<ClangTidyError> Errors;
142141
ClangTidyOptions Opts;
143142
Opts.CheckOptions.insert({"DeduplicateFindings", "false"});
144-
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp",
145-
std::nullopt, Opts,
143+
runCheckOnCode<IncludeCleanerCheck>(Code.code(), &Errors, "file.cpp", {},
144+
Opts,
146145
{{"baz.h", R"(#pragma once
147146
#include "bar.h"
148147
)"},
@@ -176,7 +175,7 @@ std::vector x;
176175
llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"}))};
177176
std::vector<ClangTidyError> Errors;
178177
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
179-
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
178+
PreCode, &Errors, "file.cpp", {}, Opts,
180179
{{"bar.h", R"(#pragma once
181180
#include "baz.h"
182181
#include "foo/qux.h"
@@ -215,14 +214,13 @@ int BazResult_1 = baz_1();
215214
)";
216215

217216
std::vector<ClangTidyError> Errors;
218-
EXPECT_EQ(PostCode,
219-
runCheckOnCode<IncludeCleanerCheck>(
220-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
221-
{{"bar.h", R"(#pragma once
217+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
218+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
219+
{{"bar.h", R"(#pragma once
222220
#include "baz.h"
223221
int bar();
224222
)"},
225-
{"baz.h", R"(#pragma once
223+
{"baz.h", R"(#pragma once
226224
int baz_0();
227225
int baz_1();
228226
)"}}));
@@ -244,13 +242,12 @@ std::vector Vec;
244242
)";
245243

246244
std::vector<ClangTidyError> Errors;
247-
EXPECT_EQ(PostCode,
248-
runCheckOnCode<IncludeCleanerCheck>(
249-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
250-
{{"string", R"(#pragma once
245+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
246+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
247+
{{"string", R"(#pragma once
251248
namespace std { class string {}; }
252249
)"},
253-
{"vector", R"(#pragma once
250+
{"vector", R"(#pragma once
254251
#include <string>
255252
namespace std { class vector {}; }
256253
)"}}));
@@ -272,14 +269,13 @@ int FooBarResult = foobar();
272269
)";
273270

274271
std::vector<ClangTidyError> Errors;
275-
EXPECT_EQ(PostCode,
276-
runCheckOnCode<IncludeCleanerCheck>(
277-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
278-
{{"bar.h", R"(#pragma once
272+
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
273+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
274+
{{"bar.h", R"(#pragma once
279275
#include "private.h"
280276
int bar();
281277
)"},
282-
{"private.h", R"(#pragma once
278+
{"private.h", R"(#pragma once
283279
// IWYU pragma: private, include "public.h"
284280
int foobar();
285281
)"}}));
@@ -295,11 +291,10 @@ DECLARE(myfunc) {
295291
)";
296292

297293
std::vector<ClangTidyError> Errors;
298-
EXPECT_EQ(PreCode,
299-
runCheckOnCode<IncludeCleanerCheck>(
300-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
301-
{{"foo.h",
302-
R"(#pragma once
294+
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
295+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
296+
{{"foo.h",
297+
R"(#pragma once
303298
#define DECLARE(X) void X()
304299
)"}}));
305300

@@ -311,11 +306,10 @@ DECLARE {
311306
}
312307
)";
313308

314-
EXPECT_EQ(PreCode,
315-
runCheckOnCode<IncludeCleanerCheck>(
316-
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
317-
{{"foo.h",
318-
R"(#pragma once
309+
EXPECT_EQ(PreCode, runCheckOnCode<IncludeCleanerCheck>(
310+
PreCode, &Errors, "file.cpp", {}, ClangTidyOptions(),
311+
{{"foo.h",
312+
R"(#pragma once
319313
#define DECLARE void myfunc()
320314
)"}}));
321315
}

clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class ObjCGeneratedHeaderInserterCheck : public IncludeInserterCheckBase {
167167
template <typename Check>
168168
std::string runCheckOnCode(StringRef Code, StringRef Filename) {
169169
std::vector<ClangTidyError> Errors;
170-
return test::runCheckOnCode<Check>(Code, &Errors, Filename, std::nullopt,
170+
return test::runCheckOnCode<Check>(Code, &Errors, Filename, {},
171171
ClangTidyOptions(),
172172
{// Main file include
173173
{"clang_tidy/tests/"

clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ std::string runChecker(StringRef Code, unsigned ExpectedWarningCount) {
5656
"}"}};
5757
std::vector<ClangTidyError> errors;
5858

59-
std::string result =
60-
test::runCheckOnCode<Check>(Code, &errors, "foo.cc", std::nullopt,
61-
ClangTidyOptions(), AdditionalFileContents);
59+
std::string result = test::runCheckOnCode<Check>(
60+
Code, &errors, "foo.cc", {}, ClangTidyOptions(), AdditionalFileContents);
6261

6362
EXPECT_EQ(ExpectedWarningCount, errors.size());
6463
return result;

0 commit comments

Comments
 (0)