Skip to content

Commit e475c3e

Browse files
committed
[Driver][LTO] Copy fix empty stats filename to AMDGPU, HIPAMD, MinGW
1 parent fc74db4 commit e475c3e

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,19 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
611611
addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
612612
Args.AddAllArgs(CmdArgs, options::OPT_L);
613613
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
614-
if (C.getDriver().isUsingLTO())
615-
addLTOOptions(getToolChain(), Args, CmdArgs, Output, Inputs[0],
614+
if (C.getDriver().isUsingLTO()) {
615+
assert(!Inputs.empty() && "Must have at least one input.");
616+
// Find the first filename InputInfo object.
617+
auto Input = llvm::find_if(
618+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
619+
if (Input == Inputs.end())
620+
// For a very rare case, all of the inputs to the linker are
621+
// InputArg. If that happens, just use the first InputInfo.
622+
Input = Inputs.begin();
623+
624+
addLTOOptions(getToolChain(), Args, CmdArgs, Output, *Input,
616625
C.getDriver().getLTOMode() == LTOK_Thin);
617-
else if (Args.hasArg(options::OPT_mcpu_EQ))
626+
} else if (Args.hasArg(options::OPT_mcpu_EQ))
618627
CmdArgs.push_back(Args.MakeArgString(
619628
"-plugin-opt=mcpu=" + Args.getLastArgValue(options::OPT_mcpu_EQ)));
620629
CmdArgs.push_back("-o");

clang/lib/Driver/ToolChains/HIPAMD.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
119119
auto &TC = getToolChain();
120120
auto &D = TC.getDriver();
121121
assert(!Inputs.empty() && "Must have at least one input.");
122+
// Find the first filename InputInfo object.
123+
auto Input = llvm::find_if(
124+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
125+
if (Input == Inputs.end())
126+
// For a very rare case, all of the inputs to the linker are
127+
// InputArg. If that happens, just use the first InputInfo.
128+
Input = Inputs.begin();
129+
122130
bool IsThinLTO = D.getLTOMode(/*IsOffload=*/true) == LTOK_Thin;
123-
addLTOOptions(TC, Args, LldArgs, Output, Inputs[0], IsThinLTO);
131+
addLTOOptions(TC, Args, LldArgs, Output, *Input, IsThinLTO);
124132

125133
// Extract all the -m options
126134
std::vector<llvm::StringRef> Features;

clang/lib/Driver/ToolChains/MinGW.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,15 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
243243

244244
if (D.isUsingLTO()) {
245245
assert(!Inputs.empty() && "Must have at least one input.");
246-
addLTOOptions(TC, Args, CmdArgs, Output, Inputs[0],
246+
// Find the first filename InputInfo object.
247+
auto Input = llvm::find_if(
248+
Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
249+
if (Input == Inputs.end())
250+
// For a very rare case, all of the inputs to the linker are
251+
// InputArg. If that happens, just use the first InputInfo.
252+
Input = Inputs.begin();
253+
254+
addLTOOptions(TC, Args, CmdArgs, Output, *Input,
247255
D.getLTOMode() == LTOK_Thin);
248256
}
249257

0 commit comments

Comments
 (0)