[clang] [clang-format] Print the names of unfound files in error messages (PR #113640)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 24 20:10:32 PDT 2024


https://github.com/owenca created https://github.com/llvm/llvm-project/pull/113640

Fixes #113631.

>From 274b7cbdd8989c9f34c3df4041fa9098857bcc89 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Thu, 24 Oct 2024 20:05:52 -0700
Subject: [PATCH] [clang-format] Print the names of unfound files in error
 messages

Fixes #113631.
---
 clang/test/Format/error-unfound-files.cpp | 7 +++++++
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/error-unfound-files.cpp

diff --git a/clang/test/Format/error-unfound-files.cpp b/clang/test/Format/error-unfound-files.cpp
new file mode 100644
index 00000000000000..3923c8d097443c
--- /dev/null
+++ b/clang/test/Format/error-unfound-files.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -f a.c b.c
+
+// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
+// CHECK: a.c:
+// CHECK-NEXT: b.c:
+
+// rm -f a.c b.c
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 96fb85e99bf5f0..7c54462b3795dd 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
           ? MemoryBuffer::getFileAsStream(FileName)
           : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
   if (std::error_code EC = CodeOrErr.getError()) {
-    errs() << EC.message() << "\n";
+    errs() << FileName << ": " << EC.message() << "\n";
     return true;
   }
   std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get());



More information about the cfe-commits mailing list