From ccad3db9b95012e260c71ded41c6141619202b09 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 15 Apr 2011 18:49:23 +0000 Subject: [PATCH] Fixes a crash when generating dependency file stuff and output file is not writable. // rdar://9286457. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129587 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Frontend/DependencyFile.cpp | 2 +- test/Frontend/dependency-generation-crash.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/Frontend/dependency-generation-crash.c diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index bc5a55df08..5c3a23128a 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -171,7 +171,7 @@ void DependencyFileCallback::OutputDependencyFile() { *OS << '\n'; // Create phony targets if requested. - if (PhonyTarget) { + if (PhonyTarget && !Files.empty()) { // Skip the first entry, this is always the input file itself. for (std::vector::iterator I = Files.begin() + 1, E = Files.end(); I != E; ++I) { diff --git a/test/Frontend/dependency-generation-crash.c b/test/Frontend/dependency-generation-crash.c new file mode 100644 index 0000000000..181bb71f1b --- /dev/null +++ b/test/Frontend/dependency-generation-crash.c @@ -0,0 +1,4 @@ +// RUN: touch %t +// RUN: chmod 0 %t +// %clang -E -dependency-file bla -MT %t -MP -o %t -x c /dev/null +// rdar://9286457 -- 2.40.0