Skip to content

Conversation

@owenca
Copy link
Contributor

@owenca owenca commented Oct 25, 2024

Also fix the return status when -i is used with reading from stdin.

Fixes #113631.

@llvmbot
Copy link
Member

llvmbot commented Oct 25, 2024

@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)

Changes

Fixes #113631.


Full diff: https://github.com/llvm/llvm-project/pull/113640.diff

2 Files Affected:

  • (added) clang/test/Format/error-unfound-files.cpp (+7)
  • (modified) clang/tools/clang-format/ClangFormat.cpp (+1-1)
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());

@owenca owenca merged commit 801f3a5 into llvm:main Oct 26, 2024
8 checks passed
@owenca owenca deleted the 113631 branch October 26, 2024 02:29
@llvm llvm deleted a comment from llvm-ci Oct 26, 2024
@llvm llvm deleted a comment from llvm-ci Oct 26, 2024
winner245 pushed a commit to winner245/llvm-project that referenced this pull request Oct 26, 2024
…vm#113640)

Also fix the return status when `-i` is used with reading from stdin.

Fixes llvm#113631.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
…vm#113640)

Also fix the return status when `-i` is used with reading from stdin.

Fixes llvm#113631.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clang-format doesn't show the names of unfound files

4 participants