diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -15,6 +15,7 @@ #ifndef LLVM_CLANG_BASIC_MODULE_H #define LLVM_CLANG_BASIC_MODULE_H +#include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/FileEntry.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" @@ -44,8 +45,6 @@ namespace clang { -class DirectoryEntry; -class FileEntry; class FileManager; class LangOptions; class TargetInfo; @@ -134,7 +133,7 @@ std::string PresumedModuleMapFile; /// The umbrella header or directory. - const void *Umbrella = nullptr; + llvm::PointerUnion Umbrella; /// The module signature. ASTFileSignature Signature; @@ -303,9 +302,6 @@ /// to a regular (public) module map. unsigned ModuleMapIsPrivate : 1; - /// Whether Umbrella is a directory or header. - unsigned HasUmbrellaDir : 1; - /// Describes the visibility of the various names within a /// particular module. enum NameVisibilityKind { @@ -548,15 +544,16 @@ /// Retrieve the header that serves as the umbrella header for this /// module. Header getUmbrellaHeader() const { - if (!HasUmbrellaDir) - return Header{UmbrellaAsWritten, - static_cast(Umbrella)}; + if (auto *FE = Umbrella.dyn_cast()) + return Header{UmbrellaAsWritten, FE}; return Header{}; } /// Determine whether this module has an umbrella directory that is /// not based on an umbrella header. - bool hasUmbrellaDir() const { return Umbrella && HasUmbrellaDir; } + bool hasUmbrellaDir() const { + return Umbrella && Umbrella.is(); + } /// Add a top-level header associated with this module. void addTopHeader(const FileEntry *File); diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -44,7 +44,7 @@ InferSubmodules(false), InferExplicitSubmodules(false), InferExportWildcard(false), ConfigMacrosExhaustive(false), NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), - HasUmbrellaDir(false), NameVisibility(Hidden) { + NameVisibility(Hidden) { if (Parent) { IsAvailable = Parent->isAvailable(); IsUnimportable = Parent->isUnimportable(); @@ -247,7 +247,7 @@ if (Header U = getUmbrellaHeader()) return {"", U.Entry->getDir()}; - return {UmbrellaAsWritten, static_cast(Umbrella)}; + return {UmbrellaAsWritten, Umbrella.dyn_cast()}; } void Module::addTopHeader(const FileEntry *File) { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1125,7 +1125,6 @@ Twine NameAsWritten) { Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader)); Mod->Umbrella = UmbrellaHeader; - Mod->HasUmbrellaDir = false; Mod->UmbrellaAsWritten = NameAsWritten.str(); UmbrellaDirs[UmbrellaHeader->getDir()] = Mod; @@ -1137,7 +1136,6 @@ void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, Twine NameAsWritten) { Mod->Umbrella = UmbrellaDir; - Mod->HasUmbrellaDir = true; Mod->UmbrellaAsWritten = NameAsWritten.str(); UmbrellaDirs[UmbrellaDir] = Mod; }