diff options
Diffstat (limited to 'lib/Driver/Compilation.cpp')
-rw-r--r-- | lib/Driver/Compilation.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 645da5059587..ca2525dd07fb 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -1,4 +1,4 @@ -//===--- Compilation.cpp - Compilation Task Implementation ----------------===// +//===- Compilation.cpp - Compilation Task Implementation ------------------===// // // The LLVM Compiler Infrastructure // @@ -8,32 +8,48 @@ //===----------------------------------------------------------------------===// #include "clang/Driver/Compilation.h" +#include "clang/Basic/LLVM.h" #include "clang/Driver/Action.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" +#include "clang/Driver/Job.h" #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" +#include "clang/Driver/Util.h" +#include "llvm/ADT/None.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/Triple.h" #include "llvm/Option/ArgList.h" +#include "llvm/Option/OptSpecifier.h" +#include "llvm/Option/Option.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/raw_ostream.h" +#include <cassert> +#include <string> +#include <system_error> +#include <utility> -using namespace clang::driver; using namespace clang; +using namespace driver; using namespace llvm::opt; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, InputArgList *_Args, DerivedArgList *_TranslatedArgs, bool ContainsError) - : TheDriver(D), DefaultToolChain(_DefaultToolChain), ActiveOffloadMask(0u), - Args(_Args), TranslatedArgs(_TranslatedArgs), ForDiagnostics(false), - ContainsError(ContainsError) { + : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), + TranslatedArgs(_TranslatedArgs), ContainsError(ContainsError) { // The offloading host toolchain is the default toolchain. OrderedOffloadingToolchains.insert( std::make_pair(Action::OFK_Host, &DefaultToolChain)); } Compilation::~Compilation() { + // Remove temporary files. This must be done before arguments are freed, as + // the file names might be derived from the input arguments. + if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles) + CleanupFileList(TempFiles); + delete TranslatedArgs; delete Args; @@ -74,9 +90,8 @@ Compilation::getArgsForToolChain(const ToolChain *TC, StringRef BoundArch, } // Add allocated arguments to the final DAL. - for (auto ArgPtr : AllocatedArgs) { + for (auto ArgPtr : AllocatedArgs) Entry->AddSynthesizedArg(ArgPtr); - } } return *Entry; @@ -105,7 +120,7 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { // so we don't need to check again. if (IssueErrors) - getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) + getDriver().Diag(diag::err_drv_unable_to_remove_file) << EC.message(); return false; } @@ -115,9 +130,8 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { bool Compilation::CleanupFileList(const ArgStringList &Files, bool IssueErrors) const { bool Success = true; - for (ArgStringList::const_iterator - it = Files.begin(), ie = Files.end(); it != ie; ++it) - Success &= CleanupFile(*it, IssueErrors); + for (const auto &File: Files) + Success &= CleanupFile(File, IssueErrors); return Success; } @@ -125,14 +139,12 @@ bool Compilation::CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors) const { bool Success = true; - for (ArgStringMap::const_iterator - it = Files.begin(), ie = Files.end(); it != ie; ++it) { - + for (const auto &File : Files) { // If specified, only delete the files associated with the JobAction. // Otherwise, delete all files in the map. - if (JA && it->first != JA) + if (JA && File.first != JA) continue; - Success &= CleanupFile(it->second, IssueErrors); + Success &= CleanupFile(File.second, IssueErrors); } return Success; } @@ -151,7 +163,7 @@ int Compilation::ExecuteCommand(const Command &C, llvm::sys::fs::F_Append | llvm::sys::fs::F_Text); if (EC) { - getDriver().Diag(clang::diag::err_drv_cc_print_options_failure) + getDriver().Diag(diag::err_drv_cc_print_options_failure) << EC.message(); FailingCommand = &C; delete OS; @@ -173,7 +185,7 @@ int Compilation::ExecuteCommand(const Command &C, int Res = C.Execute(Redirects, &Error, &ExecutionFailed); if (!Error.empty()) { assert(Res && "Error string set with 0 result code!"); - getDriver().Diag(clang::diag::err_drv_command_failure) << Error; + getDriver().Diag(diag::err_drv_command_failure) << Error; } if (Res) @@ -186,21 +198,20 @@ using FailingCommandList = SmallVectorImpl<std::pair<int, const Command *>>; static bool ActionFailed(const Action *A, const FailingCommandList &FailingCommands) { - if (FailingCommands.empty()) return false; - // CUDA can have the same input source code compiled multiple times so do not - // compiled again if there are already failures. It is OK to abort the CUDA - // pipeline on errors. - if (A->isOffloading(Action::OFK_Cuda)) + // CUDA/HIP can have the same input source code compiled multiple times so do + // not compiled again if there are already failures. It is OK to abort the + // CUDA pipeline on errors. + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) return true; for (const auto &CI : FailingCommands) if (A == &(CI.second->getSource())) return true; - for (const Action *AI : A->inputs()) + for (const auto *AI : A->inputs()) if (ActionFailed(AI, FailingCommands)) return true; @@ -239,6 +250,10 @@ void Compilation::initCompilationForDiagnostics() { AllActions.clear(); Jobs.clear(); + // Remove temporary files. + if (!TheDriver.isSaveTempsEnabled() && !ForceKeepTempFiles) + CleanupFileList(TempFiles); + // Clear temporary/results file lists. TempFiles.clear(); ResultFiles.clear(); @@ -256,6 +271,9 @@ void Compilation::initCompilationForDiagnostics() { // Redirect stdout/stderr to /dev/null. Redirects = {None, {""}, {""}}; + + // Temporary files added by diagnostics should be kept. + ForceKeepTempFiles = true; } StringRef Compilation::getSysRoot() const { |