Skip to content

Commit c1343a2

Browse files
authored
[clang] [Driver] Ensure we error on lto with link.exe and target *-windows-msvc on non cl driver modes (#109607)
Similar to previous PRs I've done to change some `IsCLMode` checks to `isWindowsMSVCEnvironment`. I stumbled into this one accidentally last week. I did some greps and I think this is the last one for now. All the remaining `IsCLMode` checks are only valid for the cl driver mode. For the `*-windows-msvc` target MSVC link.exe and lld are supported. LTO isn't supported with MSVC link.exe and so we error when lto is enabled but MSVC link.exe is being used. However we only error if the driver mode is cl. If we are using the clang driver with the `*-windows-msvc` target then ensure an error is also emitted when LTO and MSVC link.exe are used together.
1 parent 14e1fef commit c1343a2

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4022,7 +4022,8 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
40224022
// Emitting LLVM while linking disabled except in HIPAMD Toolchain
40234023
if (Args.hasArg(options::OPT_emit_llvm) && !Args.hasArg(options::OPT_hip_link))
40244024
Diag(clang::diag::err_drv_emit_llvm_link);
4025-
if (IsCLMode() && LTOMode != LTOK_None &&
4025+
if (C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment() &&
4026+
LTOMode != LTOK_None &&
40264027
!Args.getLastArgValue(options::OPT_fuse_ld_EQ)
40274028
.equals_insensitive("lld"))
40284029
Diag(clang::diag::err_drv_lto_without_lld);

clang/test/Driver/cl-options.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@
626626
// LTO-THIN: -flto=thin
627627

628628
// RUN: not %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s
629+
// RUN: not %clang_cl -### -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s
630+
// RUN: not %clang -### --target=x86_64-windows-msvc -fuse-ld=link -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s
629631
// LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld
630632

631633
// RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s

clang/test/Driver/clang_f_opts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@
605605
// RUN: %clang -### -S -fjmc -g -fno-jmc --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s
606606
// RUN: %clang -### -S -fjmc -g --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC %s
607607
// RUN: %clang -### -S -fjmc -g -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC %s
608-
// RUN: %clang -### -fjmc -g -flto --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
608+
// RUN: %clang -### -fjmc -g -flto -fuse-ld=lld --target=x86_64-pc-windows-msvc %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
609609
// RUN: %clang -### -fjmc -g -flto --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_JMC_LTO %s
610610
// RUN: %clang -### -fjmc -g -flto -fno-jmc --target=x86_64-unknown-linux %s 2>&1 | FileCheck -check-prefix=CHECK_NOJMC_LTO %s
611611
// CHECK_JMC_WARN: -fjmc requires debug info. Use -g or debug options that enable debugger's stepping function; option ignored

clang/test/Driver/lto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir
66
// CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc
77

8-
// RUN: %clang -ccc-print-phases %s -flto 2> %t
8+
// RUN: %clang -ccc-print-phases %if target={{.*-windows-msvc.*}} %{ -fuse-ld=lld %} -flto %s 2> %t
99
// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s
1010
//
1111
// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}lto.c", c

clang/test/Driver/thinlto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// CHECK-COMPILE-ACTIONS: 2: compiler, {1}, ir
66
// CHECK-COMPILE-ACTIONS: 3: backend, {2}, lto-bc
77

8-
// RUN: %clang -ccc-print-phases %s -flto=thin 2> %t
8+
// RUN: %clang -ccc-print-phases %if target={{.*-windows-msvc.*}} %{ -fuse-ld=lld %} -flto=thin %s 2> %t
99
// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s
1010
//
1111
// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.c", c

clang/test/Driver/thinlto.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK-COMPILE-ACTIONS-NOT: lto-bc
77
// CHECK-COMPILE-ACTIONS: 12: backend, {11}, lto-bc, (host-cuda)
88

9-
// RUN: %clangxx -ccc-print-phases --no-offload-new-driver -nocudainc -nocudalib %s -flto=thin 2> %t
9+
// RUN: %clangxx -ccc-print-phases %if target={{.*-windows-msvc.*}} %{ -fuse-ld=lld %} --no-offload-new-driver -nocudainc -nocudalib %s -flto=thin 2> %t
1010
// RUN: FileCheck -check-prefix=CHECK-COMPILELINK-ACTIONS < %t %s
1111
//
1212
// CHECK-COMPILELINK-ACTIONS: 0: input, "{{.*}}thinlto.cu", cuda, (host-cuda)

0 commit comments

Comments
 (0)