FileManager.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. //===--- FileManager.cpp - File System Probing and Caching ----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the FileManager interface.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. //
  13. // TODO: This should index all interesting directories with dirent calls.
  14. // getdirentries ?
  15. // opendir/readdir_r/closedir ?
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #include "clang/Basic/FileManager.h"
  19. #include "clang/Basic/FileSystemStatCache.h"
  20. #include "llvm/ADT/SmallString.h"
  21. #include "llvm/Config/llvm-config.h"
  22. #include "llvm/ADT/STLExtras.h"
  23. #include "llvm/Support/FileSystem.h"
  24. #include "llvm/Support/MemoryBuffer.h"
  25. #include "llvm/Support/Path.h"
  26. #include "llvm/Support/raw_ostream.h"
  27. #include <algorithm>
  28. #include <cassert>
  29. #include <climits>
  30. #include <cstdint>
  31. #include <cstdlib>
  32. #include <string>
  33. #include <utility>
  34. using namespace clang;
  35. //===----------------------------------------------------------------------===//
  36. // Common logic.
  37. //===----------------------------------------------------------------------===//
  38. FileManager::FileManager(const FileSystemOptions &FSO,
  39. IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
  40. : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64),
  41. SeenFileEntries(64), NextFileUID(0) {
  42. NumDirLookups = NumFileLookups = 0;
  43. NumDirCacheMisses = NumFileCacheMisses = 0;
  44. // If the caller doesn't provide a virtual file system, just grab the real
  45. // file system.
  46. if (!this->FS)
  47. this->FS = llvm::vfs::getRealFileSystem();
  48. }
  49. FileManager::~FileManager() = default;
  50. void FileManager::setStatCache(std::unique_ptr<FileSystemStatCache> statCache) {
  51. assert(statCache && "No stat cache provided?");
  52. StatCache = std::move(statCache);
  53. }
  54. void FileManager::clearStatCache() { StatCache.reset(); }
  55. /// Retrieve the directory that the given file name resides in.
  56. /// Filename can point to either a real file or a virtual file.
  57. static llvm::ErrorOr<const DirectoryEntry *>
  58. getDirectoryFromFile(FileManager &FileMgr, StringRef Filename,
  59. bool CacheFailure) {
  60. if (Filename.empty())
  61. return std::errc::no_such_file_or_directory;
  62. if (llvm::sys::path::is_separator(Filename[Filename.size() - 1]))
  63. return std::errc::is_a_directory;
  64. StringRef DirName = llvm::sys::path::parent_path(Filename);
  65. // Use the current directory if file has no path component.
  66. if (DirName.empty())
  67. DirName = ".";
  68. return FileMgr.getDirectory(DirName, CacheFailure);
  69. }
  70. /// Add all ancestors of the given path (pointing to either a file or
  71. /// a directory) as virtual directories.
  72. void FileManager::addAncestorsAsVirtualDirs(StringRef Path) {
  73. StringRef DirName = llvm::sys::path::parent_path(Path);
  74. if (DirName.empty())
  75. DirName = ".";
  76. auto &NamedDirEnt = *SeenDirEntries.insert(
  77. {DirName, std::errc::no_such_file_or_directory}).first;
  78. // When caching a virtual directory, we always cache its ancestors
  79. // at the same time. Therefore, if DirName is already in the cache,
  80. // we don't need to recurse as its ancestors must also already be in
  81. // the cache (or it's a known non-virtual directory).
  82. if (NamedDirEnt.second)
  83. return;
  84. // Add the virtual directory to the cache.
  85. auto UDE = std::make_unique<DirectoryEntry>();
  86. UDE->Name = NamedDirEnt.first();
  87. NamedDirEnt.second = *UDE.get();
  88. VirtualDirectoryEntries.push_back(std::move(UDE));
  89. // Recursively add the other ancestors.
  90. addAncestorsAsVirtualDirs(DirName);
  91. }
  92. /// Converts a llvm::ErrorOr<T &> to an llvm::ErrorOr<T *> by promoting
  93. /// the address of the inner reference to a pointer or by propagating the error.
  94. template <typename T>
  95. static llvm::ErrorOr<T *> promoteInnerReference(llvm::ErrorOr<T &> value) {
  96. if (value) return &*value;
  97. return value.getError();
  98. }
  99. llvm::ErrorOr<const DirectoryEntry *>
  100. FileManager::getDirectory(StringRef DirName, bool CacheFailure) {
  101. // stat doesn't like trailing separators except for root directory.
  102. // At least, on Win32 MSVCRT, stat() cannot strip trailing '/'.
  103. // (though it can strip '\\')
  104. if (DirName.size() > 1 &&
  105. DirName != llvm::sys::path::root_path(DirName) &&
  106. llvm::sys::path::is_separator(DirName.back()))
  107. DirName = DirName.substr(0, DirName.size()-1);
  108. #ifdef _WIN32
  109. // Fixing a problem with "clang C:test.c" on Windows.
  110. // Stat("C:") does not recognize "C:" as a valid directory
  111. std::string DirNameStr;
  112. if (DirName.size() > 1 && DirName.back() == ':' &&
  113. DirName.equals_lower(llvm::sys::path::root_name(DirName))) {
  114. DirNameStr = DirName.str() + '.';
  115. DirName = DirNameStr;
  116. }
  117. #endif
  118. ++NumDirLookups;
  119. // See if there was already an entry in the map. Note that the map
  120. // contains both virtual and real directories.
  121. auto SeenDirInsertResult =
  122. SeenDirEntries.insert({DirName, std::errc::no_such_file_or_directory});
  123. if (!SeenDirInsertResult.second)
  124. return promoteInnerReference(SeenDirInsertResult.first->second);
  125. // We've not seen this before. Fill it in.
  126. ++NumDirCacheMisses;
  127. auto &NamedDirEnt = *SeenDirInsertResult.first;
  128. assert(!NamedDirEnt.second && "should be newly-created");
  129. // Get the null-terminated directory name as stored as the key of the
  130. // SeenDirEntries map.
  131. StringRef InterndDirName = NamedDirEnt.first();
  132. // Check to see if the directory exists.
  133. llvm::vfs::Status Status;
  134. auto statError = getStatValue(InterndDirName, Status, false,
  135. nullptr /*directory lookup*/);
  136. if (statError) {
  137. // There's no real directory at the given path.
  138. if (CacheFailure)
  139. NamedDirEnt.second = statError;
  140. else
  141. SeenDirEntries.erase(DirName);
  142. return statError;
  143. }
  144. // It exists. See if we have already opened a directory with the
  145. // same inode (this occurs on Unix-like systems when one dir is
  146. // symlinked to another, for example) or the same path (on
  147. // Windows).
  148. DirectoryEntry &UDE = UniqueRealDirs[Status.getUniqueID()];
  149. NamedDirEnt.second = UDE;
  150. if (UDE.getName().empty()) {
  151. // We don't have this directory yet, add it. We use the string
  152. // key from the SeenDirEntries map as the string.
  153. UDE.Name = InterndDirName;
  154. }
  155. return &UDE;
  156. }
  157. llvm::ErrorOr<const FileEntry *>
  158. FileManager::getFile(StringRef Filename, bool openFile, bool CacheFailure) {
  159. auto Result = getFileRef(Filename, openFile, CacheFailure);
  160. if (Result)
  161. return &Result->getFileEntry();
  162. return llvm::errorToErrorCode(Result.takeError());
  163. }
  164. llvm::Expected<FileEntryRef>
  165. FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) {
  166. ++NumFileLookups;
  167. // See if there is already an entry in the map.
  168. auto SeenFileInsertResult =
  169. SeenFileEntries.insert({Filename, std::errc::no_such_file_or_directory});
  170. if (!SeenFileInsertResult.second) {
  171. if (!SeenFileInsertResult.first->second)
  172. return llvm::errorCodeToError(
  173. SeenFileInsertResult.first->second.getError());
  174. // Construct and return and FileEntryRef, unless it's a redirect to another
  175. // filename.
  176. SeenFileEntryOrRedirect Value = *SeenFileInsertResult.first->second;
  177. FileEntry *FE;
  178. if (LLVM_LIKELY(FE = Value.dyn_cast<FileEntry *>()))
  179. return FileEntryRef(SeenFileInsertResult.first->first(), *FE);
  180. return getFileRef(*Value.get<const StringRef *>(), openFile, CacheFailure);
  181. }
  182. // We've not seen this before. Fill it in.
  183. ++NumFileCacheMisses;
  184. auto &NamedFileEnt = *SeenFileInsertResult.first;
  185. assert(!NamedFileEnt.second && "should be newly-created");
  186. // Get the null-terminated file name as stored as the key of the
  187. // SeenFileEntries map.
  188. StringRef InterndFileName = NamedFileEnt.first();
  189. // Look up the directory for the file. When looking up something like
  190. // sys/foo.h we'll discover all of the search directories that have a 'sys'
  191. // subdirectory. This will let us avoid having to waste time on known-to-fail
  192. // searches when we go to find sys/bar.h, because all the search directories
  193. // without a 'sys' subdir will get a cached failure result.
  194. auto DirInfoOrErr = getDirectoryFromFile(*this, Filename, CacheFailure);
  195. if (!DirInfoOrErr) { // Directory doesn't exist, file can't exist.
  196. if (CacheFailure)
  197. NamedFileEnt.second = DirInfoOrErr.getError();
  198. else
  199. SeenFileEntries.erase(Filename);
  200. return llvm::errorCodeToError(DirInfoOrErr.getError());
  201. }
  202. const DirectoryEntry *DirInfo = *DirInfoOrErr;
  203. // FIXME: Use the directory info to prune this, before doing the stat syscall.
  204. // FIXME: This will reduce the # syscalls.
  205. // Check to see if the file exists.
  206. std::unique_ptr<llvm::vfs::File> F;
  207. llvm::vfs::Status Status;
  208. auto statError = getStatValue(InterndFileName, Status, true,
  209. openFile ? &F : nullptr);
  210. if (statError) {
  211. // There's no real file at the given path.
  212. if (CacheFailure)
  213. NamedFileEnt.second = statError;
  214. else
  215. SeenFileEntries.erase(Filename);
  216. return llvm::errorCodeToError(statError);
  217. }
  218. assert((openFile || !F) && "undesired open file");
  219. // It exists. See if we have already opened a file with the same inode.
  220. // This occurs when one dir is symlinked to another, for example.
  221. FileEntry &UFE = UniqueRealFiles[Status.getUniqueID()];
  222. NamedFileEnt.second = &UFE;
  223. // If the name returned by getStatValue is different than Filename, re-intern
  224. // the name.
  225. if (Status.getName() != Filename) {
  226. auto &NewNamedFileEnt =
  227. *SeenFileEntries.insert({Status.getName(), &UFE}).first;
  228. assert((*NewNamedFileEnt.second).get<FileEntry *>() == &UFE &&
  229. "filename from getStatValue() refers to wrong file");
  230. InterndFileName = NewNamedFileEnt.first().data();
  231. // In addition to re-interning the name, construct a redirecting seen file
  232. // entry, that will point to the name the filesystem actually wants to use.
  233. StringRef *Redirect = new (CanonicalNameStorage) StringRef(InterndFileName);
  234. NamedFileEnt.second = Redirect;
  235. }
  236. if (UFE.isValid()) { // Already have an entry with this inode, return it.
  237. // FIXME: this hack ensures that if we look up a file by a virtual path in
  238. // the VFS that the getDir() will have the virtual path, even if we found
  239. // the file by a 'real' path first. This is required in order to find a
  240. // module's structure when its headers/module map are mapped in the VFS.
  241. // We should remove this as soon as we can properly support a file having
  242. // multiple names.
  243. if (DirInfo != UFE.Dir && Status.IsVFSMapped)
  244. UFE.Dir = DirInfo;
  245. // Always update the name to use the last name by which a file was accessed.
  246. // FIXME: Neither this nor always using the first name is correct; we want
  247. // to switch towards a design where we return a FileName object that
  248. // encapsulates both the name by which the file was accessed and the
  249. // corresponding FileEntry.
  250. // FIXME: The Name should be removed from FileEntry once all clients
  251. // adopt FileEntryRef.
  252. UFE.Name = InterndFileName;
  253. return FileEntryRef(InterndFileName, UFE);
  254. }
  255. // Otherwise, we don't have this file yet, add it.
  256. UFE.Name = InterndFileName;
  257. UFE.Size = Status.getSize();
  258. UFE.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
  259. UFE.Dir = DirInfo;
  260. UFE.UID = NextFileUID++;
  261. UFE.UniqueID = Status.getUniqueID();
  262. UFE.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
  263. UFE.File = std::move(F);
  264. UFE.IsValid = true;
  265. if (UFE.File) {
  266. if (auto PathName = UFE.File->getName())
  267. fillRealPathName(&UFE, *PathName);
  268. } else if (!openFile) {
  269. // We should still fill the path even if we aren't opening the file.
  270. fillRealPathName(&UFE, InterndFileName);
  271. }
  272. return FileEntryRef(InterndFileName, UFE);
  273. }
  274. const FileEntry *
  275. FileManager::getVirtualFile(StringRef Filename, off_t Size,
  276. time_t ModificationTime) {
  277. ++NumFileLookups;
  278. // See if there is already an entry in the map for an existing file.
  279. auto &NamedFileEnt = *SeenFileEntries.insert(
  280. {Filename, std::errc::no_such_file_or_directory}).first;
  281. if (NamedFileEnt.second) {
  282. SeenFileEntryOrRedirect Value = *NamedFileEnt.second;
  283. FileEntry *FE;
  284. if (LLVM_LIKELY(FE = Value.dyn_cast<FileEntry *>()))
  285. return FE;
  286. return getVirtualFile(*Value.get<const StringRef *>(), Size,
  287. ModificationTime);
  288. }
  289. // We've not seen this before, or the file is cached as non-existent.
  290. ++NumFileCacheMisses;
  291. addAncestorsAsVirtualDirs(Filename);
  292. FileEntry *UFE = nullptr;
  293. // Now that all ancestors of Filename are in the cache, the
  294. // following call is guaranteed to find the DirectoryEntry from the
  295. // cache.
  296. auto DirInfo = getDirectoryFromFile(*this, Filename, /*CacheFailure=*/true);
  297. assert(DirInfo &&
  298. "The directory of a virtual file should already be in the cache.");
  299. // Check to see if the file exists. If so, drop the virtual file
  300. llvm::vfs::Status Status;
  301. const char *InterndFileName = NamedFileEnt.first().data();
  302. if (!getStatValue(InterndFileName, Status, true, nullptr)) {
  303. UFE = &UniqueRealFiles[Status.getUniqueID()];
  304. Status = llvm::vfs::Status(
  305. Status.getName(), Status.getUniqueID(),
  306. llvm::sys::toTimePoint(ModificationTime),
  307. Status.getUser(), Status.getGroup(), Size,
  308. Status.getType(), Status.getPermissions());
  309. NamedFileEnt.second = UFE;
  310. // If we had already opened this file, close it now so we don't
  311. // leak the descriptor. We're not going to use the file
  312. // descriptor anyway, since this is a virtual file.
  313. if (UFE->File)
  314. UFE->closeFile();
  315. // If we already have an entry with this inode, return it.
  316. if (UFE->isValid())
  317. return UFE;
  318. UFE->UniqueID = Status.getUniqueID();
  319. UFE->IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file;
  320. fillRealPathName(UFE, Status.getName());
  321. } else {
  322. VirtualFileEntries.push_back(std::make_unique<FileEntry>());
  323. UFE = VirtualFileEntries.back().get();
  324. NamedFileEnt.second = UFE;
  325. }
  326. UFE->Name = InterndFileName;
  327. UFE->Size = Size;
  328. UFE->ModTime = ModificationTime;
  329. UFE->Dir = *DirInfo;
  330. UFE->UID = NextFileUID++;
  331. UFE->IsValid = true;
  332. UFE->File.reset();
  333. return UFE;
  334. }
  335. llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) {
  336. // Stat of the file and return nullptr if it doesn't exist.
  337. llvm::vfs::Status Status;
  338. if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr))
  339. return None;
  340. // Fill it in from the stat.
  341. BypassFileEntries.push_back(std::make_unique<FileEntry>());
  342. const FileEntry &VFE = VF.getFileEntry();
  343. FileEntry &BFE = *BypassFileEntries.back();
  344. BFE.Name = VFE.getName();
  345. BFE.Size = Status.getSize();
  346. BFE.Dir = VFE.Dir;
  347. BFE.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime());
  348. BFE.UID = NextFileUID++;
  349. BFE.IsValid = true;
  350. return FileEntryRef(VF.getName(), BFE);
  351. }
  352. bool FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
  353. StringRef pathRef(path.data(), path.size());
  354. if (FileSystemOpts.WorkingDir.empty()
  355. || llvm::sys::path::is_absolute(pathRef))
  356. return false;
  357. SmallString<128> NewPath(FileSystemOpts.WorkingDir);
  358. llvm::sys::path::append(NewPath, pathRef);
  359. path = NewPath;
  360. return true;
  361. }
  362. bool FileManager::makeAbsolutePath(SmallVectorImpl<char> &Path) const {
  363. bool Changed = FixupRelativePath(Path);
  364. if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) {
  365. FS->makeAbsolute(Path);
  366. Changed = true;
  367. }
  368. return Changed;
  369. }
  370. void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
  371. llvm::SmallString<128> AbsPath(FileName);
  372. // This is not the same as `VFS::getRealPath()`, which resolves symlinks
  373. // but can be very expensive on real file systems.
  374. // FIXME: the semantic of RealPathName is unclear, and the name might be
  375. // misleading. We need to clean up the interface here.
  376. makeAbsolutePath(AbsPath);
  377. llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
  378. UFE->RealPathName = AbsPath.str();
  379. }
  380. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  381. FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile) {
  382. uint64_t FileSize = Entry->getSize();
  383. // If there's a high enough chance that the file have changed since we
  384. // got its size, force a stat before opening it.
  385. if (isVolatile)
  386. FileSize = -1;
  387. StringRef Filename = Entry->getName();
  388. // If the file is already open, use the open file descriptor.
  389. if (Entry->File) {
  390. auto Result =
  391. Entry->File->getBuffer(Filename, FileSize,
  392. /*RequiresNullTerminator=*/true, isVolatile);
  393. Entry->closeFile();
  394. return Result;
  395. }
  396. // Otherwise, open the file.
  397. return getBufferForFileImpl(Filename, FileSize, isVolatile);
  398. }
  399. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
  400. FileManager::getBufferForFileImpl(StringRef Filename, int64_t FileSize,
  401. bool isVolatile) {
  402. if (FileSystemOpts.WorkingDir.empty())
  403. return FS->getBufferForFile(Filename, FileSize,
  404. /*RequiresNullTerminator=*/true, isVolatile);
  405. SmallString<128> FilePath(Filename);
  406. FixupRelativePath(FilePath);
  407. return FS->getBufferForFile(FilePath, FileSize,
  408. /*RequiresNullTerminator=*/true, isVolatile);
  409. }
  410. /// getStatValue - Get the 'stat' information for the specified path,
  411. /// using the cache to accelerate it if possible. This returns true
  412. /// if the path points to a virtual file or does not exist, or returns
  413. /// false if it's an existent real file. If FileDescriptor is NULL,
  414. /// do directory look-up instead of file look-up.
  415. std::error_code
  416. FileManager::getStatValue(StringRef Path, llvm::vfs::Status &Status,
  417. bool isFile, std::unique_ptr<llvm::vfs::File> *F) {
  418. // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be
  419. // absolute!
  420. if (FileSystemOpts.WorkingDir.empty())
  421. return FileSystemStatCache::get(Path, Status, isFile, F,
  422. StatCache.get(), *FS);
  423. SmallString<128> FilePath(Path);
  424. FixupRelativePath(FilePath);
  425. return FileSystemStatCache::get(FilePath.c_str(), Status, isFile, F,
  426. StatCache.get(), *FS);
  427. }
  428. std::error_code
  429. FileManager::getNoncachedStatValue(StringRef Path,
  430. llvm::vfs::Status &Result) {
  431. SmallString<128> FilePath(Path);
  432. FixupRelativePath(FilePath);
  433. llvm::ErrorOr<llvm::vfs::Status> S = FS->status(FilePath.c_str());
  434. if (!S)
  435. return S.getError();
  436. Result = *S;
  437. return std::error_code();
  438. }
  439. void FileManager::GetUniqueIDMapping(
  440. SmallVectorImpl<const FileEntry *> &UIDToFiles) const {
  441. UIDToFiles.clear();
  442. UIDToFiles.resize(NextFileUID);
  443. // Map file entries
  444. for (llvm::StringMap<llvm::ErrorOr<SeenFileEntryOrRedirect>,
  445. llvm::BumpPtrAllocator>::const_iterator
  446. FE = SeenFileEntries.begin(),
  447. FEEnd = SeenFileEntries.end();
  448. FE != FEEnd; ++FE)
  449. if (llvm::ErrorOr<SeenFileEntryOrRedirect> Entry = FE->getValue()) {
  450. if (const auto *FE = (*Entry).dyn_cast<FileEntry *>())
  451. UIDToFiles[FE->getUID()] = FE;
  452. }
  453. // Map virtual file entries
  454. for (const auto &VFE : VirtualFileEntries)
  455. UIDToFiles[VFE->getUID()] = VFE.get();
  456. }
  457. StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
  458. // FIXME: use llvm::sys::fs::canonical() when it gets implemented
  459. llvm::DenseMap<const DirectoryEntry *, llvm::StringRef>::iterator Known
  460. = CanonicalDirNames.find(Dir);
  461. if (Known != CanonicalDirNames.end())
  462. return Known->second;
  463. StringRef CanonicalName(Dir->getName());
  464. SmallString<4096> CanonicalNameBuf;
  465. if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
  466. CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
  467. CanonicalDirNames.insert({Dir, CanonicalName});
  468. return CanonicalName;
  469. }
  470. void FileManager::PrintStats() const {
  471. llvm::errs() << "\n*** File Manager Stats:\n";
  472. llvm::errs() << UniqueRealFiles.size() << " real files found, "
  473. << UniqueRealDirs.size() << " real dirs found.\n";
  474. llvm::errs() << VirtualFileEntries.size() << " virtual files found, "
  475. << VirtualDirectoryEntries.size() << " virtual dirs found.\n";
  476. llvm::errs() << NumDirLookups << " dir lookups, "
  477. << NumDirCacheMisses << " dir cache misses.\n";
  478. llvm::errs() << NumFileLookups << " file lookups, "
  479. << NumFileCacheMisses << " file cache misses.\n";
  480. //llvm::errs() << PagesMapped << BytesOfPagesMapped << FSLookups;
  481. }