aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorGeorge Karpenkov <ekarpenkov@apple.com>2018-07-20 20:21:57 +0000
committerGeorge Karpenkov <ekarpenkov@apple.com>2018-07-20 20:21:57 +0000
commit346dfbe2bce57f7d0bb27d24fe3fdd7ae1f50701 (patch)
tree209f87606d835738189c9ef40a13d21bece9efba /llvm/utils/FileCheck/FileCheck.cpp
parent7ed83591c2e33a008bdd1393892fadc080786fd0 (diff)
downloadllvm-346dfbe2bce57f7d0bb27d24fe3fdd7ae1f50701.zip
llvm-346dfbe2bce57f7d0bb27d24fe3fdd7ae1f50701.tar.gz
llvm-346dfbe2bce57f7d0bb27d24fe3fdd7ae1f50701.tar.bz2
[FileCheck] Provide an option for FileCheck to dump original input to stderr on failure
The option can be either set using environment variable (e.g. env FILECHECK_DUMP_INPUT_ON_FAILURE=1 ninja check-fuzzer) or with a FileCheck flag. This can be extremely useful for debugging, cf. https://groups.google.com/forum/#!topic/llvm-dev/kLrzg8OM_h8 for discussion. Differential Revision: https://reviews.llvm.org/D49328 llvm-svn: 337609
Diffstat (limited to 'llvm/utils/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/utils/FileCheck/FileCheck.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp
index 60b7120..b9cd99e 100644
--- a/llvm/utils/FileCheck/FileCheck.cpp
+++ b/llvm/utils/FileCheck/FileCheck.cpp
@@ -97,6 +97,13 @@ static cl::opt<bool> VerboseVerbose(
"vv", cl::init(false),
cl::desc("Print information helpful in diagnosing internal FileCheck\n"
"issues. Implies -v.\n"));
+static const char * DumpInputEnv = "FILECHECK_DUMP_INPUT_ON_FAILURE";
+
+static cl::opt<bool> DumpInputOnFailure(
+ "dump-input-on-failure", cl::init(std::getenv(DumpInputEnv)),
+ cl::desc("Dump original input to stderr before failing.\n"
+ "The value can be also controlled using\n"
+ "FILECHECK_DUMP_INPUT_ON_FAILURE environment variable.\n"));
typedef cl::list<std::string>::const_iterator prefix_iterator;
@@ -1605,5 +1612,9 @@ int main(int argc, char **argv) {
InputFileText, InputFile.getBufferIdentifier()),
SMLoc());
- return CheckInput(SM, InputFileText, CheckStrings) ? EXIT_SUCCESS : 1;
+ int ExitCode = CheckInput(SM, InputFileText, CheckStrings) ? EXIT_SUCCESS : 1;
+ if (ExitCode == 1 && DumpInputOnFailure)
+ errs() << "Full input was:\n<<<<<<\n" << InputFileText << "\n>>>>>>\n";
+
+ return ExitCode;
}