Skip to content

Commit 866beec

Browse files
jansvoboda11NoumanAmir657
authored andcommitted
[clang][lex] Remove -index-header-map (llvm#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
1 parent 6981fbd commit 866beec

File tree

12 files changed

+18
-116
lines changed

12 files changed

+18
-116
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,9 +4564,6 @@ def ibuiltininc : Flag<["-"], "ibuiltininc">, Group<clang_i_Group>,
45644564
HelpText<"Enable builtin #include directories even when -nostdinc is used "
45654565
"before or after -ibuiltininc. "
45664566
"Using -nobuiltininc after the option disables it">;
4567-
def index_header_map : Flag<["-"], "index-header-map">,
4568-
Visibility<[ClangOption, CC1Option]>,
4569-
HelpText<"Make the next included directory (-I or -F) an indexer header map">;
45704567
def iapinotes_modules : JoinedOrSeparate<["-"], "iapinotes-modules">, Group<clang_i_Group>,
45714568
Visibility<[ClangOption, CC1Option]>,
45724569
HelpText<"Add directory to the API notes search path referenced by module name">, MetaVarName<"<directory>">;

clang/include/clang/Lex/DirectoryLookup.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class DirectoryLookup {
5858
LLVM_PREFERRED_TYPE(LookupType_t)
5959
unsigned LookupType : 2;
6060

61-
/// Whether this is a header map used when building a framework.
62-
LLVM_PREFERRED_TYPE(bool)
63-
unsigned IsIndexHeaderMap : 1;
64-
6561
/// Whether we've performed an exhaustive search for module maps
6662
/// within the subdirectories of this directory.
6763
LLVM_PREFERRED_TYPE(bool)
@@ -73,13 +69,12 @@ class DirectoryLookup {
7369
bool isFramework)
7470
: u(Dir), DirCharacteristic(DT),
7571
LookupType(isFramework ? LT_Framework : LT_NormalDir),
76-
IsIndexHeaderMap(false), SearchedAllModuleMaps(false) {}
72+
SearchedAllModuleMaps(false) {}
7773

7874
/// This ctor *does not take ownership* of 'Map'.
79-
DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT,
80-
bool isIndexHeaderMap)
75+
DirectoryLookup(const HeaderMap *Map, SrcMgr::CharacteristicKind DT)
8176
: u(Map), DirCharacteristic(DT), LookupType(LT_HeaderMap),
82-
IsIndexHeaderMap(isIndexHeaderMap), SearchedAllModuleMaps(false) {}
77+
SearchedAllModuleMaps(false) {}
8378

8479
/// getLookupType - Return the kind of directory lookup that this is: either a
8580
/// normal directory, a framework path, or a HeaderMap.
@@ -146,11 +141,6 @@ class DirectoryLookup {
146141
return getDirCharacteristic() != SrcMgr::C_User;
147142
}
148143

149-
/// Whether this header map is building a framework or not.
150-
bool isIndexHeaderMap() const {
151-
return isHeaderMap() && IsIndexHeaderMap;
152-
}
153-
154144
/// LookupFile - Lookup the specified file in this search path, returning it
155145
/// if it exists or returning null if not.
156146
///

clang/include/clang/Lex/HeaderSearch.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@ struct HeaderFileInfo {
108108
LLVM_PREFERRED_TYPE(bool)
109109
unsigned Resolved : 1;
110110

111-
/// Whether this is a header inside a framework that is currently
112-
/// being built.
113-
///
114-
/// When a framework is being built, the headers have not yet been placed
115-
/// into the appropriate framework subdirectories, and therefore are
116-
/// provided via a header map. This bit indicates when this is one of
117-
/// those framework headers.
118-
LLVM_PREFERRED_TYPE(bool)
119-
unsigned IndexHeaderMapHeader : 1;
120-
121111
/// Whether this file has been looked up as a header.
122112
LLVM_PREFERRED_TYPE(bool)
123113
unsigned IsValid : 1;
@@ -140,7 +130,7 @@ struct HeaderFileInfo {
140130
: IsLocallyIncluded(false), isImport(false), isPragmaOnce(false),
141131
DirInfo(SrcMgr::C_User), External(false), isModuleHeader(false),
142132
isTextualModuleHeader(false), isCompilingModuleHeader(false),
143-
Resolved(false), IndexHeaderMapHeader(false), IsValid(false) {}
133+
Resolved(false), IsValid(false) {}
144134

145135
/// Retrieve the controlling macro for this header file, if
146136
/// any.

clang/include/clang/Lex/HeaderSearchOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ enum IncludeDirGroup {
3535
/// Paths for '\#include <>' added by '-I'.
3636
Angled,
3737

38-
/// Like Angled, but marks header maps used when building frameworks.
39-
IndexHeaderMap,
40-
4138
/// Like Angled, but marks system directories.
4239
System,
4340

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11851185

11861186
Args.addAllArgs(CmdArgs,
11871187
{options::OPT_D, options::OPT_U, options::OPT_I_Group,
1188-
options::OPT_F, options::OPT_index_header_map,
1189-
options::OPT_embed_dir_EQ});
1188+
options::OPT_F, options::OPT_embed_dir_EQ});
11901189

11911190
// Add -Wp, and -Xpreprocessor if using the preprocessor.
11921191

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,24 +3190,17 @@ static void GenerateHeaderSearchArgs(const HeaderSearchOptions &Opts,
31903190
auto It = Opts.UserEntries.begin();
31913191
auto End = Opts.UserEntries.end();
31923192

3193-
// Add -I..., -F..., and -index-header-map options in order.
3194-
for (; It < End && Matches(*It, {frontend::IndexHeaderMap, frontend::Angled},
3195-
std::nullopt, true);
3193+
// Add -I... and -F... options in order.
3194+
for (; It < End && Matches(*It, {frontend::Angled}, std::nullopt, true);
31963195
++It) {
31973196
OptSpecifier Opt = [It, Matches]() {
3198-
if (Matches(*It, frontend::IndexHeaderMap, true, true))
3199-
return OPT_F;
3200-
if (Matches(*It, frontend::IndexHeaderMap, false, true))
3201-
return OPT_I;
32023197
if (Matches(*It, frontend::Angled, true, true))
32033198
return OPT_F;
32043199
if (Matches(*It, frontend::Angled, false, true))
32053200
return OPT_I;
32063201
llvm_unreachable("Unexpected HeaderSearchOptions::Entry.");
32073202
}();
32083203

3209-
if (It->Group == frontend::IndexHeaderMap)
3210-
GenerateArg(Consumer, OPT_index_header_map);
32113204
GenerateArg(Consumer, Opt, It->Path);
32123205
};
32133206

@@ -3319,8 +3312,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
33193312
llvm::CachedHashString(MacroDef.split('=').first));
33203313
}
33213314

3322-
// Add -I..., -F..., and -index-header-map options in order.
3323-
bool IsIndexHeaderMap = false;
3315+
// Add -I... and -F... options in order.
33243316
bool IsSysrootSpecified =
33253317
Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
33263318

@@ -3339,20 +3331,10 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
33393331
return A->getValue();
33403332
};
33413333

3342-
for (const auto *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
3343-
if (A->getOption().matches(OPT_index_header_map)) {
3344-
// -index-header-map applies to the next -I or -F.
3345-
IsIndexHeaderMap = true;
3346-
continue;
3347-
}
3348-
3349-
frontend::IncludeDirGroup Group =
3350-
IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
3351-
3334+
for (const auto *A : Args.filtered(OPT_I, OPT_F)) {
33523335
bool IsFramework = A->getOption().matches(OPT_F);
3353-
Opts.AddPath(PrefixHeaderPath(A, IsFramework), Group, IsFramework,
3354-
/*IgnoreSysroot*/ true);
3355-
IsIndexHeaderMap = false;
3336+
Opts.AddPath(PrefixHeaderPath(A, IsFramework), frontend::Angled,
3337+
IsFramework, /*IgnoreSysroot=*/true);
33563338
}
33573339

33583340
// Add -iprefix/-iwithprefix/-iwithprefixbefore options.

clang/lib/Lex/HeaderSearch.cpp

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -974,12 +974,10 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
974974
const HeaderFileInfo *FromHFI = getExistingFileInfo(*Includer);
975975
assert(FromHFI && "includer without file info");
976976
unsigned DirInfo = FromHFI->DirInfo;
977-
bool IndexHeaderMapHeader = FromHFI->IndexHeaderMapHeader;
978977
StringRef Framework = FromHFI->Framework;
979978

980979
HeaderFileInfo &ToHFI = getFileInfo(*FE);
981980
ToHFI.DirInfo = DirInfo;
982-
ToHFI.IndexHeaderMapHeader = IndexHeaderMapHeader;
983981
ToHFI.Framework = Framework;
984982

985983
if (SearchPath) {
@@ -1125,14 +1123,7 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
11251123
// Set the `Framework` info if this file is in a header map with framework
11261124
// style include spelling or found in a framework dir. The header map case
11271125
// is possible when building frameworks which use header maps.
1128-
if (CurDir->isHeaderMap() && isAngled) {
1129-
size_t SlashPos = Filename.find('/');
1130-
if (SlashPos != StringRef::npos)
1131-
HFI.Framework =
1132-
getUniqueFrameworkName(StringRef(Filename.begin(), SlashPos));
1133-
if (CurDir->isIndexHeaderMap())
1134-
HFI.IndexHeaderMapHeader = 1;
1135-
} else if (CurDir->isFramework()) {
1126+
if ((CurDir->isHeaderMap() && isAngled) || CurDir->isFramework()) {
11361127
size_t SlashPos = Filename.find('/');
11371128
if (SlashPos != StringRef::npos)
11381129
HFI.Framework =
@@ -1156,41 +1147,6 @@ OptionalFileEntryRef HeaderSearch::LookupFile(
11561147
return File;
11571148
}
11581149

1159-
// If we are including a file with a quoted include "foo.h" from inside
1160-
// a header in a framework that is currently being built, and we couldn't
1161-
// resolve "foo.h" any other way, change the include to <Foo/foo.h>, where
1162-
// "Foo" is the name of the framework in which the including header was found.
1163-
if (!Includers.empty() && Includers.front().first && !isAngled &&
1164-
!Filename.contains('/')) {
1165-
const HeaderFileInfo *IncludingHFI =
1166-
getExistingFileInfo(*Includers.front().first);
1167-
assert(IncludingHFI && "includer without file info");
1168-
if (IncludingHFI->IndexHeaderMapHeader) {
1169-
SmallString<128> ScratchFilename;
1170-
ScratchFilename += IncludingHFI->Framework;
1171-
ScratchFilename += '/';
1172-
ScratchFilename += Filename;
1173-
1174-
OptionalFileEntryRef File = LookupFile(
1175-
ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir,
1176-
Includers.front(), SearchPath, RelativePath, RequestingModule,
1177-
SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr);
1178-
1179-
if (checkMSVCHeaderSearch(Diags, MSFE,
1180-
File ? &File->getFileEntry() : nullptr,
1181-
IncludeLoc)) {
1182-
if (SuggestedModule)
1183-
*SuggestedModule = MSSuggestedModule;
1184-
return MSFE;
1185-
}
1186-
1187-
cacheLookupSuccess(LookupFileCache[Filename],
1188-
LookupFileCache[ScratchFilename].HitIt, IncludeLoc);
1189-
// FIXME: SuggestedModule.
1190-
return File;
1191-
}
1192-
}
1193-
11941150
if (checkMSVCHeaderSearch(Diags, MSFE, nullptr, IncludeLoc)) {
11951151
if (SuggestedModule)
11961152
*SuggestedModule = MSSuggestedModule;
@@ -1358,7 +1314,6 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI,
13581314
HFI.DirInfo = OtherHFI.DirInfo;
13591315
HFI.External = (!HFI.IsValid || HFI.External);
13601316
HFI.IsValid = true;
1361-
HFI.IndexHeaderMapHeader = OtherHFI.IndexHeaderMapHeader;
13621317

13631318
if (HFI.Framework.empty())
13641319
HFI.Framework = OtherHFI.Framework;

clang/lib/Lex/InitHeaderSearch.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
149149

150150
// Compute the DirectoryLookup type.
151151
SrcMgr::CharacteristicKind Type;
152-
if (Group == Quoted || Group == Angled || Group == IndexHeaderMap) {
152+
if (Group == Quoted || Group == Angled) {
153153
Type = SrcMgr::C_User;
154154
} else if (Group == ExternCSystem) {
155155
Type = SrcMgr::C_ExternCSystem;
@@ -170,9 +170,8 @@ bool InitHeaderSearch::AddUnmappedPath(const Twine &Path, IncludeDirGroup Group,
170170
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.
173-
IncludePath.emplace_back(
174-
Group, DirectoryLookup(HM, Type, Group == IndexHeaderMap),
175-
UserEntryIdx);
173+
IncludePath.emplace_back(Group, DirectoryLookup(HM, Type),
174+
UserEntryIdx);
176175
return true;
177176
}
178177
}
@@ -488,7 +487,7 @@ void InitHeaderSearch::Realize(const LangOptions &Lang) {
488487
unsigned NumQuoted = SearchList.size();
489488

490489
for (auto &Include : IncludePath)
491-
if (Include.Group == Angled || Include.Group == IndexHeaderMap)
490+
if (Include.Group == Angled)
492491
SearchList.push_back(Include);
493492

494493
RemoveDuplicates(SearchList, NumQuoted, Verbose);

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,6 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
21202120
HFI.isImport |= (Flags >> 5) & 0x01;
21212121
HFI.isPragmaOnce |= (Flags >> 4) & 0x01;
21222122
HFI.DirInfo = (Flags >> 1) & 0x07;
2123-
HFI.IndexHeaderMapHeader = Flags & 0x01;
21242123
HFI.LazyControllingMacro = Reader.getGlobalIdentifierID(
21252124
M, endian::readNext<IdentifierID, llvm::endianness::little>(d));
21262125
if (unsigned FrameworkOffset =

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,8 +2036,7 @@ namespace {
20362036
| (Data.HFI.isImport << 5)
20372037
| (Writer.isWritingStdCXXNamedModules() ? 0 :
20382038
Data.HFI.isPragmaOnce << 4)
2039-
| (Data.HFI.DirInfo << 1)
2040-
| Data.HFI.IndexHeaderMapHeader;
2039+
| (Data.HFI.DirInfo << 1);
20412040
LE.write<uint8_t>(Flags);
20422041

20432042
if (Data.HFI.LazyControllingMacro.isID())

clang/test/Driver/index-header-map.c

Lines changed: 0 additions & 4 deletions
This file was deleted.

clang/unittests/Lex/HeaderSearchTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class HeaderSearchTest : public ::testing::Test {
7575
// Test class supports only one HMap at a time.
7676
assert(!HMap);
7777
HMap = HeaderMap::Create(*FE, FileMgr);
78-
auto DL =
79-
DirectoryLookup(HMap.get(), SrcMgr::C_User, /*isFramework=*/false);
78+
auto DL = DirectoryLookup(HMap.get(), SrcMgr::C_User);
8079
Search.AddSearchPath(DL, isAngled);
8180
}
8281

0 commit comments

Comments
 (0)