diff options
author | David Stenberg <david.stenberg@ericsson.com> | 2018-05-29 13:07:58 +0000 |
---|---|---|
committer | David Stenberg <david.stenberg@ericsson.com> | 2018-05-29 13:07:58 +0000 |
commit | d45d7eae053111e8f0e33849f28e412b8b718f1c (patch) | |
tree | 518f57e98922f3c7920ccfdd0837f6d8797e13cb /clang/lib/Frontend/DependencyFile.cpp | |
parent | f6c870a794e3e09660ee86e5b1eb0b8a17f28c6d (diff) | |
download | llvm-d45d7eae053111e8f0e33849f28e412b8b718f1c.zip llvm-d45d7eae053111e8f0e33849f28e412b8b718f1c.tar.gz llvm-d45d7eae053111e8f0e33849f28e412b8b718f1c.tar.bz2 |
Fix emission of phony dependency targets when adding extra deps
Summary:
This commit fixes a bug where passing extra dependency entries
(using -fdepfile-entry) would result in -MP incorrectly emitting
a phony target for the input file, and no phony target for the
first extra dependency.
The extra dependencies are added first to the filename vector in
DFGImpl. That clashed with the emission of the phony targets, as
the code assumed that the first index always correspond to the
input file.
Reviewers: rsmith, pcc, krasin, bruno, vsapsai
Reviewed By: vsapsai
Subscribers: vsapsai, bruno, cfe-commits
Differential Revision: https://reviews.llvm.org/D44568
llvm-svn: 333413
Diffstat (limited to 'clang/lib/Frontend/DependencyFile.cpp')
-rw-r--r-- | clang/lib/Frontend/DependencyFile.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 4e60552..f89722e 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -163,6 +163,7 @@ class DFGImpl : public PPCallbacks { bool SeenMissingHeader; bool IncludeModuleFiles; DependencyOutputFormat OutputFormat; + unsigned InputFileIndex; private: bool FileMatchesDepCriteria(const char *Filename, @@ -177,9 +178,11 @@ public: AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(false), IncludeModuleFiles(Opts.IncludeModuleFiles), - OutputFormat(Opts.OutputFormat) { + OutputFormat(Opts.OutputFormat), + InputFileIndex(0) { for (const auto &ExtraDep : Opts.ExtraDeps) { - AddFilename(ExtraDep); + if (AddFilename(ExtraDep)) + ++InputFileIndex; } } @@ -201,7 +204,7 @@ public: OutputDependencyFile(); } - void AddFilename(StringRef Filename); + bool AddFilename(StringRef Filename); bool includeSystemHeaders() const { return IncludeSystemHeaders; } bool includeModuleFiles() const { return IncludeModuleFiles; } }; @@ -325,9 +328,12 @@ void DFGImpl::InclusionDirective(SourceLocation HashLoc, } } -void DFGImpl::AddFilename(StringRef Filename) { - if (FilesSet.insert(Filename).second) +bool DFGImpl::AddFilename(StringRef Filename) { + if (FilesSet.insert(Filename).second) { Files.push_back(Filename); + return true; + } + return false; } /// Print the filename, with escaping or quoting that accommodates the three @@ -463,8 +469,10 @@ void DFGImpl::OutputDependencyFile() { // Create phony targets if requested. if (PhonyTarget && !Files.empty()) { - // Skip the first entry, this is always the input file itself. - for (auto I = Files.begin() + 1, E = Files.end(); I != E; ++I) { + unsigned Index = 0; + for (auto I = Files.begin(), E = Files.end(); I != E; ++I) { + if (Index++ == InputFileIndex) + continue; OS << '\n'; PrintFilename(OS, *I, OutputFormat); OS << ":\n"; |