diff options
author | Adrian Prantl <aprantl@apple.com> | 2014-01-03 21:49:09 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2014-01-03 21:49:09 +0000 |
commit | 609ad7ec447f1e6beb8b51085016556cb641a83a (patch) | |
tree | 235c2384782e6caca3d69c4b1e05071c30370b3b /utils | |
parent | 077b7b14727c7110f9bdd799dfb6038def62c14d (diff) | |
download | llvm-609ad7ec447f1e6beb8b51085016556cb641a83a.tar.gz llvm-609ad7ec447f1e6beb8b51085016556cb641a83a.tar.bz2 llvm-609ad7ec447f1e6beb8b51085016556cb641a83a.tar.xz |
FileCheck: Print a nice error message for missing closing ']' in regex vars.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198449 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r-- | utils/FileCheck/FileCheck.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/utils/FileCheck/FileCheck.cpp b/utils/FileCheck/FileCheck.cpp index 893e83d61c..d33db18cb8 100644 --- a/utils/FileCheck/FileCheck.cpp +++ b/utils/FileCheck/FileCheck.cpp @@ -154,7 +154,7 @@ private: /// (right after the opening sequence). /// \return offset of the closing sequence within Str, or npos if it was not /// found. - size_t FindRegexVarEnd(StringRef Str); + size_t FindRegexVarEnd(StringRef Str, SourceMgr &SM); }; @@ -227,7 +227,7 @@ bool Pattern::ParsePattern(StringRef PatternStr, if (PatternStr.startswith("[[")) { // Find the closing bracket pair ending the match. End is going to be an // offset relative to the beginning of the match string. - size_t End = FindRegexVarEnd(PatternStr.substr(2)); + size_t End = FindRegexVarEnd(PatternStr.substr(2), SM); if (End == StringRef::npos) { SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()), @@ -532,7 +532,7 @@ void Pattern::PrintFailureInfo(const SourceMgr &SM, StringRef Buffer, } } -size_t Pattern::FindRegexVarEnd(StringRef Str) { +size_t Pattern::FindRegexVarEnd(StringRef Str, SourceMgr &SM) { // Offset keeps track of the current offset within the input Str size_t Offset = 0; // [...] Nesting depth @@ -553,7 +553,12 @@ size_t Pattern::FindRegexVarEnd(StringRef Str) { BracketDepth++; break; case ']': - assert(BracketDepth > 0 && "Invalid regex"); + if (BracketDepth == 0) { + SM.PrintMessage(SMLoc::getFromPointer(Str.data()), + SourceMgr::DK_Error, + "missing closing \"]\" for regex variable"); + exit(1); + } BracketDepth--; break; } |