[PATCH] D54769: [FileCheck] New option -warn
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 21 08:08:58 PST 2018
SjoerdMeijer updated this revision to Diff 174933.
SjoerdMeijer added a comment.
> Is the purpose of this warning purely for testing your -warn implementation?
Yes, exactly. But I've restricted it even further, so that it will be printed only when -v is also enabled. But I most likely/definitely refactor this away as soon as we have some real warnings in.
https://reviews.llvm.org/D54769
Files:
include/llvm/Support/FileCheck.h
lib/Support/FileCheck.cpp
test/FileCheck/check-warning.txt
utils/FileCheck/FileCheck.cpp
Index: utils/FileCheck/FileCheck.cpp
===================================================================
--- utils/FileCheck/FileCheck.cpp
+++ utils/FileCheck/FileCheck.cpp
@@ -85,6 +85,10 @@
"vv", cl::init(false),
cl::desc("Print information helpful in diagnosing internal FileCheck\n"
"issues. Implies -v.\n"));
+
+static cl::opt<bool> Warn("warn", cl::init(false),
+ cl::desc("Print warning messages.\n"));
+
static const char * DumpInputEnv = "FILECHECK_DUMP_INPUT_ON_FAILURE";
static cl::opt<bool> DumpInputOnFailure(
@@ -130,6 +134,7 @@
Req.AllowEmptyInput = AllowEmptyInput;
Req.EnableVarScope = EnableVarScope;
Req.AllowDeprecatedDagOverlap = AllowDeprecatedDagOverlap;
+ Req.Warn = Warn;
Req.Verbose = Verbose;
Req.VerboseVerbose = VerboseVerbose;
Req.NoCanonicalizeWhiteSpace = NoCanonicalizeWhiteSpace;
@@ -157,7 +162,6 @@
return 2;
}
-
SourceMgr SM;
// Read the expected strings from the check file.
@@ -204,6 +208,9 @@
InputFileText, InputFile.getBufferIdentifier()),
SMLoc());
+ if (Req.Verbose)
+ FC.PrintWarning(SM, SMLoc(), "Running FileCheck with warnings enabled");
+
int ExitCode =
FC.CheckInput(SM, InputFileText, CheckStrings) ? EXIT_SUCCESS : 1;
if (ExitCode == 1 && DumpInputOnFailure)
Index: test/FileCheck/check-warning.txt
===================================================================
--- /dev/null
+++ test/FileCheck/check-warning.txt
@@ -0,0 +1,10 @@
+; RUN: FileCheck -v -warn -input-file %s %s 2>&1 | FileCheck -check-prefix=CHECK-WARNING %s
+; RUN: FileCheck -v -warn=true -input-file %s %s 2>&1 | FileCheck -check-prefix=CHECK-WARNING %s
+; RUN: FileCheck -v -warn=false -input-file %s %s 2>&1 | FileCheck -check-prefix=CHECK-QUIET %s
+
+hello world
+
+; CHECK: hello world
+
+; CHECK-WARNING: warning: Running FileCheck with warnings enabled
+; CHECK-QUIET-NOT: warning: Running FileCheck with warnings enabled
Index: lib/Support/FileCheck.cpp
===================================================================
--- lib/Support/FileCheck.cpp
+++ lib/Support/FileCheck.cpp
@@ -25,6 +25,13 @@
using namespace llvm;
+void FileCheck::PrintWarning(SourceMgr &SM, SMLoc Loc, const Twine &Msg) {
+ if (!Req.Warn)
+ return;
+
+ SM.PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
+}
+
/// Parses the given string into the Pattern.
///
/// \p Prefix provides which prefix is being matched, \p SM provides the
Index: include/llvm/Support/FileCheck.h
===================================================================
--- include/llvm/Support/FileCheck.h
+++ include/llvm/Support/FileCheck.h
@@ -35,6 +35,7 @@
bool AllowDeprecatedDagOverlap = false;
bool Verbose = false;
bool VerboseVerbose = false;
+ bool Warn = false;
};
@@ -218,6 +219,8 @@
/// Returns false if the input fails to satisfy the checks.
bool CheckInput(SourceMgr &SM, StringRef Buffer,
ArrayRef<FileCheckString> CheckStrings);
+
+ void PrintWarning(SourceMgr &SM, SMLoc Loc, const Twine &Msg);
};
} // namespace llvm
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54769.174933.patch
Type: text/x-patch
Size: 3143 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181121/ee537db6/attachment.bin>
More information about the llvm-commits
mailing list