aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/FileManager.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
commit344a3780b2e33f6ca763666c380202b18aab72a3 (patch)
treef0b203ee6eb71d7fdd792373e3c81eb18d6934dd /clang/lib/Basic/FileManager.cpp
parentb60736ec1405bb0a8dd40989f67ef4c93da068ab (diff)
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r--clang/lib/Basic/FileManager.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 6e9d5d7fb422..74cd2f295be6 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -128,7 +128,7 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) {
// Stat("C:") does not recognize "C:" as a valid directory
std::string DirNameStr;
if (DirName.size() > 1 && DirName.back() == ':' &&
- DirName.equals_lower(llvm::sys::path::root_name(DirName))) {
+ DirName.equals_insensitive(llvm::sys::path::root_name(DirName))) {
DirNameStr = DirName.str() + '.';
DirName = DirNameStr;
}
@@ -384,9 +384,12 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
// Now that all ancestors of Filename are in the cache, the
// following call is guaranteed to find the DirectoryEntry from the
- // cache.
- auto DirInfo = expectedToOptional(
- getDirectoryFromFile(*this, Filename, /*CacheFailure=*/true));
+ // cache. A virtual file can also have an empty filename, that could come
+ // from a source location preprocessor directive with an empty filename as
+ // an example, so we need to pretend it has a name to ensure a valid directory
+ // entry can be returned.
+ auto DirInfo = expectedToOptional(getDirectoryFromFile(
+ *this, Filename.empty() ? "." : Filename, /*CacheFailure=*/true));
assert(DirInfo &&
"The directory of a virtual file should already be in the cache.");
@@ -608,7 +611,7 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) {
SmallString<4096> CanonicalNameBuf;
if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf))
- CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
+ CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage);
CanonicalNames.insert({Dir, CanonicalName});
return CanonicalName;
@@ -624,7 +627,7 @@ StringRef FileManager::getCanonicalName(const FileEntry *File) {
SmallString<4096> CanonicalNameBuf;
if (!FS->getRealPath(File->getName(), CanonicalNameBuf))
- CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage);
+ CanonicalName = CanonicalNameBuf.str().copy(CanonicalNameStorage);
CanonicalNames.insert({File, CanonicalName});
return CanonicalName;