sepavloff updated this revision to Diff 280796. sepavloff added a comment. Rebased patch
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D78902/new/ https://reviews.llvm.org/D78902 Files: clang/include/clang/Driver/Job.h clang/lib/Driver/Job.cpp clang/lib/Driver/ToolChains/AIX.cpp clang/lib/Driver/ToolChains/AMDGPU.cpp clang/lib/Driver/ToolChains/AVR.cpp clang/lib/Driver/ToolChains/Ananas.cpp clang/lib/Driver/ToolChains/BareMetal.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Driver/ToolChains/CloudABI.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp clang/lib/Driver/ToolChains/CrossWindows.cpp clang/lib/Driver/ToolChains/Cuda.cpp clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/DragonFly.cpp clang/lib/Driver/ToolChains/Flang.cpp clang/lib/Driver/ToolChains/FreeBSD.cpp clang/lib/Driver/ToolChains/Fuchsia.cpp clang/lib/Driver/ToolChains/Gnu.cpp clang/lib/Driver/ToolChains/HIP.cpp clang/lib/Driver/ToolChains/Hexagon.cpp clang/lib/Driver/ToolChains/InterfaceStubs.cpp clang/lib/Driver/ToolChains/MSP430.cpp clang/lib/Driver/ToolChains/MSVC.cpp clang/lib/Driver/ToolChains/MinGW.cpp clang/lib/Driver/ToolChains/Minix.cpp clang/lib/Driver/ToolChains/Myriad.cpp clang/lib/Driver/ToolChains/NaCl.cpp clang/lib/Driver/ToolChains/NetBSD.cpp clang/lib/Driver/ToolChains/OpenBSD.cpp clang/lib/Driver/ToolChains/PS4CPU.cpp clang/lib/Driver/ToolChains/RISCVToolchain.cpp clang/lib/Driver/ToolChains/Solaris.cpp clang/lib/Driver/ToolChains/WebAssembly.cpp clang/lib/Driver/ToolChains/XCore.cpp clang/unittests/Driver/ToolChainTest.cpp
Index: clang/unittests/Driver/ToolChainTest.cpp =================================================================== --- clang/unittests/Driver/ToolChainTest.cpp +++ clang/unittests/Driver/ToolChainTest.cpp @@ -259,4 +259,34 @@ EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl"); EXPECT_FALSE(Res.TargetIsValid); } + +TEST(ToolChainTest, CommandOutput) { + IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); + + IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); + struct TestDiagnosticConsumer : public DiagnosticConsumer {}; + DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer); + IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem( + new llvm::vfs::InMemoryFileSystem); + + Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags, + InMemoryFileSystem); + CCDriver.setCheckInputsExist(false); + std::unique_ptr<Compilation> CC( + CCDriver.BuildCompilation({"/home/test/bin/clang", "foo.cpp"})); + const JobList &Jobs = CC->getJobs(); + + const auto &CmdCompile = Jobs.getJobs().front(); + const auto &InFile = CmdCompile->getInputFilenames().front(); + EXPECT_STREQ(InFile, "foo.cpp"); + auto ObjFile = CmdCompile->getOutputFilenames().front(); + EXPECT_TRUE(StringRef(ObjFile).endswith(".o")); + + const auto &CmdLink = Jobs.getJobs().back(); + const auto LinkInFile = CmdLink->getInputFilenames().front(); + EXPECT_EQ(ObjFile, LinkInFile); + auto ExeFile = CmdLink->getOutputFilenames().front(); + EXPECT_EQ("a.out", ExeFile); +} + } // end anonymous namespace. Index: clang/lib/Driver/ToolChains/XCore.cpp =================================================================== --- clang/lib/Driver/ToolChains/XCore.cpp +++ clang/lib/Driver/ToolChains/XCore.cpp @@ -53,7 +53,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void tools::XCore::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -82,7 +82,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("xcc")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } /// XCore tool chain Index: clang/lib/Driver/ToolChains/WebAssembly.cpp =================================================================== --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -114,8 +114,9 @@ CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Linker, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Linker, CmdArgs, Inputs, Output)); // When optimizing, if wasm-opt is available, run it. if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { @@ -139,7 +140,7 @@ CmdArgs.push_back(Output.getFilename()); C.addCommand(std::make_unique<Command>( JA, *this, ResponseFileSupport::AtFileCurCP(), WasmOpt, CmdArgs, - Inputs)); + Inputs, Output)); } } } Index: clang/lib/Driver/ToolChains/Solaris.cpp =================================================================== --- clang/lib/Driver/ToolChains/Solaris.cpp +++ clang/lib/Driver/ToolChains/Solaris.cpp @@ -42,7 +42,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -152,7 +152,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } static StringRef getSolarisLibSuffix(const llvm::Triple &Triple) { Index: clang/lib/Driver/ToolChains/RISCVToolchain.cpp =================================================================== --- clang/lib/Driver/ToolChains/RISCVToolchain.cpp +++ clang/lib/Driver/ToolChains/RISCVToolchain.cpp @@ -191,8 +191,8 @@ CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(), - Args.MakeArgString(Linker), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker), + CmdArgs, Inputs, Output)); } // RISCV tools end. Index: clang/lib/Driver/ToolChains/PS4CPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/PS4CPU.cpp +++ clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -66,8 +66,9 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("orbis-as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } static void AddPS4SanitizerArgs(const ToolChain &TC, ArgStringList &CmdArgs) { @@ -152,8 +153,9 @@ const char *Exec = Args.MakeArgString(ToolChain.GetProgramPath("orbis-ld")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } toolchains::PS4CPU::PS4CPU(const Driver &D, const llvm::Triple &Triple, Index: clang/lib/Driver/ToolChains/OpenBSD.cpp =================================================================== --- clang/lib/Driver/ToolChains/OpenBSD.cpp +++ clang/lib/Driver/ToolChains/OpenBSD.cpp @@ -89,8 +89,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -228,8 +229,9 @@ } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } SanitizerMask OpenBSD::getSupportedSanitizers() const { Index: clang/lib/Driver/ToolChains/NetBSD.cpp =================================================================== --- clang/lib/Driver/ToolChains/NetBSD.cpp +++ clang/lib/Driver/ToolChains/NetBSD.cpp @@ -103,8 +103,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString((getToolChain().GetProgramPath("as"))); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void netbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -338,8 +339,9 @@ ToolChain.addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } /// NetBSD - NetBSD tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/NaCl.cpp =================================================================== --- clang/lib/Driver/ToolChains/NaCl.cpp +++ clang/lib/Driver/ToolChains/NaCl.cpp @@ -193,8 +193,9 @@ } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } /// NaCl Toolchain Index: clang/lib/Driver/ToolChains/Myriad.cpp =================================================================== --- clang/lib/Driver/ToolChains/Myriad.cpp +++ clang/lib/Driver/ToolChains/Myriad.cpp @@ -79,7 +79,7 @@ Args.MakeArgString(getToolChain().GetProgramPath("moviCompile")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), Args.MakeArgString(Exec), CmdArgs, - Inputs)); + Inputs, Output)); } void tools::SHAVE::Assembler::ConstructJob(Compilation &C, const JobAction &JA, @@ -115,7 +115,7 @@ Args.MakeArgString(getToolChain().GetProgramPath("moviAsm")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), Args.MakeArgString(Exec), CmdArgs, - Inputs)); + Inputs, Output)); } void tools::Myriad::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -200,9 +200,9 @@ std::string Exec = Args.MakeArgString(TC.GetProgramPath("sparc-myriad-rtems-ld")); - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(), - Args.MakeArgString(Exec), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Exec), + CmdArgs, Inputs, Output)); } MyriadToolChain::MyriadToolChain(const Driver &D, const llvm::Triple &Triple, Index: clang/lib/Driver/ToolChains/Minix.cpp =================================================================== --- clang/lib/Driver/ToolChains/Minix.cpp +++ clang/lib/Driver/ToolChains/Minix.cpp @@ -36,8 +36,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void tools::minix::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -89,8 +90,9 @@ } const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } /// Minix - Minix tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/MinGW.cpp =================================================================== --- clang/lib/Driver/ToolChains/MinGW.cpp +++ clang/lib/Driver/ToolChains/MinGW.cpp @@ -51,7 +51,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); if (Args.hasArg(options::OPT_gsplit_dwarf)) SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, @@ -168,9 +168,10 @@ // running on windows, not when operating as a cross compiler. As some users // have come to rely on this behaviour, try to replicate it. #ifdef _WIN32 - if (!llvm::sys::path::has_extension(OutputFile)) + if (!llvm::sys::path::has_extension(OutputFile)) { CmdArgs.push_back(Args.MakeArgString(Twine(OutputFile) + ".exe")); - else + OutputFile = CmdArgs.back(); + } else CmdArgs.push_back(OutputFile); #else CmdArgs.push_back(OutputFile); @@ -322,8 +323,9 @@ } } const char *Exec = Args.MakeArgString(TC.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } // Simplified from Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple. Index: clang/lib/Driver/ToolChains/MSVC.cpp =================================================================== --- clang/lib/Driver/ToolChains/MSVC.cpp +++ clang/lib/Driver/ToolChains/MSVC.cpp @@ -592,9 +592,9 @@ linkPath = TC.GetProgramPath(Linker.str().c_str()); } - auto LinkCmd = - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileUTF16(), - Args.MakeArgString(linkPath), CmdArgs, Inputs); + auto LinkCmd = std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileUTF16(), + Args.MakeArgString(linkPath), CmdArgs, Inputs, Output); if (!Environment.empty()) LinkCmd->setEnvironment(Environment); C.addCommand(std::move(LinkCmd)); @@ -734,9 +734,9 @@ CmdArgs.push_back(Fo); std::string Exec = FindVisualStudioExecutable(getToolChain(), "cl.exe"); - return std::make_unique<Command>(JA, *this, - ResponseFileSupport::AtFileUTF16(), - Args.MakeArgString(Exec), CmdArgs, Inputs); + return std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileUTF16(), Args.MakeArgString(Exec), + CmdArgs, Inputs, Output); } MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple &Triple, Index: clang/lib/Driver/ToolChains/MSP430.cpp =================================================================== --- clang/lib/Driver/ToolChains/MSP430.cpp +++ clang/lib/Driver/ToolChains/MSP430.cpp @@ -312,7 +312,7 @@ Args.AddAllArgs(CmdArgs, options::OPT_T); - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(), - Args.MakeArgString(Linker), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker), + CmdArgs, Inputs, Output)); } Index: clang/lib/Driver/ToolChains/InterfaceStubs.cpp =================================================================== --- clang/lib/Driver/ToolChains/InterfaceStubs.cpp +++ clang/lib/Driver/ToolChains/InterfaceStubs.cpp @@ -56,7 +56,7 @@ C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), Args.MakeArgString(Merger), CmdArgs, - Inputs)); + Inputs, Output)); } } // namespace ifstool } // namespace tools Index: clang/lib/Driver/ToolChains/Hexagon.cpp =================================================================== --- clang/lib/Driver/ToolChains/Hexagon.cpp +++ clang/lib/Driver/ToolChains/Hexagon.cpp @@ -189,8 +189,9 @@ } auto *Exec = Args.MakeArgString(HTC.GetProgramPath(AsName)); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void hexagon::Linker::RenderExtraToolArgs(const JobAction &JA, @@ -407,8 +408,9 @@ LinkingOutput); const char *Exec = Args.MakeArgString(HTC.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } // Hexagon tools end. Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -93,7 +93,7 @@ LldArgs.push_back(Input.getFilename()); const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Lld, LldArgs, Inputs)); + Lld, LldArgs, Inputs, Output)); } // Construct a clang-offload-bundler command to bundle code objects for @@ -120,14 +120,16 @@ BundlerArgs.push_back(Args.MakeArgString(BundlerTargetArg)); BundlerArgs.push_back(Args.MakeArgString(BundlerInputArg)); - auto BundlerOutputArg = Args.MakeArgString( - std::string("-outputs=").append(std::string(OutputFileName))); + std::string Output = std::string(OutputFileName); + auto BundlerOutputArg = + Args.MakeArgString(std::string("-outputs=").append(Output)); BundlerArgs.push_back(BundlerOutputArg); const char *Bundler = Args.MakeArgString( T.getToolChain().GetProgramPath("clang-offload-bundler")); C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(), - Bundler, BundlerArgs, Inputs)); + Bundler, BundlerArgs, Inputs, + InputInfo(&JA, Output.c_str()))); } /// Add Generated HIP Object File which has device images embedded into the @@ -197,7 +199,7 @@ McinFile, "--filetype=obj"}; const char *Mc = Args.MakeArgString(TC.GetProgramPath("llvm-mc")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Mc, McArgs, Inputs)); + Mc, McArgs, Inputs, Output)); } // For amdgcn the inputs of the linker job are device bitcode and output is Index: clang/lib/Driver/ToolChains/Gnu.cpp =================================================================== --- clang/lib/Driver/ToolChains/Gnu.cpp +++ clang/lib/Driver/ToolChains/Gnu.cpp @@ -168,8 +168,9 @@ GCCName = "gcc"; const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(GCCName)); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void tools::gcc::Preprocessor::RenderExtraToolArgs( @@ -356,8 +357,9 @@ } const char *Exec = Args.MakeArgString(getToolChain().GetStaticLibToolPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -653,8 +655,9 @@ Args.AddAllArgs(CmdArgs, options::OPT_T); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void tools::gnutools::Assembler::ConstructJob(Compilation &C, @@ -921,8 +924,9 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler)); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); // Handle the debug info splitting at object creation time if we're // creating an object. Index: clang/lib/Driver/ToolChains/Fuchsia.cpp =================================================================== --- clang/lib/Driver/ToolChains/Fuchsia.cpp +++ clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -165,7 +165,7 @@ } C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/FreeBSD.cpp =================================================================== --- clang/lib/Driver/ToolChains/FreeBSD.cpp +++ clang/lib/Driver/ToolChains/FreeBSD.cpp @@ -128,8 +128,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -359,8 +360,9 @@ ToolChain.addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } /// FreeBSD - FreeBSD tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/Flang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Flang.cpp +++ clang/lib/Driver/ToolChains/Flang.cpp @@ -70,8 +70,9 @@ const auto& D = C.getDriver(); const char* Exec = Args.MakeArgString(D.GetProgramPath("flang", TC)); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } Flang::Flang(const ToolChain &TC) : Tool("flang", "flang frontend", TC) {} Index: clang/lib/Driver/ToolChains/DragonFly.cpp =================================================================== --- clang/lib/Driver/ToolChains/DragonFly.cpp +++ clang/lib/Driver/ToolChains/DragonFly.cpp @@ -45,8 +45,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void dragonfly::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -170,8 +171,9 @@ getToolChain().addProfileRTLibs(Args, CmdArgs); const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/Darwin.cpp =================================================================== --- clang/lib/Driver/ToolChains/Darwin.cpp +++ clang/lib/Driver/ToolChains/Darwin.cpp @@ -149,7 +149,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void darwin::MachOTool::anchor() {} @@ -522,7 +522,7 @@ Args.MakeArgString(getToolChain().GetProgramPath("touch")); CmdArgs.push_back(Output.getFilename()); C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, None)); + JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, None, Output)); return; } @@ -695,7 +695,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath()); std::unique_ptr<Command> Cmd = std::make_unique<Command>( - JA, *this, ResponseSupport, Exec, CmdArgs, Inputs); + JA, *this, ResponseSupport, Exec, CmdArgs, Inputs, Output); Cmd->setInputFileList(std::move(InputFileList)); C.addCommand(std::move(Cmd)); } @@ -720,7 +720,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA, @@ -741,7 +741,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("dsymutil")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA, @@ -765,7 +765,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Index: clang/lib/Driver/ToolChains/Cuda.cpp =================================================================== --- clang/lib/Driver/ToolChains/Cuda.cpp +++ clang/lib/Driver/ToolChains/Cuda.cpp @@ -427,7 +427,7 @@ JA, *this, ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8, "--options-file"}, - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } static bool shouldIncludePTX(const ArgList &Args, const char *gpu_arch) { @@ -496,7 +496,7 @@ JA, *this, ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8, "--options-file"}, - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void NVPTX::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA, @@ -577,7 +577,7 @@ JA, *this, ResponseFileSupport{ResponseFileSupport::RF_Full, llvm::sys::WEM_UTF8, "--options-file"}, - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } /// CUDA toolchain. Our assembler is ptxas, and our "linker" is fatbinary, Index: clang/lib/Driver/ToolChains/CrossWindows.cpp =================================================================== --- clang/lib/Driver/ToolChains/CrossWindows.cpp +++ clang/lib/Driver/ToolChains/CrossWindows.cpp @@ -58,7 +58,7 @@ Exec = Args.MakeArgString(Assembler); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void tools::CrossWindows::Linker::ConstructJob( @@ -203,8 +203,9 @@ Exec = Args.MakeArgString(TC.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } CrossWindowsToolChain::CrossWindowsToolChain(const Driver &D, Index: clang/lib/Driver/ToolChains/CommonArgs.cpp =================================================================== --- clang/lib/Driver/ToolChains/CommonArgs.cpp +++ clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -897,12 +897,13 @@ InputInfo II(types::TY_Object, Output.getFilename(), Output.getFilename()); // First extract the dwo sections. - C.addCommand(std::make_unique<Command>( - JA, T, ResponseFileSupport::AtFileCurCP(), Exec, ExtractArgs, II)); + C.addCommand(std::make_unique<Command>(JA, T, + ResponseFileSupport::AtFileCurCP(), + Exec, ExtractArgs, II, Output)); // Then remove them from the original .o file. C.addCommand(std::make_unique<Command>( - JA, T, ResponseFileSupport::AtFileCurCP(), Exec, StripArgs, II)); + JA, T, ResponseFileSupport::AtFileCurCP(), Exec, StripArgs, II, Output)); } // Claim options we don't want to warn if they are unused. We do this for Index: clang/lib/Driver/ToolChains/CloudABI.cpp =================================================================== --- clang/lib/Driver/ToolChains/CloudABI.cpp +++ clang/lib/Driver/ToolChains/CloudABI.cpp @@ -92,8 +92,9 @@ CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crtend.o"))); const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } // CloudABI - CloudABI tool chain which can call ld(1) directly. Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4315,9 +4315,9 @@ II.getInputArg().renderAsInput(Args, CmdArgs); } - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileUTF8(), - D.getClangProgramPath(), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileUTF8(), D.getClangProgramPath(), + CmdArgs, Inputs, Output)); return; } @@ -6247,20 +6247,23 @@ getCLFallback()->GetCommand(C, JA, Output, Inputs, Args, LinkingOutput); C.addCommand(std::make_unique<FallbackCommand>( JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs, - std::move(CLCommand))); + Output, std::move(CLCommand))); } else if (Args.hasArg(options::OPT__SLASH_fallback) && isa<PrecompileJobAction>(JA)) { // In /fallback builds, run the main compilation even if the pch generation // fails, so that the main compilation's fallback to cl.exe runs. C.addCommand(std::make_unique<ForceSuccessCommand>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs, + Output)); } else if (D.CC1Main && !D.CCGenDiagnostics) { // Invoke the CC1 directly in this process - C.addCommand(std::make_unique<CC1Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<CC1Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } else { - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } // Make the compile command echo its inputs for /showFilenames. @@ -6998,8 +7001,9 @@ CmdArgs.push_back(Input.getFilename()); const char *Exec = getToolChain().getDriver().getClangProgramPath(); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileUTF8(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileUTF8(), + Exec, CmdArgs, Inputs, Output)); } // Begin OffloadBundler @@ -7085,7 +7089,7 @@ C.addCommand(std::make_unique<Command>( JA, *this, ResponseFileSupport::None(), TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())), - CmdArgs, None)); + CmdArgs, None, Output)); } void OffloadBundler::ConstructJobMultipleOutputs( @@ -7151,7 +7155,7 @@ C.addCommand(std::make_unique<Command>( JA, *this, ResponseFileSupport::None(), TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())), - CmdArgs, None)); + CmdArgs, None, Outputs)); } void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA, @@ -7181,5 +7185,5 @@ C.addCommand(std::make_unique<Command>( JA, *this, ResponseFileSupport::None(), Args.MakeArgString(getToolChain().GetProgramPath(getShortName())), - CmdArgs, Inputs)); + CmdArgs, Inputs, Output)); } Index: clang/lib/Driver/ToolChains/BareMetal.cpp =================================================================== --- clang/lib/Driver/ToolChains/BareMetal.cpp +++ clang/lib/Driver/ToolChains/BareMetal.cpp @@ -193,5 +193,5 @@ C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), Args.MakeArgString(TC.GetLinkerPath()), - CmdArgs, Inputs)); + CmdArgs, Inputs, Output)); } Index: clang/lib/Driver/ToolChains/Ananas.cpp =================================================================== --- clang/lib/Driver/ToolChains/Ananas.cpp +++ clang/lib/Driver/ToolChains/Ananas.cpp @@ -39,8 +39,9 @@ CmdArgs.push_back(II.getFilename()); const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } void ananas::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -124,8 +125,9 @@ } const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); - C.addCommand(std::make_unique<Command>( - JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>(JA, *this, + ResponseFileSupport::AtFileCurCP(), + Exec, CmdArgs, Inputs, Output)); } // Ananas - Ananas tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/ToolChains/AVR.cpp =================================================================== --- clang/lib/Driver/ToolChains/AVR.cpp +++ clang/lib/Driver/ToolChains/AVR.cpp @@ -142,9 +142,9 @@ CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName)); } - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(), - Args.MakeArgString(Linker), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker), + CmdArgs, Inputs, Output)); } llvm::Optional<std::string> AVRToolChain::findAVRLibcInstallation() const { Index: clang/lib/Driver/ToolChains/AMDGPU.cpp =================================================================== --- clang/lib/Driver/ToolChains/AMDGPU.cpp +++ clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -354,9 +354,9 @@ CmdArgs.push_back("-shared"); CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); - C.addCommand( - std::make_unique<Command>(JA, *this, ResponseFileSupport::AtFileCurCP(), - Args.MakeArgString(Linker), CmdArgs, Inputs)); + C.addCommand(std::make_unique<Command>( + JA, *this, ResponseFileSupport::AtFileCurCP(), Args.MakeArgString(Linker), + CmdArgs, Inputs, Output)); } void amdgpu::getAMDGPUTargetFeatures(const Driver &D, Index: clang/lib/Driver/ToolChains/AIX.cpp =================================================================== --- clang/lib/Driver/ToolChains/AIX.cpp +++ clang/lib/Driver/ToolChains/AIX.cpp @@ -71,7 +71,7 @@ const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as")); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, @@ -151,7 +151,7 @@ const char *Exec = Args.MakeArgString(ToolChain.GetLinkerPath()); C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(), - Exec, CmdArgs, Inputs)); + Exec, CmdArgs, Inputs, Output)); } /// AIX - AIX tool chain which can call as(1) and ld(1) directly. Index: clang/lib/Driver/Job.cpp =================================================================== --- clang/lib/Driver/Job.cpp +++ clang/lib/Driver/Job.cpp @@ -38,12 +38,15 @@ Command::Command(const Action &Source, const Tool &Creator, ResponseFileSupport ResponseSupport, const char *Executable, const llvm::opt::ArgStringList &Arguments, - ArrayRef<InputInfo> Inputs) + ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs) : Source(Source), Creator(Creator), ResponseSupport(ResponseSupport), Executable(Executable), Arguments(Arguments) { for (const auto &II : Inputs) if (II.isFilename()) InputFilenames.push_back(II.getFilename()); + for (const auto &II : Outputs) + if (II.isFilename()) + OutputFilenames.push_back(II.getFilename()); } /// Check if the compiler flag in question should be skipped when @@ -357,8 +360,9 @@ ResponseFileSupport ResponseSupport, const char *Executable, const llvm::opt::ArgStringList &Arguments, - ArrayRef<InputInfo> Inputs) - : Command(Source, Creator, ResponseSupport, Executable, Arguments, Inputs) { + ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs) + : Command(Source, Creator, ResponseSupport, Executable, Arguments, Inputs, + Outputs) { InProcess = true; } @@ -415,9 +419,10 @@ const char *Executable_, const llvm::opt::ArgStringList &Arguments_, ArrayRef<InputInfo> Inputs, + ArrayRef<InputInfo> Outputs, std::unique_ptr<Command> Fallback_) : Command(Source_, Creator_, ResponseSupport, Executable_, Arguments_, - Inputs), + Inputs, Outputs), Fallback(std::move(Fallback_)) {} void FallbackCommand::Print(raw_ostream &OS, const char *Terminator, @@ -456,9 +461,10 @@ ForceSuccessCommand::ForceSuccessCommand( const Action &Source_, const Tool &Creator_, ResponseFileSupport ResponseSupport, const char *Executable_, - const llvm::opt::ArgStringList &Arguments_, ArrayRef<InputInfo> Inputs) + const llvm::opt::ArgStringList &Arguments_, ArrayRef<InputInfo> Inputs, + ArrayRef<InputInfo> Outputs) : Command(Source_, Creator_, ResponseSupport, Executable_, Arguments_, - Inputs) {} + Inputs, Outputs) {} void ForceSuccessCommand::Print(raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo) const { Index: clang/include/clang/Driver/Job.h =================================================================== --- clang/include/clang/Driver/Job.h +++ clang/include/clang/Driver/Job.h @@ -122,6 +122,9 @@ /// The list of program arguments which are inputs. llvm::opt::ArgStringList InputFilenames; + /// The list of program arguments which are outputs. + std::vector<std::string> OutputFilenames; + /// Response file name, if this command is set to use one, or nullptr /// otherwise const char *ResponseFile = nullptr; @@ -158,8 +161,8 @@ Command(const Action &Source, const Tool &Creator, ResponseFileSupport ResponseSupport, const char *Executable, - const llvm::opt::ArgStringList &Arguments, - ArrayRef<InputInfo> Inputs); + const llvm::opt::ArgStringList &Arguments, ArrayRef<InputInfo> Inputs, + ArrayRef<InputInfo> Outputs); // FIXME: This really shouldn't be copyable, but is currently copied in some // error handling in Driver::generateCompilationDiagnostics. Command(const Command &) = default; @@ -201,6 +204,14 @@ const llvm::opt::ArgStringList &getArguments() const { return Arguments; } + const llvm::opt::ArgStringList &getInputFilenames() const { + return InputFilenames; + } + + const std::vector<std::string> &getOutputFilenames() const { + return OutputFilenames; + } + protected: /// Optionally print the filenames to be compiled void PrintFileNames() const; @@ -212,7 +223,7 @@ CC1Command(const Action &Source, const Tool &Creator, ResponseFileSupport ResponseSupport, const char *Executable, const llvm::opt::ArgStringList &Arguments, - ArrayRef<InputInfo> Inputs); + ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs); void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo = nullptr) const override; @@ -230,7 +241,7 @@ FallbackCommand(const Action &Source_, const Tool &Creator_, ResponseFileSupport ResponseSupport, const char *Executable_, const llvm::opt::ArgStringList &Arguments_, - ArrayRef<InputInfo> Inputs, + ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs, std::unique_ptr<Command> Fallback_); void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, @@ -250,7 +261,7 @@ ResponseFileSupport ResponseSupport, const char *Executable_, const llvm::opt::ArgStringList &Arguments_, - ArrayRef<InputInfo> Inputs); + ArrayRef<InputInfo> Inputs, ArrayRef<InputInfo> Outputs); void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo = nullptr) const override;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits