Coverage Report

Created: 2019-07-24 05:18

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