[clang] df5beeb - [Driver] Add --vfsoverlay flag
Alex Brachet via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 13 09:25:52 PST 2023
Author: Alex Brachet
Date: 2023-02-13T17:25:45Z
New Revision: df5beebc98bbe76312e3a416d5fbc563c037923c
URL: https://github.com/llvm/llvm-project/commit/df5beebc98bbe76312e3a416d5fbc563c037923c
DIFF: https://github.com/llvm/llvm-project/commit/df5beebc98bbe76312e3a416d5fbc563c037923c.diff
LOG: [Driver] Add --vfsoverlay flag
This flag implies `-ivfsoverlay`, and additionally passes the same
argument to the linker if it supports it. At present the only linker
which does is lld-link, so this functionality has only been added to
the MSVC toolchain. Additionally this option has been made a
CoreOption so that clang-cl can use it without `-Xclang`
Differential Revision: https://reviews.llvm.org/D141808
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/msvc-link.c
clang/test/Driver/vfsoverlay.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 96904518a51d7..9b7f30454534b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3400,6 +3400,9 @@ def iwithsysroot : JoinedOrSeparate<["-"], "iwithsysroot">, Group<clang_i_Group>
Flags<[CC1Option]>;
def ivfsoverlay : JoinedOrSeparate<["-"], "ivfsoverlay">, Group<clang_i_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<gfortran_Group>;
def keep__private__externs : Flag<["-"], "keep_private_externs">;
def l : JoinedOrSeparate<["-"], "l">, Flags<[LinkerInput, RenderJoined]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index c97856a47686a..7b91fdf933286 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7038,6 +7038,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
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())
diff --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 223a4e8a1560f..13a7a2f47cf49 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -312,6 +312,11 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
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
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 86717cc6ebfbf..84b2345266036 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3167,7 +3167,7 @@ static bool ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args,
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;
diff --git a/clang/test/Driver/msvc-link.c b/clang/test/Driver/msvc-link.c
index 1ee17fc63c321..52efaf5ece266 100644
--- a/clang/test/Driver/msvc-link.c
+++ b/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:
diff --git a/clang/test/Driver/vfsoverlay.c b/clang/test/Driver/vfsoverlay.c
index 6ae494544f9fd..694cf623c4476 100644
--- a/clang/test/Driver/vfsoverlay.c
+++ b/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-prefix=CHECK2
+// CHECK2: "--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
More information about the cfe-commits
mailing list