aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2023-12-09 03:22:41 +0100
committerGitHub <noreply@github.com>2023-12-08 18:22:41 -0800
commit0cb0a48cdea730e885e8c955ba1687a8191f824c (patch)
tree6ac634281dd164f36f03954cb5d860700adfe728
parentf1e3e8a14f056a0929f62e29c51667aa7dbe4db8 (diff)
downloadllvm-0cb0a48cdea730e885e8c955ba1687a8191f824c.zip
llvm-0cb0a48cdea730e885e8c955ba1687a8191f824c.tar.gz
llvm-0cb0a48cdea730e885e8c955ba1687a8191f824c.tar.bz2
[clang] NFC: Remove `OptionalFileEntryRefDegradesToFileEntryPtr` (#74899)
-rw-r--r--clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp2
-rw-r--r--clang/include/clang/Basic/FileEntry.h66
-rw-r--r--clang/include/clang/Basic/Module.h2
-rw-r--r--clang/include/clang/Basic/SourceManager.h14
-rw-r--r--clang/include/clang/Lex/PreprocessorLexer.h2
-rw-r--r--clang/include/clang/Serialization/ModuleFile.h2
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp2
-rw-r--r--clang/lib/Lex/ModuleMap.cpp4
-rw-r--r--clang/lib/Lex/PPDirectives.cpp3
-rw-r--r--clang/lib/Lex/Pragma.cpp2
-rw-r--r--clang/lib/Lex/PreprocessorLexer.cpp3
-rw-r--r--clang/lib/Serialization/ASTReader.cpp6
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp6
-rw-r--r--clang/lib/Serialization/ModuleManager.cpp4
-rw-r--r--clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp2
-rw-r--r--clang/tools/libclang/CXIndexDataConsumer.cpp8
-rw-r--r--clang/tools/libclang/CXIndexDataConsumer.h4
-rw-r--r--clang/unittests/Basic/FileEntryTest.cpp25
18 files changed, 33 insertions, 124 deletions
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 52cc2e6..0b1e9f5 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -171,7 +171,7 @@ void ExpandModularHeadersPPCallbacks::InclusionDirective(
if (Imported) {
serialization::ModuleFile *MF =
Compiler.getASTReader()->getModuleManager().lookup(
- Imported->getASTFile());
+ *Imported->getASTFile());
handleModuleFile(MF);
}
parseToLocation(DirectiveLoc);
diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index 6351aea..35efa14 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -279,72 +279,6 @@ template <> struct DenseMapInfo<clang::FileEntryRef> {
namespace clang {
-/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
-/// facilitating incremental patches to propagate FileEntryRef.
-///
-/// This class can be used as return value or field where it's convenient for
-/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose
-/// is to avoid code churn due to dances like the following:
-/// \code
-/// // Old code.
-/// lvalue = rvalue;
-///
-/// // Temporary code from an incremental patch.
-/// OptionalFileEntryRef MaybeF = rvalue;
-/// lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr;
-///
-/// // Final code.
-/// lvalue = rvalue;
-/// \endcode
-///
-/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
-/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with OptionalFileEntryRef.
-class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef {
-public:
- OptionalFileEntryRefDegradesToFileEntryPtr() = default;
- OptionalFileEntryRefDegradesToFileEntryPtr(
- OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
- OptionalFileEntryRefDegradesToFileEntryPtr(
- const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
- OptionalFileEntryRefDegradesToFileEntryPtr &
- operator=(OptionalFileEntryRefDegradesToFileEntryPtr &&) = default;
- OptionalFileEntryRefDegradesToFileEntryPtr &
- operator=(const OptionalFileEntryRefDegradesToFileEntryPtr &) = default;
-
- OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
- OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
- : OptionalFileEntryRef(Ref) {}
- OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
- : OptionalFileEntryRef(MaybeRef) {}
-
- OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) {
- OptionalFileEntryRef::operator=(std::nullopt);
- return *this;
- }
- OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) {
- OptionalFileEntryRef::operator=(Ref);
- return *this;
- }
- OptionalFileEntryRefDegradesToFileEntryPtr &
- operator=(OptionalFileEntryRef MaybeRef) {
- OptionalFileEntryRef::operator=(MaybeRef);
- return *this;
- }
-
- /// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and
- /// FileEntry::getName have been deleted, delete this class and replace
- /// instances with OptionalFileEntryRef
- operator const FileEntry *() const {
- return has_value() ? &(*this)->getFileEntry() : nullptr;
- }
-};
-
-static_assert(
- std::is_trivially_copyable<
- OptionalFileEntryRefDegradesToFileEntryPtr>::value,
- "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
-
inline bool operator==(const FileEntry *LHS, const OptionalFileEntryRef &RHS) {
return LHS == (RHS ? &RHS->getFileEntry() : nullptr);
}
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index d29cc0b..23f263c 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -672,7 +672,7 @@ public:
}
/// The serialized AST file for this module, if one was created.
- OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const {
+ OptionalFileEntryRef getASTFile() const {
return getTopLevelModule()->ASTFile;
}
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 985ea63..d2ece14 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -143,7 +143,7 @@ public:
///
/// FIXME: Make non-optional using a virtual file as needed, remove \c
/// Filename and use \c OrigEntry.getNameAsRequested() instead.
- OptionalFileEntryRefDegradesToFileEntryPtr OrigEntry;
+ OptionalFileEntryRef OrigEntry;
/// References the file which the contents were actually loaded from.
///
@@ -1064,8 +1064,8 @@ public:
/// Returns the FileEntry record for the provided FileID.
const FileEntry *getFileEntryForID(FileID FID) const {
- if (auto *Entry = getSLocEntryForFile(FID))
- return Entry->getFile().getContentCache().OrigEntry;
+ if (auto FE = getFileEntryRefForID(FID))
+ return *FE;
return nullptr;
}
@@ -1083,9 +1083,11 @@ public:
std::optional<StringRef> getNonBuiltinFilenameForID(FileID FID) const;
/// Returns the FileEntry record for the provided SLocEntry.
- const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
- {
- return sloc.getFile().getContentCache().OrigEntry;
+ const FileEntry *
+ getFileEntryForSLocEntry(const SrcMgr::SLocEntry &SLocEntry) const {
+ if (auto FE = SLocEntry.getFile().getContentCache().OrigEntry)
+ return *FE;
+ return nullptr;
}
/// Return a StringRef to the source buffer data for the
diff --git a/clang/include/clang/Lex/PreprocessorLexer.h b/clang/include/clang/Lex/PreprocessorLexer.h
index eebaad7..d71fe70 100644
--- a/clang/include/clang/Lex/PreprocessorLexer.h
+++ b/clang/include/clang/Lex/PreprocessorLexer.h
@@ -157,7 +157,7 @@ public:
/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
/// getFileID(), this only works for lexers with attached preprocessors.
- OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const;
+ OptionalFileEntryRef getFileEntry() const;
/// Iterator that traverses the current stack of preprocessor
/// conditional directives (\#if/\#ifdef/\#ifndef).
diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h
index 70ab61d..9a14129 100644
--- a/clang/include/clang/Serialization/ModuleFile.h
+++ b/clang/include/clang/Serialization/ModuleFile.h
@@ -104,7 +104,7 @@ public:
return File;
}
- OptionalFileEntryRefDegradesToFileEntryPtr getFile() const {
+ OptionalFileEntryRef getFile() const {
if (auto *P = Val.getPointer())
return FileEntryRef(*P);
return std::nullopt;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index e5f8c07..56bbef9 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -2260,7 +2260,7 @@ GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex(
for (ModuleMap::module_iterator I = MMap.module_begin(),
E = MMap.module_end(); I != E; ++I) {
Module *TheModule = I->second;
- const FileEntry *Entry = TheModule->getASTFile();
+ OptionalFileEntryRef Entry = TheModule->getASTFile();
if (!Entry) {
SmallVector<std::pair<IdentifierInfo *, SourceLocation>, 2> Path;
Path.push_back(std::make_pair(
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 1d67e27..268b72c 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1067,9 +1067,7 @@ Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
if (!canInfer)
return nullptr;
} else {
- OptionalFileEntryRefDegradesToFileEntryPtr ModuleMapRef =
- getModuleMapFileForUniquing(Parent);
- ModuleMapFile = ModuleMapRef;
+ ModuleMapFile = getModuleMapFileForUniquing(Parent);
}
// Look for an umbrella header.
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 956e227..1400348 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1934,7 +1934,8 @@ Preprocessor::getIncludeNextStart(const Token &IncludeNextTok) const {
// Start looking up in the directory *after* the one in which the current
// file would be found, if any.
assert(CurPPLexer && "#include_next directive in macro?");
- LookupFromFile = CurPPLexer->getFileEntry();
+ if (auto FE = CurPPLexer->getFileEntry())
+ LookupFromFile = *FE;
Lookup = nullptr;
} else if (!Lookup) {
// The current file was not found by walking the include path. Either it
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 35ab42c..499813f 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -548,7 +548,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
return;
}
- const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry();
+ OptionalFileEntryRef CurFile = getCurrentFileLexer()->getFileEntry();
// If this file is older than the file it depends on, emit a diagnostic.
if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) {
diff --git a/clang/lib/Lex/PreprocessorLexer.cpp b/clang/lib/Lex/PreprocessorLexer.cpp
index 23c80d3..7551ba2 100644
--- a/clang/lib/Lex/PreprocessorLexer.cpp
+++ b/clang/lib/Lex/PreprocessorLexer.cpp
@@ -47,7 +47,6 @@ void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
/// getFileID(), this only works for lexers with attached preprocessors.
-OptionalFileEntryRefDegradesToFileEntryPtr
-PreprocessorLexer::getFileEntry() const {
+OptionalFileEntryRef PreprocessorLexer::getFileEntry() const {
return PP->getSourceManager().getFileEntryRefForID(getFileID());
}
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 49f25d6..ac9bddb 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2531,8 +2531,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
Overridden = false;
}
- OptionalFileEntryRefDegradesToFileEntryPtr File = OptionalFileEntryRef(
- expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)));
+ auto File = FileMgr.getOptionalFileRef(Filename, /*OpenFile=*/false);
// For an overridden file, create a virtual file with the stored
// size/timestamp.
@@ -2559,7 +2558,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
// PCH.
SourceManager &SM = getSourceManager();
// FIXME: Reject if the overrides are different.
- if ((!Overridden && !Transient) && !SkipChecks && SM.isFileOverridden(File)) {
+ if ((!Overridden && !Transient) && !SkipChecks &&
+ SM.isFileOverridden(*File)) {
if (Complain)
Error(diag::err_fe_pch_file_overridden, Filename);
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 38e8b8c..91eb2af 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2182,8 +2182,8 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
"Writing to AST an overridden file is not supported");
// The source location entry is a file. Emit input file ID.
- assert(InputFileIDs[Content->OrigEntry] != 0 && "Missed file entry");
- Record.push_back(InputFileIDs[Content->OrigEntry]);
+ assert(InputFileIDs[*Content->OrigEntry] != 0 && "Missed file entry");
+ Record.push_back(InputFileIDs[*Content->OrigEntry]);
Record.push_back(getAdjustedNumCreatedFIDs(FID));
@@ -4695,7 +4695,7 @@ void ASTWriter::collectNonAffectingInputFiles() {
if (!isModuleMap(File.getFileCharacteristic()) ||
AffectingModuleMaps.empty() ||
- AffectingModuleMaps.find(Cache->OrigEntry) != AffectingModuleMaps.end())
+ llvm::is_contained(AffectingModuleMaps, *Cache->OrigEntry))
continue;
IsSLocAffecting[I] = false;
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index d1ded6c..51b6429 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -52,8 +52,8 @@ ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const {
ModuleFile *ModuleManager::lookupByModuleName(StringRef Name) const {
if (const Module *Mod = HeaderSearchInfo.getModuleMap().findModule(Name))
- if (const FileEntry *File = Mod->getASTFile())
- return lookup(File);
+ if (OptionalFileEntryRef File = Mod->getASTFile())
+ return lookup(*File);
return nullptr;
}
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 1058ddb..f65da41 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -521,7 +521,7 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
serialization::ModuleFile *MF =
MDC.ScanInstance.getASTReader()->getModuleManager().lookup(
- M->getASTFile());
+ *M->getASTFile());
MDC.ScanInstance.getASTReader()->visitInputFileInfos(
*MF, /*IncludeSystem=*/true,
[&](const serialization::InputFileInfo &IFI, bool IsSystem) {
diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp
index 5ca484fb..c102226 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -1074,8 +1074,8 @@ CXIndexDataConsumer::getClientContainerForDC(const DeclContext *DC) const {
return DC ? ContainerMap.lookup(DC) : nullptr;
}
-CXIdxClientFile CXIndexDataConsumer::getIndexFile(const FileEntry *File) {
- return File ? FileMap.lookup(File) : nullptr;
+CXIdxClientFile CXIndexDataConsumer::getIndexFile(OptionalFileEntryRef File) {
+ return File ? FileMap.lookup(*File) : nullptr;
}
CXIdxLoc CXIndexDataConsumer::getIndexLoc(SourceLocation Loc) const {
@@ -1104,8 +1104,8 @@ void CXIndexDataConsumer::translateLoc(SourceLocation Loc,
if (FID.isInvalid())
return;
-
- OptionalFileEntryRefDegradesToFileEntryPtr FE = SM.getFileEntryRefForID(FID);
+
+ OptionalFileEntryRef FE = SM.getFileEntryRefForID(FID);
if (indexFile)
*indexFile = getIndexFile(FE);
if (file)
diff --git a/clang/tools/libclang/CXIndexDataConsumer.h b/clang/tools/libclang/CXIndexDataConsumer.h
index afa2239..54a3add 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.h
+++ b/clang/tools/libclang/CXIndexDataConsumer.h
@@ -460,8 +460,8 @@ private:
const DeclContext *getEntityContainer(const Decl *D) const;
- CXIdxClientFile getIndexFile(const FileEntry *File);
-
+ CXIdxClientFile getIndexFile(OptionalFileEntryRef File);
+
CXIdxLoc getIndexLoc(SourceLocation Loc) const;
void getEntityInfo(const NamedDecl *D,
diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp
index dcd1964..f8a0b4a 100644
--- a/clang/unittests/Basic/FileEntryTest.cpp
+++ b/clang/unittests/Basic/FileEntryTest.cpp
@@ -92,24 +92,6 @@ TEST(FileEntryTest, FileEntryRef) {
EXPECT_EQ(CE1, &R1.getFileEntry());
}
-TEST(FileEntryTest, OptionalFileEntryRefDegradesToFileEntryPtr) {
- FileEntryTestHelper Refs;
- OptionalFileEntryRefDegradesToFileEntryPtr M0;
- OptionalFileEntryRefDegradesToFileEntryPtr M1 = Refs.addFile("1");
- OptionalFileEntryRefDegradesToFileEntryPtr M2 = Refs.addFile("2");
- OptionalFileEntryRefDegradesToFileEntryPtr M0Also = std::nullopt;
- OptionalFileEntryRefDegradesToFileEntryPtr M1Also =
- Refs.addFileAlias("1-also", *M1);
-
- EXPECT_EQ(M0, M0Also);
- EXPECT_EQ(StringRef("1"), M1->getName());
- EXPECT_EQ(StringRef("2"), M2->getName());
- EXPECT_EQ(StringRef("1-also"), M1Also->getName());
-
- const FileEntry *CE1 = M1;
- EXPECT_EQ(CE1, &M1->getFileEntry());
-}
-
TEST(FileEntryTest, equals) {
FileEntryTestHelper Refs;
FileEntryRef R1 = Refs.addFile("1");
@@ -126,13 +108,6 @@ TEST(FileEntryTest, equals) {
EXPECT_NE(R1, R2);
EXPECT_EQ(R1, R1Redirect);
EXPECT_EQ(R1, R1Redirect2);
-
- OptionalFileEntryRefDegradesToFileEntryPtr M1 = R1;
-
- EXPECT_EQ(M1, &R1.getFileEntry());
- EXPECT_EQ(&R1.getFileEntry(), M1);
- EXPECT_NE(M1, &R2.getFileEntry());
- EXPECT_NE(&R2.getFileEntry(), M1);
}
TEST(FileEntryTest, isSameRef) {