@@ -860,7 +860,7 @@ bool tools::isTLSDESCEnabled(const ToolChain &TC,
860860
861861void tools::addLTOOptions (const ToolChain &ToolChain, const ArgList &Args,
862862 ArgStringList &CmdArgs, const InputInfo &Output,
863- const InputInfo &Input , bool IsThinLTO) {
863+ const InputInfoList &Inputs , bool IsThinLTO) {
864864 const llvm::Triple &Triple = ToolChain.getTriple ();
865865 const bool IsOSAIX = Triple.isOSAIX ();
866866 const bool IsAMDGCN = Triple.isAMDGCN ();
@@ -870,6 +870,17 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
870870 const bool IsFatLTO = Args.hasFlag (options::OPT_ffat_lto_objects,
871871 options::OPT_fno_fat_lto_objects, false );
872872 const bool IsUnifiedLTO = Args.hasArg (options::OPT_funified_lto);
873+
874+ assert (!Inputs.empty () && " Must have at least one input." );
875+
876+ auto Input = llvm::find_if (
877+ Inputs, [](const InputInfo &II) -> bool { return II.isFilename (); });
878+ if (Input == Inputs.end ()) {
879+ // For a very rare case, all of the inputs to the linker are
880+ // InputArg. If that happens, just use the first InputInfo.
881+ Input = Inputs.begin ();
882+ }
883+
873884 if (Linker != " lld" && Linker != " lld-link" &&
874885 llvm::sys::path::filename (LinkerPath) != " ld.lld" &&
875886 llvm::sys::path::stem (LinkerPath) != " ld.lld" && !Triple.isOSOpenBSD ()) {
@@ -1163,7 +1174,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
11631174 Args.MakeArgString (Twine (PluginOptPrefix) + " -stack-size-section" ));
11641175
11651176 // Setup statistics file output.
1166- SmallString<128 > StatsFile = getStatsFileName (Args, Output, Input, D);
1177+ SmallString<128 > StatsFile = getStatsFileName (Args, Output, * Input, D);
11671178 if (!StatsFile.empty ())
11681179 CmdArgs.push_back (
11691180 Args.MakeArgString (Twine (PluginOptPrefix) + " stats-file=" + StatsFile));
@@ -1181,7 +1192,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
11811192 // Handle serialized remarks options: '-fsave-optimization-record'
11821193 // and '-foptimization-record-*'.
11831194 if (willEmitRemarks (Args))
1184- renderRemarksOptions (Args, CmdArgs, ToolChain.getEffectiveTriple (), Input,
1195+ renderRemarksOptions (Args, CmdArgs, ToolChain.getEffectiveTriple (), * Input,
11851196 Output, PluginOptPrefix);
11861197
11871198 // Handle remarks hotness/threshold related options.
0 commit comments