Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3354,6 +3354,9 @@ Flags<[CC1Option]>; def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, Group, Flags<[CC1Option]>, HelpText<"Overlay the virtual filesystem described by file over the real file system">; +def vfsoverlay : JoinedOrSeparate<["-", "--"], "vfsoverlay">, Flags<[CC1Option, CoreOption]>, + HelpText<"Overlay the virtual filesystem described by file over the real file system. " + "Additionally, pass this overlay file to the linker if it supports it">; def imultilib : Separate<["-"], "imultilib">, Group; def keep__private__externs : Flag<["-"], "keep_private_externs">; def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>, Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6947,6 +6947,13 @@ A->claim(); } + // Forward --vfsoverlay to -cc1. + for (const Arg *A : Args.filtered(options::OPT_vfsoverlay)) { + CmdArgs.push_back("--vfsoverlay"); + CmdArgs.push_back(A->getValue()); + A->claim(); + } + // Setup statistics file output. SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D); if (!StatsFile.empty()) Index: clang/lib/Driver/ToolChains/MSVC.cpp =================================================================== --- clang/lib/Driver/ToolChains/MSVC.cpp +++ clang/lib/Driver/ToolChains/MSVC.cpp @@ -312,6 +312,11 @@ if (Linker.equals_insensitive("lld")) Linker = "lld-link"; + if (Linker == "lld-link") + for (Arg *A : Args.filtered(options::OPT_vfsoverlay)) + CmdArgs.push_back( + Args.MakeArgString(std::string("/vfsoverlay:") + A->getValue())); + if (Linker.equals_insensitive("link")) { // If we're using the MSVC linker, it's not sufficient to just use link // from the program PATH, because other environments like GnuWin32 install Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -3217,7 +3217,7 @@ Opts.AddSystemHeaderPrefix( A->getValue(), A->getOption().matches(OPT_system_header_prefix)); - for (const auto *A : Args.filtered(OPT_ivfsoverlay)) + for (const auto *A : Args.filtered(OPT_ivfsoverlay, OPT_vfsoverlay)) Opts.AddVFSOverlayFile(A->getValue()); return Diags.getNumErrors() == NumErrorsBefore; Index: clang/test/Driver/msvc-link.c =================================================================== --- clang/test/Driver/msvc-link.c +++ clang/test/Driver/msvc-link.c @@ -30,3 +30,9 @@ // NOREPRO: "-out:msvc-link.exe" // NOREPRO: "-nologo" // NOREPRO-NOT: "-Brepro" + +// RUN: %clang_cl -fuse-ld-lld --vfsoverlay %s -### -- %s 2>&1 | FileCheck --check-prefix=VFSOVERLAY %s +// VFSOVERLAY: -cc1" +// VFSOVERLAY: "--vfsoverlay" +// VFSOVERLAY: lld-link" +// VFSOVERLAY: "/vfsoverlay: Index: clang/test/Driver/vfsoverlay.c =================================================================== --- clang/test/Driver/vfsoverlay.c +++ clang/test/Driver/vfsoverlay.c @@ -1,5 +1,8 @@ // RUN: %clang -ivfsoverlay foo.h -### %s 2>&1 | FileCheck %s // CHECK: "-ivfsoverlay" "foo.h" +// RUN: %clang --vfsoverlay foo.h -### %s 2>&1 | FileCheck %s +// CHECK: "--vfsoverlay" "foo.h" + // RUN: not %clang -ivfsoverlay foo.h %s 2>&1 | FileCheck -check-prefix=CHECK-MISSING %s // CHECK-MISSING: virtual filesystem overlay file 'foo.h' not found