if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
return BaseFS;
- IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> Overlay(
- new llvm::vfs::OverlayFileSystem(BaseFS));
+ IntrusiveRefCntPtr<llvm::vfs::FileSystem> Result = BaseFS;
// earlier vfs files are on the bottom
for (const auto &File : CI.getHeaderSearchOpts().VFSOverlayFiles) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
- BaseFS->getBufferForFile(File);
+ Result->getBufferForFile(File);
if (!Buffer) {
Diags.Report(diag::err_missing_vfs_overlay_file) << File;
continue;
}
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = llvm::vfs::getVFSFromYAML(
- std::move(Buffer.get()), /*DiagHandler*/ nullptr, File);
- if (FS)
- Overlay->pushOverlay(FS);
- else
+ std::move(Buffer.get()), /*DiagHandler*/ nullptr, File,
+ /*DiagContext*/ nullptr, Result);
+ if (!FS) {
Diags.Report(diag::err_invalid_vfs_overlay) << File;
+ continue;
+ }
+
+ Result = FS;
}
- return Overlay;
+ return Result;
}
} // namespace clang
--- /dev/null
+{
+ 'version': 0,
+ 'use-external-names': false,
+ 'fallthrough': false,
+ 'roots': [
+ { 'name': '/tests', 'type': 'directory',
+ 'contents': [
+ { 'name': 'vfsroot-include.c', 'type': 'file',
+ 'external-contents': 'TEST_DIR/vfsroot-include.c'
+ },
+ { 'name': 'vfsroot-with-overlay.c', 'type': 'file',
+ 'external-contents': 'TEST_DIR/vfsroot-with-overlay.c'
+ },
+ { 'name': 'vfsroot-module.m', 'type': 'file',
+ 'external-contents': 'TEST_DIR/vfsroot-module.m'
+ }
+ ]
+ },
+ { 'name': '/direct-vfs-root-files', 'type': 'directory',
+ 'contents': [
+ { 'name': 'not_real.h', 'type': 'file',
+ 'external-contents': 'TEST_DIR/Inputs/actual_header.h'
+ },
+ { 'name': 'vfsoverlay.yaml', 'type': 'file',
+ 'external-contents': 'OUT_DIR/vfsoverlay.yaml'
+ }
+ ]
+ },
+ { 'name': '/indirect-vfs-root-files', 'type': 'directory',
+ 'contents': [
+ { 'name': 'actual_header.h', 'type': 'file',
+ 'external-contents': 'TEST_DIR/Inputs/actual_header.h'
+ }
+ ]
+ },
+ { 'name': 'TEST_DIR/Inputs/Broken.framework', 'type': 'directory',
+ 'contents': [
+ { 'name': 'Headers/A.h', 'type': 'file',
+ 'external-contents': 'TEST_DIR/Inputs/Broken.framework/VFSHeaders/A.h'
+ },
+ { 'name': 'Modules/module.modulemap', 'type': 'file',
+ 'external-contents': 'TEST_DIR/Inputs/Broken.framework/Modules/module.modulemap'
+ }
+ ]
+ },
+ # Locations for modules.
+ { 'name': 'OUT_DIR/cache', 'type': 'directory',
+ 'contents': [
+ { 'name': 'Broken.pcm', 'type': 'file',
+ 'external-contents': 'OUT_DIR/cache/Broken.pcm'
+ }
+ ]
+ }
+ ]
+}
--- /dev/null
+// REQUIRES: shell
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: sed -e "s:TEST_DIR:%S:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsroot.yaml > %t.yaml
+// RUN: not %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %S/Inputs -I /direct-vfs-root-files -fsyntax-only /tests/vfsroot-include.c 2>&1 | FileCheck %s
+// The line above tests that the compiler input file is looked up through VFS.
+
+// Test successful include through the VFS.
+#include "not_real.h"
+
+// Test that a file missing from the VFS root is not found, even if it is
+// discoverable through the real file system. Fatal error should be the last
+// in the file as it hides other errors.
+#include "actual_header.h"
+// CHECK: fatal error: 'actual_header.h' file not found
+// CHECK: 1 error generated.
+// CHECK-NOT: error