This revision was automatically updated to reflect the committed changes.
Closed by commit rGc1554f32e3b3: [clang][FileManager] Support empty file name 
in getVirtualFileRef for… (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D100428?vs=337289&id=337507#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100428/new/

https://reviews.llvm.org/D100428

Files:
  clang/lib/Basic/FileManager.cpp
  clang/test/Misc/serialized-diags-empty-filename.c


Index: clang/test/Misc/serialized-diags-empty-filename.c
===================================================================
--- /dev/null
+++ clang/test/Misc/serialized-diags-empty-filename.c
@@ -0,0 +1,8 @@
+// RUN: rm -f %t.diag
+// RUN: not %clang -c %s --serialize-diagnostics %t.diag
+// RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s
+
+# 1 "" 1
+void 1();
+
+// CHECK: :1:6: error:
Index: clang/lib/Basic/FileManager.cpp
===================================================================
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -384,9 +384,12 @@
 
   // 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.");
 


Index: clang/test/Misc/serialized-diags-empty-filename.c
===================================================================
--- /dev/null
+++ clang/test/Misc/serialized-diags-empty-filename.c
@@ -0,0 +1,8 @@
+// RUN: rm -f %t.diag
+// RUN: not %clang -c %s --serialize-diagnostics %t.diag
+// RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s
+
+# 1 "" 1
+void 1();
+
+// CHECK: :1:6: error:
Index: clang/lib/Basic/FileManager.cpp
===================================================================
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -384,9 +384,12 @@
 
   // 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.");
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to