Skip to content

Instantly share code, notes, and snippets.

@jroelofs
Created April 1, 2020 00:21
Show Gist options
  • Save jroelofs/f651d3dd6b01714eff7defe2c1085bbf to your computer and use it in GitHub Desktop.
Save jroelofs/f651d3dd6b01714eff7defe2c1085bbf to your computer and use it in GitHub Desktop.
diff --git a/llvm/include/llvm/Support/FileCheck.h b/llvm/include/llvm/Support/FileCheck.h
index 429e36cfcbb..5925fa811ca 100644
--- a/llvm/include/llvm/Support/FileCheck.h
+++ b/llvm/include/llvm/Support/FileCheck.h
@@ -61,7 +61,10 @@ enum FileCheckKind {
CheckBadNot,
/// Marks when parsing found a -COUNT directive with invalid count value.
- CheckBadCount
+ CheckBadCount,
+
+ /// Marks when parsing found a directive followed by whitespace (not a colon)
+ CheckBadColon,
};
class FileCheckType {
diff --git a/llvm/lib/Support/FileCheck.cpp b/llvm/lib/Support/FileCheck.cpp
index 23e1ece2113..2650c251b1a 100644
--- a/llvm/lib/Support/FileCheck.cpp
+++ b/llvm/lib/Support/FileCheck.cpp
@@ -1086,6 +1086,8 @@ std::string Check::FileCheckType::getDescription(StringRef Prefix) const {
return "implicit EOF";
case Check::CheckBadNot:
return "bad NOT";
+ case Check::CheckBadColon:
+ return "bad colon";
case Check::CheckBadCount:
return "bad COUNT";
}
@@ -1104,6 +1106,9 @@ FindCheckType(StringRef Buffer, StringRef Prefix) {
if (NextChar == ':')
return {Check::CheckPlain, Rest};
+ if (NextChar == ' ' || NextChar == '\t')
+ return {Check::CheckBadColon, Rest};
+
if (NextChar != '-')
return {Check::CheckNone, StringRef()};
@@ -1144,6 +1149,9 @@ FindCheckType(StringRef Buffer, StringRef Prefix) {
Rest.startswith("EMPTY-NOT:") || Rest.startswith("NOT-EMPTY:"))
return {Check::CheckBadNot, Rest};
+ if (Rest.consume_front("NEXT") || Rest.consume_front("SAME") || Rest.consume_front("NOT") || Rest.consume_front("DAG") || Rest.consume_front("LABEL") || Rest.consume_front("EMPTY"))
+ return {Check::CheckBadColon, Rest};
+
return {Check::CheckNone, Rest};
}
@@ -1306,6 +1314,13 @@ bool FileCheck::readCheckFile(SourceMgr &SM, StringRef Buffer,
return true;
}
+ // Complain about directives that are not followed immediately by a colon.
+ if (CheckTy == Check::CheckBadColon) {
+ SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Error,
+ "colon required immediately after prefix '" + UsedPrefix + "'");
+ return true;
+ }
+
// Complain about invalid count specification.
if (CheckTy == Check::CheckBadCount) {
SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Error,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment