[llvm] 6e01cd6 - Improve error message of FileCheck when stdin is empty

David Bozier via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 4 03:15:12 PST 2020


Author: David Bozier
Date: 2020-02-04T11:14:55Z
New Revision: 6e01cd6795f83c09639604871cf52f5b124c1858

URL: https://github.com/llvm/llvm-project/commit/6e01cd6795f83c09639604871cf52f5b124c1858
DIFF: https://github.com/llvm/llvm-project/commit/6e01cd6795f83c09639604871cf52f5b124c1858.diff

LOG: Improve error message of FileCheck when stdin is empty

Summary: Replace '-' in the error message with <stdin>. This is also consistent with another error message in the code.

Reviewers: jhenderson, probinson, jdenny, grimar, arichardson

Reviewed By: jhenderson

Subscribers: thopre, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D73793

Added: 
    

Modified: 
    llvm/test/FileCheck/check-empty.txt
    llvm/utils/FileCheck/FileCheck.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/FileCheck/check-empty.txt b/llvm/test/FileCheck/check-empty.txt
index da769583bee0..400cba15ecbd 100644
--- a/llvm/test/FileCheck/check-empty.txt
+++ b/llvm/test/FileCheck/check-empty.txt
@@ -17,7 +17,7 @@
 ; FOO: foo
 ; NOFOO-NOT: foo
 
-; EMPTY-ERR: FileCheck error: '-' is empty.
+; EMPTY-ERR: FileCheck error: '<stdin>' is empty.
 ; EMPTY-ERR-NEXT: FileCheck command line: {{.*}}{{F|f}}ile{{C|c}}heck{{.*}}-check-prefix={{.*}}FOO {{.*}}check-empty.txt
-; NO-EMPTY-ERR-NOT: FileCheck error: '-' is empty.
+; NO-EMPTY-ERR-NOT: FileCheck error: '<stdin>' is empty.
 ; NOT-FOUND: error: FOO: expected string not found in input

diff  --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 6f5791354ece..539bc13f946a 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -616,6 +616,8 @@ int main(int argc, char **argv) {
   // Open the file to check and add it to SourceMgr.
   ErrorOr<std::unique_ptr<MemoryBuffer>> InputFileOrErr =
       MemoryBuffer::getFileOrSTDIN(InputFilename);
+  if (InputFilename == "-")
+    InputFilename = "<stdin>"; // Overwrite for improved diagnostic messages
   if (std::error_code EC = InputFileOrErr.getError()) {
     errs() << "Could not open input file '" << InputFilename
            << "': " << EC.message() << '\n';
@@ -648,7 +650,7 @@ int main(int argc, char **argv) {
       (ExitCode == 1 && DumpInput == DumpInputFail)) {
     errs() << "\n"
            << "Input file: "
-           << (InputFilename == "-" ? "<stdin>" : InputFilename.getValue())
+           << InputFilename
            << "\n"
            << "Check file: " << CheckFilename << "\n"
            << "\n"


        


More information about the llvm-commits mailing list