aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Driver/Compilation.cpp
diff options
context:
space:
mode:
authorDavid Stenberg <david.stenberg@ericsson.com>2018-05-31 09:05:22 +0000
committerDavid Stenberg <david.stenberg@ericsson.com>2018-05-31 09:05:22 +0000
commit3891885ca06a6e390fc281f59130f07d36214400 (patch)
tree3749d5e5100bbf8aaff575289e4bde460f998c8a /clang/lib/Driver/Compilation.cpp
parenta375349c53d914ab24de2af5a95d6e0455007ff2 (diff)
downloadllvm-3891885ca06a6e390fc281f59130f07d36214400.zip
llvm-3891885ca06a6e390fc281f59130f07d36214400.tar.gz
llvm-3891885ca06a6e390fc281f59130f07d36214400.tar.bz2
[Driver] Clean up tmp files when deleting Compilation objects
Summary: In rL327851 the createUniqueFile() and createTemporaryFile() variants that do not return the file descriptors were changed to create empty files, rather than only check if the paths are free. This change was done in order to make the functions race-free. That change led to clang-tidy (and possibly other tools) leaving behind temporary assembly files, of the form placeholder-*, when using a target that does not support the internal assembler. The temporary files are created when building the Compilation object in stripPositionalArgs(), as a part of creating the compilation database for the arguments after the double-dash. The files are created by Driver::GetNamedOutputPath(). Fix this issue by cleaning out temporary files at the deletion of Compilation objects. This fixes https://bugs.llvm.org/show_bug.cgi?id=37091. Reviewers: klimek, sepavloff, arphaman, aaron.ballman, john.brawn, mehdi_amini, sammccall, bkramer, alexfh, JDevlieghere Reviewed By: aaron.ballman, JDevlieghere Subscribers: erichkeane, lebedev.ri, Ka-Ka, cfe-commits Differential Revision: https://reviews.llvm.org/D45686 llvm-svn: 333637
Diffstat (limited to 'clang/lib/Driver/Compilation.cpp')
-rw-r--r--clang/lib/Driver/Compilation.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp
index 2369999..ca2525d 100644
--- a/clang/lib/Driver/Compilation.cpp
+++ b/clang/lib/Driver/Compilation.cpp
@@ -45,6 +45,11 @@ Compilation::Compilation(const Driver &D, const ToolChain &_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;
@@ -245,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();
@@ -262,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 {