[clang] 80a4948 - [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets (#113966)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 3 18:25:23 PST 2024


Author: Zhaoshi Zheng
Date: 2024-11-03T18:25:20-08:00
New Revision: 80a49487e1b64d32d00f0c80cff746cfd4988b36

URL: https://github.com/llvm/llvm-project/commit/80a49487e1b64d32d00f0c80cff746cfd4988b36
DIFF: https://github.com/llvm/llvm-project/commit/80a49487e1b64d32d00f0c80cff746cfd4988b36.diff

LOG: [clang][Driver] Allow -fuse-lld=lld-link when lto is enabled on *windows-msvc targets (#113966)

Follow-up on https://github.com/llvm/llvm-project/pull/109607, we have a
use case on Windows-on-ARM64 where `cmake -G "Unix Makefiles"` generates
`-fuse-ld=lld-link`, which is accidentally disallowed by PR#109607.

Added: 
    clang/test/Driver/windows-lto.c

Modified: 
    clang/lib/Driver/Driver.cpp
    clang/test/Driver/clang_f_opts.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 083035dee43028..df802450ad5938 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4035,7 +4035,7 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
     if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() &&
         LTOMode != LTOK_None &&
         !Args.getLastArgValue(options::OPT_fuse_ld_EQ)
-             .equals_insensitive("lld"))
+             .starts_with_insensitive("lld"))
       Diag(clang::diag::err_drv_lto_without_lld);
 
     // If -dumpdir is not specified, give a default prefix derived from the link

diff  --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index fd15552715cb35..2cfbe256bc7456 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -606,6 +606,7 @@
 // RUN: %clang -### -S -fjmc -g --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s
 // RUN: %clang -### -S -fjmc -g -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s
 // RUN: %clang -### -fjmc -g -flto -fuse-ld=lld --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
+// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld-link --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
 // RUN: %clang -### -fjmc -g -flto --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s
 // RUN: %clang -### -fjmc -g -flto -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
 // CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored

diff  --git a/clang/test/Driver/windows-lto.c b/clang/test/Driver/windows-lto.c
new file mode 100644
index 00000000000000..f85b0438ee4b1b
--- /dev/null
+++ b/clang/test/Driver/windows-lto.c
@@ -0,0 +1,9 @@
+// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld -### %s 2>&1 | FileCheck %s
+// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld -### %s 2>&1 | FileCheck %s
+
+// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto -fuse-ld=lld-link -### %s 2>&1 | FileCheck %s
+// RUN: %clang --target=aarch64-pc-windows-msvc -O3 -flto=thin -fuse-ld=lld-link -### %s 2>&1 | FileCheck %s
+
+// CHECK: "{{.*}}lld-link{{(.exe)?}}" "-out:a.exe" "-defaultlib:libcmt" "-defaultlib:oldnames"
+
+int main() { return 0; }


        


More information about the cfe-commits mailing list