Skip to content

Commit 820a50d

Browse files
committed
Move option handling into addLTOOptions for consistency.
1 parent 44abe76 commit 820a50d

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,17 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
13091309
if (Args.hasArg(options::OPT_ftime_report))
13101310
CmdArgs.push_back(
13111311
Args.MakeArgString(Twine(PluginOptPrefix) + "-time-passes"));
1312+
1313+
if (Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
1314+
CmdArgs.push_back(
1315+
Args.MakeArgString("--thinlto-distributor=" + Twine(A->getValue())));
1316+
CmdArgs.push_back(
1317+
Args.MakeArgString("--thinlto-remote-compiler=" +
1318+
Twine(ToolChain.getDriver().getClangProgramPath())));
1319+
1320+
for (auto A : Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
1321+
CmdArgs.push_back(Args.MakeArgString("--thinlto-distributor-arg=" + A));
1322+
}
13121323
}
13131324

13141325
void tools::addOpenMPRuntimeLibraryPath(const ToolChain &TC,

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
455455
addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs,
456456
D.getLTOMode() == LTOK_Thin);
457457

458-
// Forward the DTLTO options to the linker. We add these unconditionally,
459-
// rather than in addLTOOptions() as it is the linker that decides whether to
460-
// do LTO or not dependent upon whether there are any bitcode input files in
461-
// the link.
462-
if (Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
463-
CmdArgs.push_back(
464-
Args.MakeArgString("--thinlto-distributor=" + Twine(A->getValue())));
465-
CmdArgs.push_back(
466-
Args.MakeArgString("--thinlto-remote-compiler=" +
467-
Twine(ToolChain.getDriver().getClangProgramPath())));
468-
469-
for (auto A : Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
470-
CmdArgs.push_back(Args.MakeArgString("--thinlto-distributor-arg=" + A));
471-
}
472-
473458
if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
474459
CmdArgs.push_back("--no-demangle");
475460

clang/test/Driver/DTLTO/dtlto.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
// FORWARD-SAME: "--thinlto-distributor-arg=a3"
2828

2929
/// Check that options are not added without --thinlto-distributor= and
30-
/// that there is an unused option warning issued for -Xthinlto-distributor=
31-
/// options. We specify -flto here as these options should be unaffected by it.
30+
/// that a warning is issued for unused -Xthinlto-distributor options.
3231
// RUN: %clang @%t_l1.rsp 2>&1 | \
3332
// RUN: FileCheck @%t_f.rsp --check-prefix=NODIST
3433

@@ -48,3 +47,11 @@
4847
// DEFAULT: ld.lld
4948
// DEFAULT-SAME: "--thinlto-distributor=d.exe"
5049
// DEFAULT-SAME: "--thinlto-remote-compiler={{.*}}clang{{(.exe)?}}"
50+
51+
/// Check that nothing is forwarded when the compiler is not in LTO mode, and that
52+
/// appropriate unused option warnings are issued.
53+
// RUN: %clang @%t_l2.rsp 2>&1 | \
54+
// RUN: FileCheck @%t_f.rsp --check-prefix=NOFLTO
55+
56+
// NOFLTO: warning: argument unused during compilation: '-fthinlto-distributor=d.exe'
57+
// NOFLTO: ld.lld

0 commit comments

Comments
 (0)