Skip to content

Commit 50b7465

Browse files
committed
Merge from 'main' to 'sycl-web' (81 commits)
CONFLICT (modify/delete): clang/test/Driver/offload-target.c deleted in HEAD and modified in 34447ef. Version 34447ef of clang/test/Driver/offload-target.c left in tree.
2 parents 0bb1bbb + 34447ef commit 50b7465

File tree

1,819 files changed

+18779
-7206
lines changed

Some content is hidden

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

1,819 files changed

+18779
-7206
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ static llvm::Error parseRecord(const Record &R, unsigned ID,
384384
return decodeRecord(R, I->Path, Blob);
385385
case REFERENCE_FIELD:
386386
return decodeRecord(R, F, Blob);
387+
case REFERENCE_FILE:
388+
return decodeRecord(R, I->DocumentationFileName, Blob);
387389
default:
388390
return llvm::createStringError(llvm::inconvertibleErrorCode(),
389391
"invalid field for Reference");

clang-tools-extra/clang-doc/BitcodeWriter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ static const llvm::IndexedMap<RecordIdDsc, RecordIdToIndexFunctor>
210210
{REFERENCE_TYPE, {"RefType", &genIntAbbrev}},
211211
{REFERENCE_PATH, {"Path", &genStringAbbrev}},
212212
{REFERENCE_FIELD, {"Field", &genIntAbbrev}},
213+
{REFERENCE_FILE, {"File", &genStringAbbrev}},
213214
{TEMPLATE_PARAM_CONTENTS, {"Contents", &genStringAbbrev}},
214215
{TEMPLATE_SPECIALIZATION_OF,
215216
{"SpecializationOf", &genSymbolIdAbbrev}},
@@ -286,7 +287,7 @@ static const std::vector<std::pair<BlockId, std::vector<RecordId>>>
286287
// Reference Block
287288
{BI_REFERENCE_BLOCK_ID,
288289
{REFERENCE_USR, REFERENCE_NAME, REFERENCE_QUAL_NAME, REFERENCE_TYPE,
289-
REFERENCE_PATH, REFERENCE_FIELD}},
290+
REFERENCE_PATH, REFERENCE_FIELD, REFERENCE_FILE}},
290291
// Template Blocks.
291292
{BI_TEMPLATE_BLOCK_ID, {}},
292293
{BI_TEMPLATE_PARAM_BLOCK_ID, {TEMPLATE_PARAM_CONTENTS}},
@@ -479,6 +480,7 @@ void ClangDocBitcodeWriter::emitBlock(const Reference &R, FieldId Field) {
479480
emitRecord((unsigned)R.RefType, REFERENCE_TYPE);
480481
emitRecord(R.Path, REFERENCE_PATH);
481482
emitRecord((unsigned)Field, REFERENCE_FIELD);
483+
emitRecord(R.DocumentationFileName, REFERENCE_FILE);
482484
}
483485

484486
void ClangDocBitcodeWriter::emitBlock(const FriendInfo &R) {

clang-tools-extra/clang-doc/BitcodeWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ enum RecordId {
140140
REFERENCE_TYPE,
141141
REFERENCE_PATH,
142142
REFERENCE_FIELD,
143+
REFERENCE_FILE,
143144
TEMPLATE_PARAM_CONTENTS,
144145
TEMPLATE_SPECIALIZATION_OF,
145146
TYPEDEF_USR,

clang-tools-extra/clang-doc/JSONGenerator.cpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ static auto SerializeReferenceLambda = [](const auto &Ref, Object &Object) {
4343
serializeReference(Ref, Object);
4444
};
4545

46+
static std::string infoTypeToString(InfoType IT) {
47+
switch (IT) {
48+
case InfoType::IT_default:
49+
return "default";
50+
case InfoType::IT_namespace:
51+
return "namespace";
52+
case InfoType::IT_record:
53+
return "record";
54+
case InfoType::IT_function:
55+
return "function";
56+
case InfoType::IT_enum:
57+
return "enum";
58+
case InfoType::IT_typedef:
59+
return "typedef";
60+
case InfoType::IT_concept:
61+
return "concept";
62+
case InfoType::IT_variable:
63+
return "variable";
64+
case InfoType::IT_friend:
65+
return "friend";
66+
}
67+
llvm_unreachable("Unknown InfoType encountered.");
68+
}
69+
4670
static json::Object
4771
serializeLocation(const Location &Loc,
4872
const std::optional<StringRef> RepositoryUrl) {
@@ -172,6 +196,9 @@ serializeCommonAttributes(const Info &I, json::Object &Obj,
172196
const std::optional<StringRef> RepositoryUrl) {
173197
Obj["Name"] = I.Name;
174198
Obj["USR"] = toHex(toStringRef(I.USR));
199+
Obj["InfoType"] = infoTypeToString(I.IT);
200+
if (!I.DocumentationFileName.empty())
201+
Obj["DocumentationFileName"] = I.DocumentationFileName;
175202

176203
if (!I.Path.empty())
177204
Obj["Path"] = I.Path;
@@ -205,6 +232,8 @@ static void serializeReference(const Reference &Ref, Object &ReferenceObj) {
205232
ReferenceObj["Name"] = Ref.Name;
206233
ReferenceObj["QualName"] = Ref.QualName;
207234
ReferenceObj["USR"] = toHex(toStringRef(Ref.USR));
235+
if (!Ref.DocumentationFileName.empty())
236+
ReferenceObj["DocumentationFileName"] = Ref.DocumentationFileName;
208237
}
209238

210239
// Although namespaces and records both have ScopeChildren, they serialize them
@@ -217,14 +246,18 @@ serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj,
217246
serializeInfo(Info, Object, RepositoryUrl);
218247
};
219248

220-
if (!Children.Enums.empty())
249+
if (!Children.Enums.empty()) {
221250
serializeArray(Children.Enums, Obj, "Enums", SerializeInfo);
251+
Obj["HasEnums"] = true;
252+
}
222253

223254
if (!Children.Typedefs.empty())
224255
serializeArray(Children.Typedefs, Obj, "Typedefs", SerializeInfo);
225256

226-
if (!Children.Records.empty())
257+
if (!Children.Records.empty()) {
227258
serializeArray(Children.Records, Obj, "Records", SerializeReferenceLambda);
259+
Obj["HasRecords"] = true;
260+
}
228261
}
229262

230263
template <typename Container, typename SerializationFunc>
@@ -234,10 +267,12 @@ static void serializeArray(const Container &Records, Object &Obj,
234267
json::Value RecordsArray = Array();
235268
auto &RecordsArrayRef = *RecordsArray.getAsArray();
236269
RecordsArrayRef.reserve(Records.size());
237-
for (const auto &Item : Records) {
270+
for (size_t Index = 0; Index < Records.size(); ++Index) {
238271
json::Value ItemVal = Object();
239272
auto &ItemObj = *ItemVal.getAsObject();
240-
SerializeInfo(Item, ItemObj);
273+
SerializeInfo(Records[Index], ItemObj);
274+
if (Index == Records.size() - 1)
275+
ItemObj["End"] = true;
241276
RecordsArrayRef.push_back(ItemVal);
242277
}
243278
Obj[Key] = RecordsArray;
@@ -380,6 +415,11 @@ static void serializeInfo(const FriendInfo &I, Object &Obj) {
380415
}
381416
}
382417

418+
static void insertArray(Object &Obj, json::Value &Array, StringRef Key) {
419+
Obj[Key] = Array;
420+
Obj["Has" + Key.str()] = true;
421+
}
422+
383423
static void serializeInfo(const RecordInfo &I, json::Object &Obj,
384424
const std::optional<StringRef> &RepositoryUrl) {
385425
serializeCommonAttributes(I, Obj, RepositoryUrl);
@@ -406,7 +446,7 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
406446
}
407447

408448
if (!PubFunctionsArrayRef.empty())
409-
Obj["PublicFunctions"] = PubFunctionsArray;
449+
insertArray(Obj, PubFunctionsArray, "PublicFunctions");
410450
if (!ProtFunctionsArrayRef.empty())
411451
Obj["ProtectedFunctions"] = ProtFunctionsArray;
412452
}
@@ -430,7 +470,7 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
430470
}
431471

432472
if (!PubMembersArrayRef.empty())
433-
Obj["PublicMembers"] = PublicMembersArray;
473+
insertArray(Obj, PublicMembersArray, "PublicMembers");
434474
if (!ProtMembersArrayRef.empty())
435475
Obj["ProtectedMembers"] = ProtectedMembersArray;
436476
}
@@ -496,10 +536,7 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) {
496536
SmallString<16> FileName;
497537
if (I->IT == InfoType::IT_record) {
498538
auto *RecordSymbolInfo = static_cast<SymbolInfo *>(I);
499-
if (RecordSymbolInfo->MangledName.size() < 255)
500-
FileName = RecordSymbolInfo->MangledName;
501-
else
502-
FileName = toStringRef(toHex(RecordSymbolInfo->USR));
539+
FileName = RecordSymbolInfo->MangledName;
503540
} else if (I->IT == InfoType::IT_namespace && I->Name != "")
504541
// Serialize the global namespace as index.json
505542
FileName = I->Name;
@@ -527,7 +564,10 @@ Error JSONGenerator::generateDocs(
527564
}
528565

529566
SmallString<16> FileName = determineFileName(Info, Path);
567+
if (FileToInfos.contains(Path))
568+
continue;
530569
FileToInfos[Path].push_back(Info);
570+
Info->DocumentationFileName = FileName;
531571
}
532572

533573
for (const auto &Group : FileToInfos) {

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ void Reference::merge(Reference &&Other) {
247247
Name = Other.Name;
248248
if (Path.empty())
249249
Path = Other.Path;
250+
if (DocumentationFileName.empty())
251+
DocumentationFileName = Other.DocumentationFileName;
250252
}
251253

252254
bool FriendInfo::mergeable(const FriendInfo &Other) {

clang-tools-extra/clang-doc/Representation.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ struct Reference {
121121
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
122122
StringRef Path = StringRef())
123123
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path) {}
124+
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName,
125+
StringRef Path, SmallString<16> DocumentationFileName)
126+
: USR(USR), Name(Name), QualName(QualName), RefType(IT), Path(Path),
127+
DocumentationFileName(DocumentationFileName) {}
124128

125129
bool operator==(const Reference &Other) const {
126130
return std::tie(USR, Name, QualName, RefType) ==
@@ -155,6 +159,7 @@ struct Reference {
155159
// Path of directory where the clang-doc generated file will be saved
156160
// (possibly unresolved)
157161
llvm::SmallString<128> Path;
162+
SmallString<16> DocumentationFileName;
158163
};
159164

160165
// Holds the children of a record or namespace.
@@ -331,6 +336,11 @@ struct Info {
331336
llvm::SmallString<128> Path; // Path of directory where the clang-doc
332337
// generated file will be saved
333338

339+
// The name used for the file that this info is documented in.
340+
// In the JSON generator, infos are documented in files with mangled names.
341+
// Thus, we keep track of the physical filename for linking purposes.
342+
SmallString<16> DocumentationFileName;
343+
334344
void mergeBase(Info &&I);
335345
bool mergeable(const Info &Other);
336346

clang-tools-extra/clang-doc/Serialize.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ static void InsertChild(ScopeChildren &Scope, const NamespaceInfo &Info) {
495495

496496
static void InsertChild(ScopeChildren &Scope, const RecordInfo &Info) {
497497
Scope.Records.emplace_back(Info.USR, Info.Name, InfoType::IT_record,
498-
Info.Name, getInfoRelativePath(Info.Namespace));
498+
Info.Name, getInfoRelativePath(Info.Namespace),
499+
Info.MangledName);
499500
}
500501

501502
static void InsertChild(ScopeChildren &Scope, EnumInfo Info) {
@@ -777,7 +778,13 @@ static void populateSymbolInfo(SymbolInfo &I, const T *D, const FullComment *C,
777778
Mangler->mangleCXXVTable(CXXD, MangledStream);
778779
else
779780
MangledStream << D->getNameAsString();
780-
I.MangledName = MangledName;
781+
if (MangledName.size() > 255)
782+
// File creation fails if the mangled name is too long, so default to the
783+
// USR. We should look for a better check since filesystems differ in
784+
// maximum filename length
785+
I.MangledName = llvm::toStringRef(llvm::toHex(I.USR));
786+
else
787+
I.MangledName = MangledName;
781788
delete Mangler;
782789
}
783790

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

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "clang/Lex/Preprocessor.h"
1414
#include "llvm/Support/Regex.h"
1515
#include <algorithm>
16-
#include <deque>
1716
#include <optional>
17+
#include <vector>
1818

1919
using namespace clang::ast_matchers;
2020

@@ -23,8 +23,8 @@ namespace clang::tidy::misc {
2323
namespace {
2424

2525
struct Include {
26-
FileID Id;
27-
llvm::StringRef Name;
26+
const FileEntry *File;
27+
StringRef Name;
2828
SourceLocation Loc;
2929
};
3030

@@ -50,31 +50,27 @@ class CyclicDependencyCallbacks : public PPCallbacks {
5050
if (Reason != EnterFile && Reason != ExitFile)
5151
return;
5252

53-
FileID Id = SM.getFileID(Loc);
53+
const FileID Id = SM.getFileID(Loc);
5454
if (Id.isInvalid())
5555
return;
5656

57+
const FileEntry *NewFile = SM.getFileEntryForID(Id);
58+
const FileEntry *PrevFile = SM.getFileEntryForID(PrevFID);
59+
5760
if (Reason == ExitFile) {
58-
if ((Files.size() > 1U) && (Files.back().Id == PrevFID) &&
59-
(Files[Files.size() - 2U].Id == Id))
61+
if ((Files.size() > 1U) && (Files.back().File == PrevFile) &&
62+
(Files[Files.size() - 2U].File == NewFile))
6063
Files.pop_back();
6164
return;
6265
}
6366

64-
if (!Files.empty() && Files.back().Id == Id)
67+
if (!Files.empty() && Files.back().File == NewFile)
6568
return;
6669

67-
std::optional<llvm::StringRef> FilePath = SM.getNonBuiltinFilenameForID(Id);
68-
llvm::StringRef FileName =
69-
FilePath ? llvm::sys::path::filename(*FilePath) : llvm::StringRef();
70-
71-
if (!NextToEnter)
72-
NextToEnter = Include{Id, FileName, SourceLocation()};
73-
74-
assert(NextToEnter->Name == FileName);
75-
NextToEnter->Id = Id;
76-
Files.emplace_back(*NextToEnter);
77-
NextToEnter.reset();
70+
const std::optional<StringRef> FilePath = SM.getNonBuiltinFilenameForID(Id);
71+
const StringRef FileName =
72+
FilePath ? llvm::sys::path::filename(*FilePath) : StringRef();
73+
Files.push_back({NewFile, FileName, std::exchange(NextToEnter, {})});
7874
}
7975

8076
void InclusionDirective(SourceLocation, const Token &, StringRef FilePath,
@@ -85,36 +81,26 @@ class CyclicDependencyCallbacks : public PPCallbacks {
8581
if (FileType != clang::SrcMgr::C_User)
8682
return;
8783

88-
llvm::StringRef FileName = llvm::sys::path::filename(FilePath);
89-
NextToEnter = {FileID(), FileName, Range.getBegin()};
84+
NextToEnter = Range.getBegin();
9085

9186
if (!File)
9287
return;
9388

94-
FileID Id = SM.translateFile(*File);
95-
if (Id.isInvalid())
96-
return;
97-
98-
checkForDoubleInclude(Id, FileName, Range.getBegin());
99-
}
100-
101-
void EndOfMainFile() override {
102-
if (!Files.empty() && Files.back().Id == SM.getMainFileID())
103-
Files.pop_back();
104-
105-
assert(Files.empty());
89+
checkForDoubleInclude(&File->getFileEntry(),
90+
llvm::sys::path::filename(FilePath),
91+
Range.getBegin());
10692
}
10793

108-
void checkForDoubleInclude(FileID Id, llvm::StringRef FileName,
94+
void checkForDoubleInclude(const FileEntry *File, StringRef FileName,
10995
SourceLocation Loc) {
110-
auto It =
111-
std::find_if(Files.rbegin(), Files.rend(),
112-
[&](const Include &Entry) { return Entry.Id == Id; });
96+
const auto It =
97+
llvm::find_if(llvm::reverse(Files),
98+
[&](const Include &Entry) { return Entry.File == File; });
11399
if (It == Files.rend())
114100
return;
115101

116-
const std::optional<StringRef> FilePath = SM.getNonBuiltinFilenameForID(Id);
117-
if (!FilePath || isFileIgnored(*FilePath))
102+
const StringRef FilePath = File->tryGetRealPathName();
103+
if (FilePath.empty() || isFileIgnored(FilePath))
118104
return;
119105

120106
if (It == Files.rbegin()) {
@@ -144,9 +130,19 @@ class CyclicDependencyCallbacks : public PPCallbacks {
144130
});
145131
}
146132

133+
#ifndef NDEBUG
134+
void EndOfMainFile() override {
135+
if (!Files.empty() &&
136+
Files.back().File == SM.getFileEntryForID(SM.getMainFileID()))
137+
Files.pop_back();
138+
139+
assert(Files.empty());
140+
}
141+
#endif
142+
147143
private:
148-
std::deque<Include> Files;
149-
std::optional<Include> NextToEnter;
144+
std::vector<Include> Files;
145+
SourceLocation NextToEnter;
150146
HeaderIncludeCycleCheck &Check;
151147
const SourceManager &SM;
152148
std::vector<llvm::Regex> IgnoredFilesRegexes;

clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); }
1818

1919
void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) {
2020
Finder->addMatcher(
21-
cxxMethodDecl(ofClass(classTemplateSpecializationDecl(
21+
cxxMethodDecl(isVirtual(),
22+
ofClass(classTemplateSpecializationDecl(
2223
unless(isExplicitTemplateSpecialization()))
2324
.bind("specialization")),
24-
isVirtual(), unless(isUsed()),
25+
unless(isUsed()), unless(isPure()),
2526
unless(cxxDestructorDecl(isDefaulted())))
2627
.bind("method"),
2728
this);

0 commit comments

Comments
 (0)