[clang] Don't crash when loading invalid VFS for the module dep collector
authorAlex Lorenz <arphaman@gmail.com>
Tue, 27 Apr 2021 00:01:51 +0000 (17:01 -0700)
committerAlex Lorenz <arphaman@gmail.com>
Tue, 27 Apr 2021 00:05:22 +0000 (17:05 -0700)
The VFS is null when it's invalid so return early in collectVFSFromYAML.

clang/test/VFS/broken-vfs-module-dep.c [new file with mode: 0644]
llvm/lib/Support/VirtualFileSystem.cpp

diff --git a/clang/test/VFS/broken-vfs-module-dep.c b/clang/test/VFS/broken-vfs-module-dep.c
new file mode 100644 (file)
index 0000000..2336306
--- /dev/null
@@ -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
index deb0f37..dd820c1 100644 (file)
@@ -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)