diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp --- a/clang/lib/Basic/FileManager.cpp +++ b/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."); diff --git a/clang/test/Misc/serialized-diags-empty-filename.c b/clang/test/Misc/serialized-diags-empty-filename.c new file mode 100644 --- /dev/null +++ b/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: