[PATCH] D53710: [FileCheck] Warn if a prefix is only used in LABEL checks
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 29 03:31:02 PDT 2018
SjoerdMeijer updated this revision to Diff 171475.
SjoerdMeijer added a comment.
- Instead of a Dk_Note, it is a DK_Warning now.
- Added test cases; hopefully demonstrating that when we have a prefix list, and one of them is used, we don't issue the warning.
https://reviews.llvm.org/D53710
Files:
lib/Support/FileCheck.cpp
test/FileCheck/check-prefixes-only-labels.txt
test/FileCheck/check-prefixes-only-labels2.txt
test/FileCheck/check-prefixes-only-labels3.txt
Index: test/FileCheck/check-prefixes-only-labels3.txt
===================================================================
--- /dev/null
+++ test/FileCheck/check-prefixes-only-labels3.txt
@@ -0,0 +1,11 @@
+// RUN: FileCheck -vv -check-prefix=FOO -input-file %s %s 2>&1 | FileCheck -check-prefix=DONTWARN %s
+
+; This is a very normal test, so make sure we don't complain about it:
+;
+; DONTWARN-NOT: warning: Prefix FOO only occurs in a LABEL check, this is probably not what you want.
+foo
+bar
+
+; FOO-LABEL: foo
+; FOO: bar
+
Index: test/FileCheck/check-prefixes-only-labels2.txt
===================================================================
--- /dev/null
+++ test/FileCheck/check-prefixes-only-labels2.txt
@@ -0,0 +1,13 @@
+// RUN: FileCheck -vv -check-prefixes=FOO,BAR -input-file %s %s 2>&1 | FileCheck -check-prefix=DONTWARN %s
+
+; Prefix FOO is only checked as a label check, but BAR is checked, that's why we
+; shouldn't produce a diagnostic that there is a prefix only used in label checks:
+;
+; DONTWARN-NOT: warning: Prefix {{.*}} only occurs in a LABEL check, this is probably not what you want.
+
+foo
+; FOO-LABEL: foo
+
+bar
+; BAR: bar
+
Index: test/FileCheck/check-prefixes-only-labels.txt
===================================================================
--- /dev/null
+++ test/FileCheck/check-prefixes-only-labels.txt
@@ -0,0 +1,6 @@
+// RUN: FileCheck -check-prefix=FOO -input-file %s %s 2>&1 | FileCheck -check-prefix=WARNING %s
+
+foo
+; FOO-LABEL: foo
+
+; WARNING: warning: Prefix FOO only occurs in a LABEL check, this is probably not what you want.
Index: lib/Support/FileCheck.cpp
===================================================================
--- lib/Support/FileCheck.cpp
+++ lib/Support/FileCheck.cpp
@@ -737,6 +737,8 @@
// LineNumber keeps track of the line on which CheckPrefix instances are
// found.
unsigned LineNumber = 1;
+ bool HasNonLabelPrefix = false;
+ StringRef MatchedPrefix;
while (1) {
Check::FileCheckType CheckTy;
@@ -746,6 +748,7 @@
CheckTy);
if (UsedPrefix.empty())
break;
+ MatchedPrefix = UsedPrefix;
assert(UsedPrefix.data() == Buffer.data() &&
"Failed to move Buffer's start forward, or pointed prefix outside "
"of the buffer!");
@@ -763,8 +766,11 @@
return true;
}
- // Okay, we found the prefix, yay. Remember the rest of the line, but ignore
- // leading whitespace.
+ // Okay, we found the prefix, yay.
+ if (CheckTy != Check::CheckLabel)
+ HasNonLabelPrefix = true;
+
+ // Remember the rest of the line, but ignore leading whitespace.
if (!(Req.NoCanonicalizeWhiteSpace && Req.MatchFullLines))
Buffer = Buffer.substr(Buffer.find_first_not_of(" \t"));
@@ -840,6 +846,12 @@
return true;
}
+ if (!HasNonLabelPrefix)
+ SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()),
+ SourceMgr::DK_Warning,
+ "Prefix " + MatchedPrefix + " only occurs in a LABEL check, "
+ "this is probably not what you want.");
+
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53710.171475.patch
Type: text/x-patch
Size: 3144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181029/adf213b8/attachment.bin>
More information about the llvm-commits
mailing list