diff --git a/llvm/include/llvm/Support/FileCheck.h b/llvm/include/llvm/Support/FileCheck.h --- a/llvm/include/llvm/Support/FileCheck.h +++ b/llvm/include/llvm/Support/FileCheck.h @@ -61,7 +61,10 @@ 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 --- a/llvm/lib/Support/FileCheck.cpp +++ b/llvm/lib/Support/FileCheck.cpp @@ -1088,6 +1088,8 @@ return "bad NOT"; case Check::CheckBadCount: return "bad COUNT"; + case Check::CheckBadColon: + return "bad colon"; } llvm_unreachable("unknown FileCheckType"); } @@ -1104,6 +1106,9 @@ if (NextChar == ':') return {Check::CheckPlain, Rest}; + if (NextChar == ' ' || NextChar == '\t') + return {Check::CheckBadColon, Rest}; + if (NextChar != '-') return {Check::CheckNone, StringRef()}; @@ -1144,6 +1149,11 @@ 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 +1316,14 @@ 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 after check directive '" + UsedPrefix + + "'"); + return true; + } + // Complain about invalid count specification. if (CheckTy == Check::CheckBadCount) { SM.PrintMessage(SMLoc::getFromPointer(Buffer.data()), SourceMgr::DK_Error, diff --git a/llvm/utils/FileCheck/FileCheck.cpp b/llvm/utils/FileCheck/FileCheck.cpp --- a/llvm/utils/FileCheck/FileCheck.cpp +++ b/llvm/utils/FileCheck/FileCheck.cpp @@ -287,6 +287,8 @@ return "bad-not"; case Check::CheckBadCount: return "bad-count"; + case Check::CheckBadColon: + return "bad-colon"; case Check::CheckNone: llvm_unreachable("invalid FileCheckType"); }