[clang] 19b4f17 - [clang][lex] Remove `-index-header-map` (#114459)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 31 16:04:39 PDT 2024
Author: Jan Svoboda
Date: 2024-10-31T16:04:35-07:00
New Revision: 19b4f17d4c0ae12725050d09f04f85bccc686d8e
URL: https://github.com/llvm/llvm-project/commit/19b4f17d4c0ae12725050d09f04f85bccc686d8e
DIFF: https://github.com/llvm/llvm-project/commit/19b4f17d4c0ae12725050d09f04f85bccc686d8e.diff
LOG: [clang][lex] Remove `-index-header-map` (#114459)
This PR removes the `-index-header-map` functionality from Clang. AFAIK
this was only used internally at Apple and is now dead code. The main
motivation behind this change is to enable the removal of
`HeaderFileInfo::Framework` member and reducing the size of that data
structure.
rdar://84036149
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/include/clang/Lex/DirectoryLookup.h
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/HeaderSearchOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/InitHeaderSearch.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/unittests/Lex/HeaderSearchTest.cpp
Removed:
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 d383b4f29a5264..7892bee96b10e0 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2120,7 +2120,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);
}
More information about the cfe-commits
mailing list