This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. jansvoboda11 marked an inline comment as done. Closed by commit rG06611e361363: [clang] Implement `PointerLikeTraits` for `{File,Directory}EntryRef` (authored by jansvoboda11).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154905/new/ https://reviews.llvm.org/D154905 Files: clang/include/clang/Basic/DirectoryEntry.h clang/include/clang/Basic/FileEntry.h clang/include/clang/Basic/Module.h clang/lib/Basic/Module.cpp clang/lib/Lex/ModuleMap.cpp
Index: clang/lib/Lex/ModuleMap.cpp =================================================================== --- clang/lib/Lex/ModuleMap.cpp +++ clang/lib/Lex/ModuleMap.cpp @@ -1162,7 +1162,7 @@ Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory) { Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader)); - Mod->Umbrella = &UmbrellaHeader.getMapEntry(); + Mod->Umbrella = UmbrellaHeader; Mod->UmbrellaAsWritten = NameAsWritten.str(); Mod->UmbrellaRelativeToRootModuleDirectory = PathRelativeToRootModuleDirectory.str(); @@ -1176,7 +1176,7 @@ void ModuleMap::setUmbrellaDirAsWritten( Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory) { - Mod->Umbrella = &UmbrellaDir.getMapEntry(); + Mod->Umbrella = UmbrellaDir; Mod->UmbrellaAsWritten = NameAsWritten.str(); Mod->UmbrellaRelativeToRootModuleDirectory = PathRelativeToRootModuleDirectory.str(); Index: clang/lib/Basic/Module.cpp =================================================================== --- clang/lib/Basic/Module.cpp +++ clang/lib/Basic/Module.cpp @@ -264,10 +264,10 @@ } OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const { - if (const auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>()) - return FileEntryRef(*ME).getDir(); - if (const auto *ME = Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>()) - return DirectoryEntryRef(*ME); + if (Umbrella && Umbrella.is<FileEntryRef>()) + return Umbrella.get<FileEntryRef>().getDir(); + if (Umbrella && Umbrella.is<DirectoryEntryRef>()) + return Umbrella.get<DirectoryEntryRef>(); return std::nullopt; } Index: clang/include/clang/Basic/Module.h =================================================================== --- clang/include/clang/Basic/Module.h +++ clang/include/clang/Basic/Module.h @@ -156,9 +156,7 @@ std::string PresumedModuleMapFile; /// The umbrella header or directory. - llvm::PointerUnion<const FileEntryRef::MapEntry *, - const DirectoryEntryRef::MapEntry *> - Umbrella; + llvm::PointerUnion<FileEntryRef, DirectoryEntryRef> Umbrella; /// The module signature. ASTFileSignature Signature; @@ -650,19 +648,18 @@ /// Retrieve the umbrella directory as written. std::optional<DirectoryName> getUmbrellaDirAsWritten() const { - if (const auto *ME = - Umbrella.dyn_cast<const DirectoryEntryRef::MapEntry *>()) + if (Umbrella && Umbrella.is<DirectoryEntryRef>()) return DirectoryName{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory, - DirectoryEntryRef(*ME)}; + Umbrella.get<DirectoryEntryRef>()}; return std::nullopt; } /// Retrieve the umbrella header as written. std::optional<Header> getUmbrellaHeaderAsWritten() const { - if (const auto *ME = Umbrella.dyn_cast<const FileEntryRef::MapEntry *>()) + if (Umbrella && Umbrella.is<FileEntryRef>()) return Header{UmbrellaAsWritten, UmbrellaRelativeToRootModuleDirectory, - FileEntryRef(*ME)}; + Umbrella.get<FileEntryRef>()}; return std::nullopt; } Index: clang/include/clang/Basic/FileEntry.h =================================================================== --- clang/include/clang/Basic/FileEntry.h +++ clang/include/clang/Basic/FileEntry.h @@ -234,6 +234,21 @@ } // namespace clang namespace llvm { + +template <> struct PointerLikeTypeTraits<clang::FileEntryRef> { + static inline void *getAsVoidPointer(clang::FileEntryRef File) { + return const_cast<clang::FileEntryRef::MapEntry *>(&File.getMapEntry()); + } + + static inline clang::FileEntryRef getFromVoidPointer(void *Ptr) { + return clang::FileEntryRef( + *reinterpret_cast<const clang::FileEntryRef::MapEntry *>(Ptr)); + } + + static constexpr int NumLowBitsAvailable = PointerLikeTypeTraits< + const clang::FileEntryRef::MapEntry *>::NumLowBitsAvailable; +}; + /// Specialisation of DenseMapInfo for FileEntryRef. template <> struct DenseMapInfo<clang::FileEntryRef> { static inline clang::FileEntryRef getEmptyKey() { Index: clang/include/clang/Basic/DirectoryEntry.h =================================================================== --- clang/include/clang/Basic/DirectoryEntry.h +++ clang/include/clang/Basic/DirectoryEntry.h @@ -72,7 +72,7 @@ bool isSameRef(DirectoryEntryRef RHS) const { return ME == RHS.ME; } DirectoryEntryRef() = delete; - DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {} + explicit DirectoryEntryRef(const MapEntry &ME) : ME(&ME) {} /// Allow DirectoryEntryRef to degrade into 'const DirectoryEntry*' to /// facilitate incremental adoption. @@ -197,6 +197,21 @@ } // namespace clang namespace llvm { + +template <> struct PointerLikeTypeTraits<clang::DirectoryEntryRef> { + static inline void *getAsVoidPointer(clang::DirectoryEntryRef Dir) { + return const_cast<clang::DirectoryEntryRef::MapEntry *>(&Dir.getMapEntry()); + } + + static inline clang::DirectoryEntryRef getFromVoidPointer(void *Ptr) { + return clang::DirectoryEntryRef( + *reinterpret_cast<const clang::DirectoryEntryRef::MapEntry *>(Ptr)); + } + + static constexpr int NumLowBitsAvailable = PointerLikeTypeTraits< + const clang::DirectoryEntryRef::MapEntry *>::NumLowBitsAvailable; +}; + /// Specialisation of DenseMapInfo for DirectoryEntryRef. template <> struct DenseMapInfo<clang::DirectoryEntryRef> { static inline clang::DirectoryEntryRef getEmptyKey() {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits