[clang] 289828b - [Driver][MSVC] Move lld specific flags before inputs

via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 1 18:29:29 PDT 2023


Author: Haohai Wen
Date: 2023-07-02T09:29:09+08:00
New Revision: 289828b1c0a6bc6eed8a634376a5152adae2283b

URL: https://github.com/llvm/llvm-project/commit/289828b1c0a6bc6eed8a634376a5152adae2283b
DIFF: https://github.com/llvm/llvm-project/commit/289828b1c0a6bc6eed8a634376a5152adae2283b.diff

LOG: [Driver][MSVC] Move lld specific flags before inputs

Check linker earlier so that lld specific flags can be append before
inputs. Just like position of other flags. The intention is to make
expanded cmd more consistent and elegent so that user can easily
look for inputs when using -###.

Reviewed By: mstorsjo

Differential Revision: https://reviews.llvm.org/D154176

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/MSVC.cpp
    clang/test/Driver/msvc-link.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/MSVC.cpp b/clang/lib/Driver/ToolChains/MSVC.cpp
index 2ffe0d56835c57..6b2eaef1f2e7d1 100644
--- a/clang/lib/Driver/ToolChains/MSVC.cpp
+++ b/clang/lib/Driver/ToolChains/MSVC.cpp
@@ -269,6 +269,19 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
   }
 
+  StringRef Linker =
+      Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
+  if (Linker.empty())
+    Linker = "link";
+  // We need to translate 'lld' into 'lld-link'.
+  else 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()));
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
     if (Input.isFilename()) {
@@ -301,22 +314,9 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   std::vector<const char *> Environment;
 
-  // We need to special case some linker paths.  In the case of lld, we need to
-  // translate 'lld' into 'lld-link', and in the case of the regular msvc
+  // We need to special case some linker paths. In the case of the regular msvc
   // linker, we need to use a special search algorithm.
   llvm::SmallString<128> linkPath;
-  StringRef Linker
-    = Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
-  if (Linker.empty())
-    Linker = "link";
-  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/test/Driver/msvc-link.c b/clang/test/Driver/msvc-link.c
index b0bc837d57a62d..64e099ea63042f 100644
--- a/clang/test/Driver/msvc-link.c
+++ b/clang/test/Driver/msvc-link.c
@@ -35,4 +35,4 @@
 // VFSOVERLAY: -cc1"
 // VFSOVERLAY: "--vfsoverlay"
 // VFSOVERLAY: lld-link
-// VFSOVERLAY: "/vfsoverlay:
+// VFSOVERLAY: "/vfsoverlay:{{.*}}" "{{.*}}.obj"


        


More information about the cfe-commits mailing list