[clang] [clang-tools-extra] [clang][lex] Remove `HeaderFileInfo::Framework` (PR #114460)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 13:27:15 PDT 2024
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/114460
This PR removes the `HeaderFileInfo::Framework` member and reduces the size of this data type from 32B to 16B. This should improve Clang's memory usage in situations where it keeps track of lots of header files. NFCI. Depends on #114459.
>From 57c87b5326ebe557fc8830d4a558bd6fabf907fb Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 31 Oct 2024 09:24:11 -0700
Subject: [PATCH 1/2] [clang][lex] Remove `-index-header-map`
---
clang/include/clang/Driver/Options.td | 3 --
clang/include/clang/Lex/DirectoryLookup.h | 16 ++-----
clang/include/clang/Lex/HeaderSearch.h | 12 +----
clang/include/clang/Lex/HeaderSearchOptions.h | 3 --
clang/lib/Driver/ToolChains/Clang.cpp | 3 +-
clang/lib/Frontend/CompilerInvocation.cpp | 30 +++---------
clang/lib/Lex/HeaderSearch.cpp | 47 +------------------
clang/lib/Lex/InitHeaderSearch.cpp | 9 ++--
clang/lib/Serialization/ASTReader.cpp | 1 -
clang/lib/Serialization/ASTWriter.cpp | 3 +-
clang/test/Driver/index-header-map.c | 4 --
clang/unittests/Lex/HeaderSearchTest.cpp | 3 +-
12 files changed, 18 insertions(+), 116 deletions(-)
delete mode 100644 clang/test/Driver/index-header-map.c
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index c8bc2fe377b8ec..7a05cc03353ac1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4564,9 +4564,6 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, Group<clang_i_Group>,
HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
-def index_header_map : Flag<["-"], "index-header-map">,
- Visibility<[ClangOption, CC1Option]>,
- HelpText<"Make the next included directory (-I or -F) an indexer header map">;
def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, Group<clang_i_Group>,
Visibility<[ClangOption, CC1Option]>,
HelpText<"Add directory to the API notes search path referenced by module name">, MetaVarName<"<directory>">;
diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h
index 81680d3b271e08..bb703dfad2b28f 100644
--- a/clang/include/clang/Lex/DirectoryLookup.h
+++ b/clang/include/clang/Lex/DirectoryLookup.h
@@ -58,10 +58,6 @@ class DirectoryLookup {
LLVM_PREFERRED_TYPE(LookupType_t)
unsigned LookupType : 2;
- /// Whether this is a header map used when building a framework.
- LLVM_PREFERRED_TYPE(bool)
- unsigned IsIndexHeaderMap : 1;
-
/// Whether we've performed an exhaustive search for module maps
/// within the subdirectories of this directory.
LLVM_PREFERRED_TYPE(bool)
@@ -73,13 +69,12 @@ class DirectoryLookup {
bool isFramework)
: u(Dir), DirCharacteristic(DT),
LookupType(isFramework ? LT_Framework : LT_NormalDir),
- IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {}
+ SearchedAllModuleMaps(false) {}
/// This ctor *does not take ownership* of 'Map'.
- DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT,
- bool isIndexHeaderMap)
+ DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
: u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
- IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {}
+ SearchedAllModuleMaps(false) {}
/// getLookupType - Return the kind of directory lookup that this is: either a
/// normal directory, a framework path, or a HeaderMap.
@@ -146,11 +141,6 @@ class DirectoryLookup {
return getDirCharacteristic() != SrcMgr::C_User;
}
- /// Whether this header map is building a framework or not.
- bool isIndexHeaderMap() const {
- return isHeaderMap() && IsIndexHeaderMap;
- }
-
/// LookupFile - Lookup the specified file in this search path, returning it
/// if it exists or returning null if not.
///
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index df75c192c700a0..8128377d38c35a 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -108,16 +108,6 @@ struct HeaderFileInfo {
LLVM_PREFERRED_TYPE(bool)
unsigned Resolved : 1;
- /// Whether this is a header inside a framework that is currently
- /// being built.
- ///
- /// When a framework is being built, the headers have not yet been placed
- /// into the appropriate framework subdirectories, and therefore are
- /// provided via a header map. This bit indicates when this is one of
- /// those framework headers.
- LLVM_PREFERRED_TYPE(bool)
- unsigned IndexHeaderMapHeader : 1;
-
/// Whether this file has been looked up as a header.
LLVM_PREFERRED_TYPE(bool)
unsigned IsValid : 1;
@@ -140,7 +130,7 @@ struct HeaderFileInfo {
: IsLocallyIncluded(false), isImport(false), isPragmaOnce(false),
DirInfo(SrcMgr::C_User), External(false), isModuleHeader(false),
isTextualModuleHeader(false), isCompilingModuleHeader(false),
- Resolved(false), IndexHeaderMapHeader(false), IsValid(false) {}
+ Resolved(false), IsValid(false) {}
/// Retrieve the controlling macro for this header file, if
/// any.
diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h
index 83a95e9ad90a7f..c85e3d27281701 100644
--- a/clang/include/clang/Lex/HeaderSearchOptions.h
+++ b/clang/include/clang/Lex/HeaderSearchOptions.h
@@ -35,9 +35,6 @@ enum IncludeDirGroup {
/// Paths for '\#include <>' added by '-I'.
Angled,
- /// Like Angled, but marks header maps used when building frameworks.
- IndexHeaderMap,
-
/// Like Angled, but marks system directories.
System,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 04b3832327a99c..db2a4c4d6ff974 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1185,8 +1185,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
Args.addAllArgs(CmdArgs,
{options::OPT_D, options::OPT_U, options::OPT_I_Group,
- options::OPT_F, options::OPT_index_header_map,
- options::OPT_embed_dir_EQ});
+ options::OPT_F, options::OPT_embed_dir_EQ});
// Add -Wp, and -Xpreprocessor if using the preprocessor.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index d8261e12b08b5c..b5fd35aaa1e841 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3190,15 +3190,10 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
auto It = Opts.UserEntries.begin();
auto End = Opts.UserEntries.end();
- // Add -I..., -F..., and -index-header-map options in order.
- for (; It < End && Matches(*It, {frontend::IndexHeaderMap, frontend::Angled},
- std::nullopt, true);
+ // Add -I... and -F... options in order.
+ for (; It < End && Matches(*It, {frontend::Angled}, std::nullopt, true);
++It) {
OptSpecifier Opt = [It, Matches]() {
- if (Matches(*It, frontend::IndexHeaderMap, true, true))
- return OPT_F;
- if (Matches(*It, frontend::IndexHeaderMap, false, true))
- return OPT_I;
if (Matches(*It, frontend::Angled, true, true))
return OPT_F;
if (Matches(*It, frontend::Angled, false, true))
@@ -3206,8 +3201,6 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
llvm_unreachable("Unexpected HeaderSearchOptions::Entry.");
}();
- if (It->Group == frontend::IndexHeaderMap)
- GenerateArg(Consumer, OPT_index_header_map);
GenerateArg(Consumer, Opt, It->Path);
};
@@ -3319,8 +3312,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
llvm::CachedHashString(MacroDef.split('=').first));
}
- // Add -I..., -F..., and -index-header-map options in order.
- bool IsIndexHeaderMap = false;
+ // Add -I... and -F... options in order.
bool IsSysrootSpecified =
Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
@@ -3339,20 +3331,10 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
return A->getValue();
};
- for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
- if (A->getOption().matches(OPT_index_header_map)) {
- // -index-header-map applies to the next -I or -F.
- IsIndexHeaderMap = true;
- continue;
- }
-
- frontend::IncludeDirGroup Group =
- IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
-
+ for (const auto *A : Args.filtered(OPT_I, OPT_F)) {
bool IsFramework = A->getOption().matches(OPT_F);
- Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
- /*IgnoreSysroot*/ true);
- IsIndexHeaderMap = false;
+ Opts.AddPath(PrefixHeaderPath(A, IsFramework), frontend::Angled,
+ IsFramework, /*IgnoreSysroot=*/true);
}
// Add -iprefix/-iwithprefix/-iwithprefixbefore options.
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 052be1395161d4..fb53c13be4944d 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -974,12 +974,10 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
const HeaderFileInfo *FromHFI = getExistingFileInfo(*Includer);
assert(FromHFI && "includer without file info");
unsigned DirInfo = FromHFI->DirInfo;
- bool IndexHeaderMapHeader = FromHFI->IndexHeaderMapHeader;
StringRef Framework = FromHFI->Framework;
HeaderFileInfo &ToHFI = getFileInfo(*FE);
ToHFI.DirInfo = DirInfo;
- ToHFI.IndexHeaderMapHeader = IndexHeaderMapHeader;
ToHFI.Framework = Framework;
if (SearchPath) {
@@ -1125,14 +1123,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
// Set the `Framework` info if this file is in a header map with framework
// style include spelling or found in a framework dir. The header map case
// is possible when building frameworks which use header maps.
- if (CurDir->isHeaderMap() && isAngled) {
- size_t SlashPos = Filename.find('/');
- if (SlashPos != StringRef::npos)
- HFI.Framework =
- getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
- if (CurDir->isIndexHeaderMap())
- HFI.IndexHeaderMapHeader = 1;
- } else if (CurDir->isFramework()) {
+ if ((CurDir->isHeaderMap() && isAngled) || CurDir->isFramework()) {
size_t SlashPos = Filename.find('/');
if (SlashPos != StringRef::npos)
HFI.Framework =
@@ -1156,41 +1147,6 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
return File;
}
- // If we are including a file with a quoted include "foo.h" from inside
- // a header in a framework that is currently being built, and we couldn't
- // resolve "foo.h" any other way, change the include to <Foo/foo.h>, where
- // "Foo" is the name of the framework in which the including header was found.
- if (!Includers.empty() && Includers.front().first && !isAngled &&
- !Filename.contains('/')) {
- const HeaderFileInfo *IncludingHFI =
- getExistingFileInfo(*Includers.front().first);
- assert(IncludingHFI && "includer without file info");
- if (IncludingHFI->IndexHeaderMapHeader) {
- SmallString<128> ScratchFilename;
- ScratchFilename += IncludingHFI->Framework;
- ScratchFilename += '/';
- ScratchFilename += Filename;
-
- OptionalFileEntryRef File = LookupFile(
- ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir,
- Includers.front(), SearchPath, RelativePath, RequestingModule,
- SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr);
-
- if (checkMSVCHeaderSearch(Diags, MSFE,
- File ? &File->getFileEntry() : nullptr,
- IncludeLoc)) {
- if (SuggestedModule)
- *SuggestedModule = MSSuggestedModule;
- return MSFE;
- }
-
- cacheLookupSuccess(LookupFileCache[Filename],
- LookupFileCache[ScratchFilename].HitIt, IncludeLoc);
- // FIXME: SuggestedModule.
- return File;
- }
- }
-
if (checkMSVCHeaderSearch(Diags, MSFE, nullptr, IncludeLoc)) {
if (SuggestedModule)
*SuggestedModule = MSSuggestedModule;
@@ -1358,7 +1314,6 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
HFI.DirInfo = OtherHFI.DirInfo;
HFI.External = (!HFI.IsValid || HFI.External);
HFI.IsValid = true;
- HFI.IndexHeaderMapHeader = OtherHFI.IndexHeaderMapHeader;
if (HFI.Framework.empty())
HFI.Framework = OtherHFI.Framework;
diff --git a/clang/lib/Lex/InitHeaderSearch.cpp b/clang/lib/Lex/InitHeaderSearch.cpp
index 2218db15013d92..86c2ecdf9e36eb 100644
--- a/clang/lib/Lex/InitHeaderSearch.cpp
+++ b/clang/lib/Lex/InitHeaderSearch.cpp
@@ -149,7 +149,7 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
// Compute the DirectoryLookup type.
SrcMgr::CharacteristicKind Type;
- if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
+ if (Group == Quoted || Group == Angled) {
Type = SrcMgr::C_User;
} else if (Group == ExternCSystem) {
Type = SrcMgr::C_ExternCSystem;
@@ -170,9 +170,8 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
if (auto FE = FM.getOptionalFileRef(MappedPathStr)) {
if (const HeaderMap *HM = Headers.CreateHeaderMap(*FE)) {
// It is a headermap, add it to the search path.
- IncludePath.emplace_back(
- Group, DirectoryLookup(HM, Type, Group == IndexHeaderMap),
- UserEntryIdx);
+ IncludePath.emplace_back(Group, DirectoryLookup(HM, Type),
+ UserEntryIdx);
return true;
}
}
@@ -488,7 +487,7 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) {
unsigned NumQuoted = SearchList.size();
for (auto &Include : IncludePath)
- if (Include.Group == Angled || Include.Group == IndexHeaderMap)
+ if (Include.Group == Angled)
SearchList.push_back(Include);
RemoveDuplicates(SearchList, NumQuoted, Verbose);
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 8d8f9378cfeabe..b1af2790f28764 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2123,7 +2123,6 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
HFI.isImport |= (Flags >> 5) & 0x01;
HFI.isPragmaOnce |= (Flags >> 4) & 0x01;
HFI.DirInfo = (Flags >> 1) & 0x07;
- HFI.IndexHeaderMapHeader = Flags & 0x01;
HFI.LazyControllingMacro = Reader.getGlobalIdentifierID(
M, endian::readNext<IdentifierID, llvm::endianness::little>(d));
if (unsigned FrameworkOffset =
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 569c688f793d81..010a9de7c1e676 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2036,8 +2036,7 @@ namespace {
| (Data.HFI.isImport << 5)
| (Writer.isWritingStdCXXNamedModules() ? 0 :
Data.HFI.isPragmaOnce << 4)
- | (Data.HFI.DirInfo << 1)
- | Data.HFI.IndexHeaderMapHeader;
+ | (Data.HFI.DirInfo << 1);
LE.write<uint8_t>(Flags);
if (Data.HFI.LazyControllingMacro.isID())
diff --git a/clang/test/Driver/index-header-map.c b/clang/test/Driver/index-header-map.c
deleted file mode 100644
index 8bd677a0ba98a5..00000000000000
--- a/clang/test/Driver/index-header-map.c
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: %clang -I%S/Before -index-header-map -I%S/Index -I%S/After %s -### 2>> %t.log
-// RUN: FileCheck %s < %t.log
-
-// CHECK: {{-I.*Before.*-index-header-map.*-I.*Index.*-I.*After}}
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index b0375d5985f2ef..e2dd1431e2575c 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -75,8 +75,7 @@ class HeaderSearchTest : public ::testing::Test {
// Test class supports only one HMap at a time.
assert(!HMap);
HMap = HeaderMap::Create(*FE, FileMgr);
- auto DL =
- DirectoryLookup(HMap.get(), SrcMgr::C_User, /*isFramework=*/false);
+ auto DL = DirectoryLookup(HMap.get(), SrcMgr::C_User);
Search.AddSearchPath(DL, isAngled);
}
>From a623a41c4b4c02a87e2aaf225c15856c35ed4150 Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 31 Oct 2024 10:06:44 -0700
Subject: [PATCH 2/2] [clang][lex] Remove `HeaderFileInfo::Framework`
This reduces the size of `HeaderFileInfo` from 32 to 16 bytes.
---
.../clangd/index/SymbolCollector.cpp | 58 +++++++++----------
clang/include/clang/Lex/HeaderSearch.h | 6 +-
clang/lib/Lex/HeaderSearch.cpp | 15 -----
clang/lib/Serialization/ASTReader.cpp | 21 +++----
clang/lib/Serialization/ASTReaderInternals.h | 7 +--
clang/lib/Serialization/ASTWriter.cpp | 24 +-------
clang/unittests/Lex/HeaderSearchTest.cpp | 2 -
7 files changed, 40 insertions(+), 93 deletions(-)
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index d1d744a21cfd55..91ae9d3003a971 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -335,9 +335,10 @@ class SymbolCollector::HeaderFileURICache {
}
struct FrameworkHeaderPath {
- // Path to the framework directory containing the Headers/PrivateHeaders
- // directories e.g. /Frameworks/Foundation.framework/
- llvm::StringRef HeadersParentDir;
+ // Path to the frameworks directory containing the .framework directory.
+ llvm::StringRef FrameworkParentDir;
+ // Name of the framework.
+ llvm::StringRef FrameworkName;
// Subpath relative to the Headers or PrivateHeaders dir, e.g. NSObject.h
// Note: This is NOT relative to the `HeadersParentDir`.
llvm::StringRef HeaderSubpath;
@@ -351,19 +352,17 @@ class SymbolCollector::HeaderFileURICache {
path::reverse_iterator I = path::rbegin(Path);
path::reverse_iterator Prev = I;
path::reverse_iterator E = path::rend(Path);
+ FrameworkHeaderPath HeaderPath;
while (I != E) {
- if (*I == "Headers") {
- FrameworkHeaderPath HeaderPath;
- HeaderPath.HeadersParentDir = Path.substr(0, I - E);
+ if (*I == "Headers" || *I == "PrivateHeaders") {
HeaderPath.HeaderSubpath = Path.substr(Prev - E);
- HeaderPath.IsPrivateHeader = false;
- return HeaderPath;
- }
- if (*I == "PrivateHeaders") {
- FrameworkHeaderPath HeaderPath;
- HeaderPath.HeadersParentDir = Path.substr(0, I - E);
- HeaderPath.HeaderSubpath = Path.substr(Prev - E);
- HeaderPath.IsPrivateHeader = true;
+ HeaderPath.IsPrivateHeader = *I == "PrivateHeaders";
+ if (++I == E)
+ break;
+ HeaderPath.FrameworkName = *I;
+ if (!HeaderPath.FrameworkName.consume_back(".framework"))
+ break;
+ HeaderPath.FrameworkParentDir = Path.substr(0, I - E);
return HeaderPath;
}
Prev = I;
@@ -379,26 +378,27 @@ class SymbolCollector::HeaderFileURICache {
// <Foundation/NSObject_Private.h> which should be used instead of directly
// importing the header.
std::optional<std::string>
- getFrameworkUmbrellaSpelling(llvm::StringRef Framework,
- const HeaderSearch &HS,
+ getFrameworkUmbrellaSpelling(const HeaderSearch &HS,
FrameworkHeaderPath &HeaderPath) {
+ StringRef Framework = HeaderPath.FrameworkName;
auto Res = CacheFrameworkToUmbrellaHeaderSpelling.try_emplace(Framework);
auto *CachedSpelling = &Res.first->second;
if (!Res.second) {
return HeaderPath.IsPrivateHeader ? CachedSpelling->PrivateHeader
: CachedSpelling->PublicHeader;
}
- SmallString<256> UmbrellaPath(HeaderPath.HeadersParentDir);
- llvm::sys::path::append(UmbrellaPath, "Headers", Framework + ".h");
+ SmallString<256> UmbrellaPath(HeaderPath.FrameworkParentDir);
+ llvm::sys::path::append(UmbrellaPath, Framework + ".framework", "Headers",
+ Framework + ".h");
llvm::vfs::Status Status;
auto StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
if (!StatErr)
CachedSpelling->PublicHeader = llvm::formatv("<{0}/{0}.h>", Framework);
- UmbrellaPath = HeaderPath.HeadersParentDir;
- llvm::sys::path::append(UmbrellaPath, "PrivateHeaders",
- Framework + "_Private.h");
+ UmbrellaPath = HeaderPath.FrameworkParentDir;
+ llvm::sys::path::append(UmbrellaPath, Framework + ".framework",
+ "PrivateHeaders", Framework + "_Private.h");
StatErr = HS.getFileMgr().getNoncachedStatValue(UmbrellaPath, Status);
if (!StatErr)
@@ -414,8 +414,7 @@ class SymbolCollector::HeaderFileURICache {
// give <Foundation/Foundation.h> if the umbrella header exists, otherwise
// <Foundation/NSObject.h>.
std::optional<llvm::StringRef>
- getFrameworkHeaderIncludeSpelling(FileEntryRef FE, llvm::StringRef Framework,
- HeaderSearch &HS) {
+ getFrameworkHeaderIncludeSpelling(FileEntryRef FE, HeaderSearch &HS) {
auto Res = CachePathToFrameworkSpelling.try_emplace(FE.getName());
auto *CachedHeaderSpelling = &Res.first->second;
if (!Res.second)
@@ -429,13 +428,15 @@ class SymbolCollector::HeaderFileURICache {
return std::nullopt;
}
if (auto UmbrellaSpelling =
- getFrameworkUmbrellaSpelling(Framework, HS, *HeaderPath)) {
+ getFrameworkUmbrellaSpelling(HS, *HeaderPath)) {
*CachedHeaderSpelling = *UmbrellaSpelling;
return llvm::StringRef(*CachedHeaderSpelling);
}
*CachedHeaderSpelling =
- llvm::formatv("<{0}/{1}>", Framework, HeaderPath->HeaderSubpath).str();
+ llvm::formatv("<{0}/{1}>", HeaderPath->FrameworkName,
+ HeaderPath->HeaderSubpath)
+ .str();
return llvm::StringRef(*CachedHeaderSpelling);
}
@@ -454,11 +455,8 @@ class SymbolCollector::HeaderFileURICache {
// Framework headers are spelled as <FrameworkName/Foo.h>, not
// "path/FrameworkName.framework/Headers/Foo.h".
auto &HS = PP->getHeaderSearchInfo();
- if (const auto *HFI = HS.getExistingFileInfo(*FE))
- if (!HFI->Framework.empty())
- if (auto Spelling =
- getFrameworkHeaderIncludeSpelling(*FE, HFI->Framework, HS))
- return *Spelling;
+ if (auto Spelling = getFrameworkHeaderIncludeSpelling(*FE, HS))
+ return *Spelling;
if (!tooling::isSelfContainedHeader(*FE, PP->getSourceManager(),
PP->getHeaderSearchInfo())) {
diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h
index 8128377d38c35a..a10adae17998b5 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -122,10 +122,6 @@ struct HeaderFileInfo {
/// external storage.
LazyIdentifierInfoPtr LazyControllingMacro;
- /// If this header came from a framework include, this is the name
- /// of the framework.
- StringRef Framework;
-
HeaderFileInfo()
: IsLocallyIncluded(false), isImport(false), isPragmaOnce(false),
DirInfo(SrcMgr::C_User), External(false), isModuleHeader(false),
@@ -144,6 +140,8 @@ struct HeaderFileInfo {
void mergeModuleMembership(ModuleMap::ModuleHeaderRole Role);
};
+static_assert(sizeof(HeaderFileInfo) <= 16);
+
/// An external source of header file information, which may supply
/// information about header files already included.
class ExternalHeaderFileInfoSource {
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index fb53c13be4944d..c5614a8e0ee526 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -974,11 +974,9 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
const HeaderFileInfo *FromHFI = getExistingFileInfo(*Includer);
assert(FromHFI && "includer without file info");
unsigned DirInfo = FromHFI->DirInfo;
- StringRef Framework = FromHFI->Framework;
HeaderFileInfo &ToHFI = getFileInfo(*FE);
ToHFI.DirInfo = DirInfo;
- ToHFI.Framework = Framework;
if (SearchPath) {
StringRef SearchPathRef(IncluderAndDir.second.getName());
@@ -1120,16 +1118,6 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
}
}
- // Set the `Framework` info if this file is in a header map with framework
- // style include spelling or found in a framework dir. The header map case
- // is possible when building frameworks which use header maps.
- if ((CurDir->isHeaderMap() && isAngled) || CurDir->isFramework()) {
- size_t SlashPos = Filename.find('/');
- if (SlashPos != StringRef::npos)
- HFI.Framework =
- getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
- }
-
if (checkMSVCHeaderSearch(Diags, MSFE, &File->getFileEntry(), IncludeLoc)) {
if (SuggestedModule)
*SuggestedModule = MSSuggestedModule;
@@ -1314,9 +1302,6 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
HFI.DirInfo = OtherHFI.DirInfo;
HFI.External = (!HFI.IsValid || HFI.External);
HFI.IsValid = true;
-
- if (HFI.Framework.empty())
- HFI.Framework = OtherHFI.Framework;
}
HeaderFileInfo &HeaderSearch::getFileInfo(FileEntryRef FE) {
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index b1af2790f28764..6ccd57c1cca8f5 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2125,13 +2125,9 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
HFI.DirInfo = (Flags >> 1) & 0x07;
HFI.LazyControllingMacro = Reader.getGlobalIdentifierID(
M, endian::readNext<IdentifierID, llvm::endianness::little>(d));
- if (unsigned FrameworkOffset =
- endian::readNext<uint32_t, llvm::endianness::little>(d)) {
- // The framework offset is 1 greater than the actual offset,
- // since 0 is used as an indicator for "no framework name".
- StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1);
- HFI.Framework = HS->getUniqueFrameworkName(FrameworkName);
- }
+ auto Zero = endian::readNext<uint32_t, llvm::endianness::little>(d);
+ assert(Zero == 0);
+ (void)Zero;
assert((End - d) % 4 == 0 &&
"Wrong data length in HeaderFileInfo deserialization");
@@ -3893,13 +3889,10 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
F.HeaderFileInfoTableData = Blob.data();
F.LocalNumHeaderFileInfos = Record[1];
if (Record[0]) {
- F.HeaderFileInfoTable
- = HeaderFileInfoLookupTable::Create(
- (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
- (const unsigned char *)F.HeaderFileInfoTableData,
- HeaderFileInfoTrait(*this, F,
- &PP.getHeaderSearchInfo(),
- Blob.data() + Record[2]));
+ F.HeaderFileInfoTable = HeaderFileInfoLookupTable::Create(
+ (const unsigned char *)F.HeaderFileInfoTableData + Record[0],
+ (const unsigned char *)F.HeaderFileInfoTableData,
+ HeaderFileInfoTrait(*this, F));
PP.getHeaderSearchInfo().SetExternalSource(this);
if (!PP.getHeaderSearchInfo().getExternalLookup())
diff --git a/clang/lib/Serialization/ASTReaderInternals.h b/clang/lib/Serialization/ASTReaderInternals.h
index 536b19f91691eb..a0feac1df90d1a 100644
--- a/clang/lib/Serialization/ASTReaderInternals.h
+++ b/clang/lib/Serialization/ASTReaderInternals.h
@@ -243,8 +243,6 @@ using ASTSelectorLookupTable =
class HeaderFileInfoTrait {
ASTReader &Reader;
ModuleFile &M;
- HeaderSearch *HS;
- const char *FrameworkStrings;
public:
using external_key_type = FileEntryRef;
@@ -262,9 +260,8 @@ class HeaderFileInfoTrait {
using hash_value_type = unsigned;
using offset_type = unsigned;
- HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M, HeaderSearch *HS,
- const char *FrameworkStrings)
- : Reader(Reader), M(M), HS(HS), FrameworkStrings(FrameworkStrings) {}
+ HeaderFileInfoTrait(ASTReader &Reader, ModuleFile &M)
+ : Reader(Reader), M(M) {}
static hash_value_type ComputeHash(internal_key_ref ikey);
internal_key_type GetInternalKey(external_key_type ekey);
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index 010a9de7c1e676..50e5d4af322a86 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1958,10 +1958,6 @@ namespace {
class HeaderFileInfoTrait {
ASTWriter &Writer;
- // Keep track of the framework names we've used during serialization.
- SmallString<128> FrameworkStringData;
- llvm::StringMap<unsigned> FrameworkNameOffset;
-
public:
HeaderFileInfoTrait(ASTWriter &Writer) : Writer(Writer) {}
@@ -2045,21 +2041,7 @@ namespace {
LE.write<IdentifierID>(
Writer.getIdentifierRef(Data.HFI.LazyControllingMacro.getPtr()));
- unsigned Offset = 0;
- if (!Data.HFI.Framework.empty()) {
- // If this header refers into a framework, save the framework name.
- llvm::StringMap<unsigned>::iterator Pos
- = FrameworkNameOffset.find(Data.HFI.Framework);
- if (Pos == FrameworkNameOffset.end()) {
- Offset = FrameworkStringData.size() + 1;
- FrameworkStringData.append(Data.HFI.Framework);
- FrameworkStringData.push_back(0);
-
- FrameworkNameOffset[Data.HFI.Framework] = Offset;
- } else
- Offset = Pos->second;
- }
- LE.write<uint32_t>(Offset);
+ LE.write<uint32_t>(0);
auto EmitModule = [&](Module *M, ModuleMap::ModuleHeaderRole Role) {
if (uint32_t ModID = Writer.getLocalOrImportedSubmoduleID(M)) {
@@ -2076,9 +2058,6 @@ namespace {
assert(Out.tell() - Start == DataLen && "Wrong data length");
}
-
- const char *strings_begin() const { return FrameworkStringData.begin(); }
- const char *strings_end() const { return FrameworkStringData.end(); }
};
} // namespace
@@ -2213,7 +2192,6 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) {
// Write the header search table
RecordData::value_type Record[] = {HEADER_SEARCH_TABLE, BucketOffset,
NumHeaderSearchEntries, TableData.size()};
- TableData.append(GeneratorTrait.strings_begin(),GeneratorTrait.strings_end());
Stream.EmitRecordWithBlob(TableAbbrev, Record, TableData);
// Free all of the strings we had to duplicate.
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index e2dd1431e2575c..4d07150c04e8d4 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -250,7 +250,6 @@ TEST_F(HeaderSearchTest, HeaderFrameworkLookup) {
auto FI = Search.getExistingFileInfo(FE);
EXPECT_TRUE(FI);
EXPECT_TRUE(FI->IsValid);
- EXPECT_EQ(FI->Framework.str(), "Foo");
EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
}
@@ -320,7 +319,6 @@ TEST_F(HeaderSearchTest, HeaderMapFrameworkLookup) {
auto FI = Search.getExistingFileInfo(FE);
EXPECT_TRUE(FI);
EXPECT_TRUE(FI->IsValid);
- EXPECT_EQ(FI->Framework.str(), "Foo");
EXPECT_EQ(Search.getIncludeNameForHeader(FE), "Foo/Foo.h");
}
More information about the cfe-commits
mailing list