@@ -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" );
0 commit comments