Index: lib/Frontend/DependencyFile.cpp =================================================================== --- lib/Frontend/DependencyFile.cpp +++ lib/Frontend/DependencyFile.cpp @@ -162,6 +162,7 @@ bool SeenMissingHeader; bool IncludeModuleFiles; DependencyOutputFormat OutputFormat; + unsigned InputFileIndex; private: bool FileMatchesDepCriteria(const char *Filename, @@ -176,9 +177,11 @@ AddMissingHeaderDeps(Opts.AddMissingHeaderDeps), SeenMissingHeader(false), IncludeModuleFiles(Opts.IncludeModuleFiles), - OutputFormat(Opts.OutputFormat) { + OutputFormat(Opts.OutputFormat), + InputFileIndex(0) { for (const auto &ExtraDep : Opts.ExtraDeps) { AddFilename(ExtraDep); + ++InputFileIndex; } } @@ -446,8 +449,10 @@ // 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"; Index: test/Frontend/dependency-gen-extradeps-phony.c =================================================================== --- /dev/null +++ test/Frontend/dependency-gen-extradeps-phony.c @@ -0,0 +1,11 @@ +// RUN: %clang -MM -MP -Xclang -fdepfile-entry=1.extra -Xclang -fdepfile-entry=2.extra %s | FileCheck %s +// +// Verify that phony targets are only created for the extra dependency files, +// and not the input file. + +// CHECK: dependency-gen-extradeps-phony.o: 1.extra 2.extra +// CHECK-NOT: .c: +// CHECK: 1.extra: +// CHECK-NOT: .c: +// CHECK: 2.extra: +// CHECK-NOT: .c: