[PATCH] D100428: [clang][FileManager] Support empty file name in getVirtualFileRef for serialized diagnostics
Alex Lorenz via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 13 17:04:10 PDT 2021
arphaman created this revision.
arphaman added reviewers: dexonsmith, Bigcheese.
Herald added a subscriber: ributzka.
arphaman requested review of this revision.
Herald added a project: clang.
After https://reviews.llvm.org/D90484 libclang is unable to read a serialized diagnostic file which contains a diagnostic which came from a file with an empty filename. The reason being is that the serialized diagnostic reader is creating a virtual file for the "" filename, which now fails after the changes in https://reviews.llvm.org/D90484. This patch restores the previous behavior in `getVirtualFileRef` by allowing it to construct a file entry ref with an empty name by pretending its name is "." so that the directory entry can be created.
Repository:
rG LLVM Github Monorepo
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
@@ -387,8 +387,8 @@
// 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));
+ auto DirInfo = expectedToOptional(getDirectoryFromFile(
+ *this, Filename.empty() ? "." : Filename, /*CacheFailure=*/true));
assert(DirInfo &&
"The directory of a virtual file should already be in the cache.");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100428.337289.patch
Type: text/x-patch
Size: 1095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210414/456f3b92/attachment-0001.bin>
More information about the cfe-commits
mailing list