Author: Owen Pan Date: 2024-10-25T19:29:21-07:00 New Revision: 801f3a5400ca2fbcfdeb73fd744e8cce0cebc722
URL: https://github.com/llvm/llvm-project/commit/801f3a5400ca2fbcfdeb73fd744e8cce0cebc722 DIFF: https://github.com/llvm/llvm-project/commit/801f3a5400ca2fbcfdeb73fd744e8cce0cebc722.diff LOG: [clang-format] Print the names of unfound files in error messages (#113640) Also fix the return status when `-i` is used with reading from stdin. Fixes #113631. Added: clang/test/Format/error-unfound-files.cpp Modified: clang/tools/clang-format/ClangFormat.cpp Removed: ################################################################################ diff --git a/clang/test/Format/error-unfound-files.cpp b/clang/test/Format/error-unfound-files.cpp new file mode 100644 index 00000000000000..1cc57ed064fb42 --- /dev/null +++ b/clang/test/Format/error-unfound-files.cpp @@ -0,0 +1,5 @@ +// 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: diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp index 5522d05744a2b4..cc735e48725921 100644 --- a/clang/tools/clang-format/ClangFormat.cpp +++ b/clang/tools/clang-format/ClangFormat.cpp @@ -410,7 +410,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) { const bool IsSTDIN = FileName == "-"; if (!OutputXML && Inplace && IsSTDIN) { errs() << "error: cannot use -i when reading from stdin.\n"; - return false; + return true; } // On Windows, overwriting a file with an open file mapping doesn't work, // so read the whole file into memory when formatting in-place. @@ -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()); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits