Skip to content

Commit 2074f32

Browse files
author
Jenkins
committed
merge main into amd-stg-open
Change-Id: I3c8e3576cef0a1cbf77bc7e76c0af527938128de
2 parents 5f21bf5 + 89bacc0 commit 2074f32

File tree

35 files changed

+377
-90
lines changed

35 files changed

+377
-90
lines changed

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ std::string IncludeFixerSemaSource::minimizeInclude(
307307

308308
// Get the FileEntry for the include.
309309
StringRef StrippedInclude = Include.trim("\"<>");
310-
auto Entry = SourceManager.getFileManager().getFile(StrippedInclude);
310+
auto Entry =
311+
SourceManager.getFileManager().getOptionalFileRef(StrippedInclude);
311312

312313
// If the file doesn't exist return the path from the database.
313314
// FIXME: This should never happen.

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ class HeaderSearch {
316316
std::unique_ptr<IncludeAliasMap> IncludeAliases;
317317

318318
/// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
319-
std::vector<std::pair<const FileEntry *, std::unique_ptr<HeaderMap>>> HeaderMaps;
319+
std::vector<std::pair<FileEntryRef, std::unique_ptr<HeaderMap>>> HeaderMaps;
320320

321321
/// The mapping between modules and headers.
322322
mutable ModuleMap ModMap;
@@ -501,7 +501,7 @@ class HeaderSearch {
501501
/// HIToolbox is a subframework within Carbon.framework. If so, return
502502
/// the FileEntry for the designated file, otherwise return null.
503503
OptionalFileEntryRef LookupSubframeworkHeader(
504-
StringRef Filename, const FileEntry *ContextFileEnt,
504+
StringRef Filename, FileEntryRef ContextFileEnt,
505505
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
506506
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule);
507507

@@ -573,7 +573,7 @@ class HeaderSearch {
573573

574574
/// This method returns a HeaderMap for the specified
575575
/// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
576-
const HeaderMap *CreateHeaderMap(const FileEntry *FE);
576+
const HeaderMap *CreateHeaderMap(FileEntryRef FE);
577577

578578
/// Get filenames for all registered header maps.
579579
void getHeaderMapFileNames(SmallVectorImpl<std::string> &Names) const;
@@ -870,7 +870,7 @@ class HeaderSearch {
870870
///
871871
/// \param IsAngled If non-null, filled in to indicate whether the suggested
872872
/// path should be referenced as <Header.h> instead of "Header.h".
873-
std::string suggestPathToFileForDiagnostics(const FileEntry *File,
873+
std::string suggestPathToFileForDiagnostics(FileEntryRef File,
874874
llvm::StringRef MainFile,
875875
bool *IsAngled = nullptr) const;
876876

clang/include/clang/Lex/ModuleMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class ModuleMapCallbacks {
5757
/// contents.
5858
/// \param File The file itself.
5959
/// \param IsSystem Whether this is a module map from a system include path.
60-
virtual void moduleMapFileRead(SourceLocation FileStart,
61-
const FileEntry &File, bool IsSystem) {}
60+
virtual void moduleMapFileRead(SourceLocation FileStart, FileEntryRef File,
61+
bool IsSystem) {}
6262

6363
/// Called when a header is added during module map parsing.
6464
///

clang/include/clang/Lex/Preprocessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,8 +2718,8 @@ class Preprocessor {
27182718
/// \return A file that can be #included to provide the desired effect. Null
27192719
/// if no such file could be determined or if a #include is not
27202720
/// appropriate (eg, if a module should be imported instead).
2721-
const FileEntry *getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
2722-
SourceLocation MLoc);
2721+
OptionalFileEntryRef getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
2722+
SourceLocation MLoc);
27232723

27242724
bool isRecordingPreamble() const {
27252725
return PreambleConditionalStack.isRecording();

clang/lib/Basic/Sarif.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ using namespace llvm;
3636
using clang::detail::SarifArtifact;
3737
using clang::detail::SarifArtifactLocation;
3838

39-
static StringRef getFileName(const FileEntry &FE) {
40-
StringRef Filename = FE.tryGetRealPathName();
39+
static StringRef getFileName(FileEntryRef FE) {
40+
StringRef Filename = FE.getFileEntry().tryGetRealPathName();
4141
if (Filename.empty())
4242
Filename = FE.getName();
4343
return Filename;
@@ -215,8 +215,8 @@ SarifDocumentWriter::createPhysicalLocation(const CharSourceRange &R) {
215215
assert(R.isCharRange() &&
216216
"Cannot create a physicalLocation from a token range!");
217217
FullSourceLoc Start{R.getBegin(), SourceMgr};
218-
const FileEntry *FE = Start.getExpansionLoc().getFileEntry();
219-
assert(FE != nullptr && "Diagnostic does not exist within a valid file!");
218+
OptionalFileEntryRef FE = Start.getExpansionLoc().getFileEntryRef();
219+
assert(FE && "Diagnostic does not exist within a valid file!");
220220

221221
const std::string &FileURI = fileNameToURI(getFileName(*FE));
222222
auto I = CurrentArtifacts.find(FileURI);

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8423,7 +8423,8 @@ void CodeGenFunction::EmitSimpleOMPExecutableDirective(
84238423
D.getDirectiveKind() == OMPD_critical ||
84248424
D.getDirectiveKind() == OMPD_section ||
84258425
D.getDirectiveKind() == OMPD_master ||
8426-
D.getDirectiveKind() == OMPD_masked) {
8426+
D.getDirectiveKind() == OMPD_masked ||
8427+
D.getDirectiveKind() == OMPD_unroll) {
84278428
EmitStmt(D.getAssociatedStmt());
84288429
} else {
84298430
auto LPCRegion =

clang/lib/Frontend/DependencyFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct DepCollectorMMCallbacks : public ModuleMapCallbacks {
105105
DependencyCollector &DepCollector;
106106
DepCollectorMMCallbacks(DependencyCollector &DC) : DepCollector(DC) {}
107107

108-
void moduleMapFileRead(SourceLocation Loc, const FileEntry &Entry,
108+
void moduleMapFileRead(SourceLocation Loc, FileEntryRef Entry,
109109
bool IsSystem) override {
110110
StringRef Filename = Entry.getName();
111111
DepCollector.maybeAddDependency(Filename,

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ std::vector<bool> HeaderSearch::computeUserEntryUsage() const {
144144

145145
/// CreateHeaderMap - This method returns a HeaderMap for the specified
146146
/// FileEntry, uniquing them through the 'HeaderMaps' datastructure.
147-
const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) {
147+
const HeaderMap *HeaderSearch::CreateHeaderMap(FileEntryRef FE) {
148148
// We expect the number of headermaps to be small, and almost always empty.
149149
// If it ever grows, use of a linear search should be re-evaluated.
150150
if (!HeaderMaps.empty()) {
@@ -167,7 +167,7 @@ const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) {
167167
void HeaderSearch::getHeaderMapFileNames(
168168
SmallVectorImpl<std::string> &Names) const {
169169
for (auto &HM : HeaderMaps)
170-
Names.push_back(std::string(HM.first->getName()));
170+
Names.push_back(std::string(HM.first.getName()));
171171
}
172172

173173
std::string HeaderSearch::getCachedModuleFileName(Module *Module) {
@@ -1178,19 +1178,17 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
11781178
/// is a subframework within Carbon.framework. If so, return the FileEntry
11791179
/// for the designated file, otherwise return null.
11801180
OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader(
1181-
StringRef Filename, const FileEntry *ContextFileEnt,
1181+
StringRef Filename, FileEntryRef ContextFileEnt,
11821182
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
11831183
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) {
1184-
assert(ContextFileEnt && "No context file?");
1185-
11861184
// Framework names must have a '/' in the filename. Find it.
11871185
// FIXME: Should we permit '\' on Windows?
11881186
size_t SlashPos = Filename.find('/');
11891187
if (SlashPos == StringRef::npos)
11901188
return std::nullopt;
11911189

11921190
// Look up the base framework name of the ContextFileEnt.
1193-
StringRef ContextName = ContextFileEnt->getName();
1191+
StringRef ContextName = ContextFileEnt.getName();
11941192

11951193
// If the context info wasn't a framework, couldn't be a subframework.
11961194
const unsigned DotFrameworkLen = 10;
@@ -1923,11 +1921,8 @@ void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {
19231921
}
19241922

19251923
std::string HeaderSearch::suggestPathToFileForDiagnostics(
1926-
const FileEntry *File, llvm::StringRef MainFile, bool *IsAngled) const {
1927-
// FIXME: We assume that the path name currently cached in the FileEntry is
1928-
// the most appropriate one for this analysis (and that it's spelled the
1929-
// same way as the corresponding header search path).
1930-
return suggestPathToFileForDiagnostics(File->getName(), /*WorkingDir=*/"",
1924+
FileEntryRef File, llvm::StringRef MainFile, bool *IsAngled) const {
1925+
return suggestPathToFileForDiagnostics(File.getName(), /*WorkingDir=*/"",
19311926
MainFile, IsAngled);
19321927
}
19331928

clang/lib/Lex/InitHeaderSearch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
167167
// Check to see if this is an apple-style headermap (which are not allowed to
168168
// be frameworks).
169169
if (!isFramework) {
170-
if (auto FE = FM.getFile(MappedPathStr)) {
170+
if (auto FE = FM.getOptionalFileRef(MappedPathStr)) {
171171
if (const HeaderMap *HM = Headers.CreateHeaderMap(*FE)) {
172172
// It is a headermap, add it to the search path.
173173
IncludePath.emplace_back(

clang/lib/Lex/ModuleMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,7 @@ bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
31203120

31213121
// Notify callbacks that we parsed it.
31223122
for (const auto &Cb : Callbacks)
3123-
Cb->moduleMapFileRead(Start, *File, IsSystem);
3123+
Cb->moduleMapFileRead(Start, File, IsSystem);
31243124

31253125
return Result;
31263126
}

clang/lib/Lex/PPDirectives.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ Module *Preprocessor::getModuleForLocation(SourceLocation Loc,
874874
: HeaderInfo.lookupModule(getLangOpts().CurrentModule, Loc);
875875
}
876876

877-
const FileEntry *
877+
OptionalFileEntryRef
878878
Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
879879
SourceLocation Loc) {
880880
Module *IncM = getModuleForLocation(
@@ -920,7 +920,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
920920
// make a particular module visible. Let the caller know they should
921921
// suggest an import instead.
922922
if (getLangOpts().ObjC || getLangOpts().CPlusPlusModules)
923-
return nullptr;
923+
return std::nullopt;
924924

925925
// If this is an accessible, non-textual header of M's top-level module
926926
// that transitively includes the given location and makes the
@@ -931,7 +931,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
931931
// FIXME: If we're bailing out due to a private header, we shouldn't suggest
932932
// an import either.
933933
if (InPrivateHeader)
934-
return nullptr;
934+
return std::nullopt;
935935

936936
// If the header is includable and has an include guard, assume the
937937
// intended way to expose its contents is by #include, not by importing a
@@ -942,7 +942,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
942942
Loc = SM.getIncludeLoc(ID);
943943
}
944944

945-
return nullptr;
945+
return std::nullopt;
946946
}
947947

948948
OptionalFileEntryRef Preprocessor::LookupFile(
@@ -1041,14 +1041,14 @@ OptionalFileEntryRef Preprocessor::LookupFile(
10411041
return FE;
10421042
}
10431043

1044-
const FileEntry *CurFileEnt;
1044+
OptionalFileEntryRef CurFileEnt;
10451045
// Otherwise, see if this is a subframework header. If so, this is relative
10461046
// to one of the headers on the #include stack. Walk the list of the current
10471047
// headers on the #include stack and pass them to HeaderInfo.
10481048
if (IsFileLexer()) {
10491049
if ((CurFileEnt = CurPPLexer->getFileEntry())) {
10501050
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
1051-
Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule,
1051+
Filename, *CurFileEnt, SearchPath, RelativePath, RequestingModule,
10521052
SuggestedModule)) {
10531053
if (SuggestedModule && !LangOpts.AsmPreprocessor)
10541054
HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
@@ -1063,7 +1063,7 @@ OptionalFileEntryRef Preprocessor::LookupFile(
10631063
if (IsFileLexer(ISEntry)) {
10641064
if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
10651065
if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
1066-
Filename, CurFileEnt, SearchPath, RelativePath,
1066+
Filename, *CurFileEnt, SearchPath, RelativePath,
10671067
RequestingModule, SuggestedModule)) {
10681068
if (SuggestedModule && !LangOpts.AsmPreprocessor)
10691069
HeaderInfo.getModuleMap().diagnoseHeaderInclusion(

clang/lib/Sema/SemaLookup.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5699,7 +5699,7 @@ void Sema::diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl,
56995699

57005700
/// Get a "quoted.h" or <angled.h> include path to use in a diagnostic
57015701
/// suggesting the addition of a #include of the specified file.
5702-
static std::string getHeaderNameForHeader(Preprocessor &PP, const FileEntry *E,
5702+
static std::string getHeaderNameForHeader(Preprocessor &PP, FileEntryRef E,
57035703
llvm::StringRef IncludingFile) {
57045704
bool IsAngled = false;
57055705
auto Path = PP.getHeaderSearchInfo().suggestPathToFileForDiagnostics(
@@ -5732,11 +5732,12 @@ void Sema::diagnoseMissingImport(SourceLocation UseLoc, const NamedDecl *Decl,
57325732

57335733
// Try to find a suitable header-name to #include.
57345734
std::string HeaderName;
5735-
if (const FileEntry *Header =
5735+
if (OptionalFileEntryRef Header =
57365736
PP.getHeaderToIncludeForDiagnostics(UseLoc, DeclLoc)) {
57375737
if (const FileEntry *FE =
57385738
SourceMgr.getFileEntryForID(SourceMgr.getFileID(UseLoc)))
5739-
HeaderName = getHeaderNameForHeader(PP, Header, FE->tryGetRealPathName());
5739+
HeaderName =
5740+
getHeaderNameForHeader(PP, *Header, FE->tryGetRealPathName());
57405741
}
57415742

57425743
// If we have a #include we should suggest, or if all definition locations

clang/lib/Serialization/GlobalModuleIndex.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ namespace {
405405
const PCHContainerReader &PCHContainerRdr;
406406

407407
/// Mapping from files to module file information.
408-
typedef llvm::MapVector<const FileEntry *, ModuleFileInfo> ModuleFilesMap;
408+
using ModuleFilesMap = llvm::MapVector<FileEntryRef, ModuleFileInfo>;
409409

410410
/// Information about each of the known module files.
411411
ModuleFilesMap ModuleFiles;
412412

413413
/// Mapping from the imported module file to the imported
414414
/// information.
415-
typedef std::multimap<const FileEntry *, ImportedModuleFileInfo>
416-
ImportedModuleFilesMap;
415+
using ImportedModuleFilesMap =
416+
std::multimap<FileEntryRef, ImportedModuleFileInfo>;
417417

418418
/// Information about each importing of a module file.
419419
ImportedModuleFilesMap ImportedModuleFiles;
@@ -430,9 +430,8 @@ namespace {
430430
void emitBlockInfoBlock(llvm::BitstreamWriter &Stream);
431431

432432
/// Retrieve the module file information for the given file.
433-
ModuleFileInfo &getModuleFileInfo(const FileEntry *File) {
434-
llvm::MapVector<const FileEntry *, ModuleFileInfo>::iterator Known
435-
= ModuleFiles.find(File);
433+
ModuleFileInfo &getModuleFileInfo(FileEntryRef File) {
434+
auto Known = ModuleFiles.find(File);
436435
if (Known != ModuleFiles.end())
437436
return Known->second;
438437

@@ -448,7 +447,7 @@ namespace {
448447
: FileMgr(FileMgr), PCHContainerRdr(PCHContainerRdr) {}
449448

450449
/// Load the contents of the given module file into the builder.
451-
llvm::Error loadModuleFile(const FileEntry *File);
450+
llvm::Error loadModuleFile(FileEntryRef File);
452451

453452
/// Write the index to the given bitstream.
454453
/// \returns true if an error occurred, false otherwise.
@@ -519,7 +518,7 @@ namespace {
519518
};
520519
}
521520

522-
llvm::Error GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
521+
llvm::Error GlobalModuleIndexBuilder::loadModuleFile(FileEntryRef File) {
523522
// Open the module file.
524523

525524
auto Buffer = FileMgr.getBufferForFile(File, /*isVolatile=*/true);
@@ -653,9 +652,9 @@ llvm::Error GlobalModuleIndexBuilder::loadModuleFile(const FileEntry *File) {
653652
Idx += Length;
654653

655654
// Find the imported module file.
656-
auto DependsOnFile
657-
= FileMgr.getFile(ImportedFile, /*OpenFile=*/false,
658-
/*CacheFailure=*/false);
655+
auto DependsOnFile =
656+
FileMgr.getOptionalFileRef(ImportedFile, /*OpenFile=*/false,
657+
/*CacheFailure=*/false);
659658

660659
if (!DependsOnFile)
661660
return llvm::createStringError(std::errc::bad_file_descriptor,
@@ -754,14 +753,14 @@ class IdentifierIndexWriterTrait {
754753

755754
bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
756755
for (auto MapEntry : ImportedModuleFiles) {
757-
auto *File = MapEntry.first;
756+
auto File = MapEntry.first;
758757
ImportedModuleFileInfo &Info = MapEntry.second;
759758
if (getModuleFileInfo(File).Signature) {
760759
if (getModuleFileInfo(File).Signature != Info.StoredSignature)
761760
// Verify Signature.
762761
return true;
763-
} else if (Info.StoredSize != File->getSize() ||
764-
Info.StoredModTime != File->getModificationTime())
762+
} else if (Info.StoredSize != File.getSize() ||
763+
Info.StoredModTime != File.getModificationTime())
765764
// Verify Size and ModTime.
766765
return true;
767766
}
@@ -792,11 +791,11 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
792791
M != MEnd; ++M) {
793792
Record.clear();
794793
Record.push_back(M->second.ID);
795-
Record.push_back(M->first->getSize());
796-
Record.push_back(M->first->getModificationTime());
794+
Record.push_back(M->first.getSize());
795+
Record.push_back(M->first.getModificationTime());
797796

798797
// File name
799-
StringRef Name(M->first->getName());
798+
StringRef Name(M->first.getName());
800799
Record.push_back(Name.size());
801800
Record.append(Name.begin(), Name.end());
802801

@@ -892,7 +891,7 @@ GlobalModuleIndex::writeIndex(FileManager &FileMgr,
892891
}
893892

894893
// If we can't find the module file, skip it.
895-
auto ModuleFile = FileMgr.getFile(D->path());
894+
auto ModuleFile = FileMgr.getOptionalFileRef(D->path());
896895
if (!ModuleFile)
897896
continue;
898897

clang/lib/Serialization/ModuleManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
143143
// being consistent across operating systems and across subsequent accesses
144144
// to the Modules map.
145145
auto implicitModuleNamesMatch = [](ModuleKind Kind, const ModuleFile *MF,
146-
const FileEntry *Entry) -> bool {
146+
FileEntryRef Entry) -> bool {
147147
if (Kind != MK_ImplicitModule)
148148
return true;
149-
return Entry->getName() == MF->FileName;
149+
return Entry.getName() == MF->FileName;
150150
};
151151

152152
// Check whether we already loaded this module, before
153153
if (ModuleFile *ModuleEntry = Modules.lookup(Entry)) {
154-
if (implicitModuleNamesMatch(Type, ModuleEntry, Entry)) {
154+
if (implicitModuleNamesMatch(Type, ModuleEntry, *Entry)) {
155155
// Check the stored signature.
156156
if (checkSignature(ModuleEntry->Signature, ExpectedSignature, ErrorStr))
157157
return OutOfDate;

clang/test/Driver/haiku.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Check the C++ header path (libstdc++)
2-
// RUN: %clangxx --target=x86_64-unknown-haiku -### %s 2>&1 \
2+
// RUN: %clangxx --target=x86_64-unknown-haiku --stdlib=libstdc++ -### %s 2>&1 \
33
// RUN: --sysroot=%S/Inputs/haiku_x86_64_tree \
44
// RUN: | FileCheck --check-prefix=CHECK-LIBSTDCXX-HEADER-PATH %s
55
// CHECK-LIBSTDCXX-HEADER-PATH: "-internal-isystem" "[[SYSROOT:[^"]+]]/boot/system/develop/headers/c++"

0 commit comments

Comments
 (0)