-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][modules] De-duplicate some logic in HeaderFileInfoTrait
#114330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-modules Author: Jan Svoboda (jansvoboda11) ChangesFull diff: https://github.com/llvm/llvm-project/pull/114330.diff 2 Files Affected:
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 8d8f9378cfeabe..692fb8a91840c0 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2042,19 +2042,15 @@ ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M,
return LocalID + I->second;
}
-const FileEntry *HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
+OptionalFileEntryRef
+HeaderFileInfoTrait::getFile(const internal_key_type &Key) {
FileManager &FileMgr = Reader.getFileManager();
- if (!Key.Imported) {
- if (auto File = FileMgr.getOptionalFileRef(Key.Filename))
- return *File;
- return nullptr;
- }
+ if (!Key.Imported)
+ return FileMgr.getOptionalFileRef(Key.Filename);
std::string Resolved = std::string(Key.Filename);
Reader.ResolveImportedPath(M, Resolved);
- if (auto File = FileMgr.getOptionalFileRef(Resolved))
- return *File;
- return nullptr;
+ return FileMgr.getOptionalFileRef(Resolved);
}
unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) {
@@ -2080,8 +2076,8 @@ bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) {
return true;
// Determine whether the actual files are equivalent.
- const FileEntry *FEA = getFile(a);
- const FileEntry *FEB = getFile(b);
+ OptionalFileEntryRef FEA = getFile(a);
+ OptionalFileEntryRef FEB = getFile(b);
return FEA && FEA == FEB;
}
@@ -2112,12 +2108,13 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
HeaderFileInfo HFI;
unsigned Flags = *d++;
+ OptionalFileEntryRef FE;
bool Included = (Flags >> 6) & 0x01;
if (Included)
- if (const FileEntry *FE = getFile(key))
+ if ((FE = getFile(key)))
// Not using \c Preprocessor::markIncluded(), since that would attempt to
// deserialize this header file info again.
- Reader.getPreprocessor().getIncludedFiles().insert(FE);
+ Reader.getPreprocessor().getIncludedFiles().insert(*FE);
// FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp.
HFI.isImport |= (Flags >> 5) & 0x01;
@@ -2146,14 +2143,10 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
// implicit module import.
SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID);
Module *Mod = Reader.getSubmodule(GlobalSMID);
- FileManager &FileMgr = Reader.getFileManager();
ModuleMap &ModMap =
Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap();
- std::string Filename = std::string(key.Filename);
- if (key.Imported)
- Reader.ResolveImportedPath(M, Filename);
- if (auto FE = FileMgr.getOptionalFileRef(Filename)) {
+ if (FE || (FE = getFile(key))) {
// FIXME: NameAsWritten
Module::Header H = {std::string(key.Filename), "", *FE};
ModMap.addHeader(Mod, H, HeaderRole, /*Imported=*/true);
diff --git a/clang/lib/Serialization/ASTReaderInternals.h b/clang/lib/Serialization/ASTReaderInternals.h
index 536b19f91691eb..4ece1cacc91414 100644
--- a/clang/lib/Serialization/ASTReaderInternals.h
+++ b/clang/lib/Serialization/ASTReaderInternals.h
@@ -278,7 +278,7 @@ class HeaderFileInfoTrait {
data_type ReadData(internal_key_ref,const unsigned char *d, unsigned DataLen);
private:
- const FileEntry *getFile(const internal_key_type &Key);
+ OptionalFileEntryRef getFile(const internal_key_type &Key);
};
/// The on-disk hash table used for known header files.
|
benlangmuir
approved these changes
Oct 31, 2024
smallp-o-p
pushed a commit
to smallp-o-p/llvm-project
that referenced
this pull request
Nov 3, 2024
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this pull request
Nov 4, 2024
jansvoboda11
added a commit
to swiftlang/llvm-project
that referenced
this pull request
Nov 4, 2024
…vm#114330) (cherry picked from commit be60afe)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:modules
C++20 modules and Clang Header Modules
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.