[clang] 2509f9f - [clang] Don't crash when loading invalid VFS for the module dep collector

Alex Lorenz via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 26 17:05:38 PDT 2021


Author: Alex Lorenz
Date: 2021-04-26T17:05:22-07:00
New Revision: 2509f9fbad0d37e3e5fea934c0ae7af3877ba4ae

URL: https://github.com/llvm/llvm-project/commit/2509f9fbad0d37e3e5fea934c0ae7af3877ba4ae
DIFF: https://github.com/llvm/llvm-project/commit/2509f9fbad0d37e3e5fea934c0ae7af3877ba4ae.diff

LOG: [clang] Don't crash when loading invalid VFS for the module dep collector

The VFS is null when it's invalid so return early in collectVFSFromYAML.

Added: 
    clang/test/VFS/broken-vfs-module-dep.c

Modified: 
    llvm/lib/Support/VirtualFileSystem.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/VFS/broken-vfs-module-dep.c b/clang/test/VFS/broken-vfs-module-dep.c
new file mode 100644
index 0000000000000..2336306de8c6d
--- /dev/null
+++ b/clang/test/VFS/broken-vfs-module-dep.c
@@ -0,0 +1,7 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: not %clang_cc1 -module-dependency-dir %t -ivfsoverlay %S/Inputs/invalid-yaml.yaml %s 2>&1 | FileCheck %s
+
+// CHECK: error: Unexpected token
+// CHECK: error: Unexpected token
+// CHECK: 1 error generated

diff  --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index deb0f37bd159d..dd820c15ca68e 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -2127,6 +2127,8 @@ void vfs::collectVFSFromYAML(std::unique_ptr<MemoryBuffer> Buffer,
   std::unique_ptr<RedirectingFileSystem> VFS = RedirectingFileSystem::create(
       std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext,
       std::move(ExternalFS));
+  if (!VFS)
+    return;
   ErrorOr<RedirectingFileSystem::LookupResult> RootResult =
       VFS->lookupPath("/");
   if (!RootResult)


        


More information about the cfe-commits mailing list