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; }; Index: lib/Support/FileCheck.cpp =================================================================== --- lib/Support/FileCheck.cpp +++ lib/Support/FileCheck.cpp @@ -25,6 +25,14 @@ using namespace llvm; +static void PrintWarningInRange(SMRange MatchRange, const SourceMgr &SM, + const Twine &Msg, + const FileCheckRequest &Req) { + if (!Req.Warn) + return; + SM.PrintMessage(MatchRange.Start, SourceMgr::DK_Warning, Msg, {MatchRange}); +} + /// Parses the given string into the Pattern. /// /// \p Prefix provides which prefix is being matched, \p SM provides the @@ -1214,14 +1222,13 @@ MatchRanges.insert(MI, M); break; } - if (Req.VerboseVerbose) { - SMLoc OldStart = SMLoc::getFromPointer(Buffer.data() + MI->Pos); - SMLoc OldEnd = SMLoc::getFromPointer(Buffer.data() + MI->End); - SMRange OldRange(OldStart, OldEnd); - SM.PrintMessage(OldStart, SourceMgr::DK_Note, - "match discarded, overlaps earlier DAG match here", - {OldRange}); - } + + SMLoc OldStart = SMLoc::getFromPointer(Buffer.data() + MI->Pos); + SMLoc OldEnd = SMLoc::getFromPointer(Buffer.data() + MI->End); + SMRange OldRange(OldStart, OldEnd); + PrintWarningInRange(OldRange, SM, "match discarded, overlaps earlier " + "DAG match here", Req); + MatchPos = MI->End; } if (!Req.VerboseVerbose) Index: test/FileCheck/check-overlap-warning.txt =================================================================== --- /dev/null +++ test/FileCheck/check-overlap-warning.txt @@ -0,0 +1,12 @@ +; RUN: FileCheck -warn -input-file %s %s 2>&1 | FileCheck -check-prefix=WARNING %s + +hello world +hello world + +; CHECK-DAG: hello world +; CHECK-DAG: hello world + +; WARNING: warning: match discarded, overlaps earlier DAG match here +; WARNING-NEXT: hello world +; WARNING-NEXT: ^~~~~~~~~~~ + Index: test/FileCheck/verbose.txt =================================================================== --- test/FileCheck/verbose.txt +++ test/FileCheck/verbose.txt @@ -75,16 +75,6 @@ VV-NEXT: verbose.txt:[[@LINE-15]]:4: note: found here VV-NEXT: {{^abcdef$}} VV-NEXT: {{^ \^~~$}} -VV-NEXT: verbose.txt:[[@LINE-18]]:1: note: match discarded, overlaps earlier DAG match here -VV-NEXT: {{^}}abcdef{{$}} -VV-NEXT: {{^}}^~~~~~{{$}} - -V-NEXT: verbose.txt:[[@LINE-19]]:12: remark: {{C}}HECK-DAG: expected string found in input -V-NEXT: {{C}}HECK-DAG: def -V-NEXT: {{^ \^$}} -V-NEXT: verbose.txt:[[@LINE-24]]:4: note: found here -V-NEXT: {{^abcdef$}} -V-NEXT: {{^ \^~~$}} xyz CHECK: xyz 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 Warn("warn", cl::init(false), + cl::desc("Print warning messages.\n")); + static const char * DumpInputEnv = "FILECHECK_DUMP_INPUT_ON_FAILURE"; static cl::opt 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;