From 2509f9fbad0d37e3e5fea934c0ae7af3877ba4ae Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Mon, 26 Apr 2021 17:01:51 -0700 Subject: [PATCH] [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. --- clang/test/VFS/broken-vfs-module-dep.c | 7 +++++++ llvm/lib/Support/VirtualFileSystem.cpp | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 clang/test/VFS/broken-vfs-module-dep.c 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 0000000..2336306 --- /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 deb0f37..dd820c1 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2127,6 +2127,8 @@ void vfs::collectVFSFromYAML(std::unique_ptr Buffer, std::unique_ptr VFS = RedirectingFileSystem::create( std::move(Buffer), DiagHandler, YAMLFilePath, DiagContext, std::move(ExternalFS)); + if (!VFS) + return; ErrorOr RootResult = VFS->lookupPath("/"); if (!RootResult) -- 2.7.4