[llvm] r198449 - FileCheck: Print a nice error message for missing closing ']' in regex vars.

Adrian Prantl aprantl at apple.com
Fri Jan 3 13:49:09 PST 2014


Author: adrian
Date: Fri Jan  3 15:49:09 2014
New Revision: 198449

URL: http://llvm.org/viewvc/llvm-project?rev=198449&view=rev
Log:
FileCheck: Print a nice error message for missing closing ']' in regex vars.

Modified:
    llvm/trunk/utils/FileCheck/FileCheck.cpp

Modified: llvm/trunk/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/FileCheck/FileCheck.cpp?rev=198449&r1=198448&r2=198449&view=diff
==============================================================================
--- llvm/trunk/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/trunk/utils/FileCheck/FileCheck.cpp Fri Jan  3 15:49:09 2014
@@ -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 Pat
     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 Sou
   }
 }
 
-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(StringRe
           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;
       }





More information about the llvm-commits mailing list