[PATCH] D109050: [FileCheck] Use StringRef for MatchRegexp to fix crash.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 05:28:01 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa3d357e50487: [FileCheck] Use StringRef for MatchRegexp to fix crash. (authored by fhahn).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109050/new/

https://reviews.llvm.org/D109050

Files:
  llvm/lib/FileCheck/FileCheck.cpp
  llvm/test/FileCheck/invalid-regex.txt


Index: llvm/test/FileCheck/invalid-regex.txt
===================================================================
--- /dev/null
+++ llvm/test/FileCheck/invalid-regex.txt
@@ -0,0 +1,19 @@
+# This file contains invalid regular expressions in variable patterns. Make
+# sure a proper error message is presented
+//------------------------------------------------
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -check-prefix=CHECK-STAR %s < /dev/null 2>&1 | \
+RUN:   FileCheck -check-prefix=ERR-STAR %s
+
+CHECK-STAR: [[BOOM:*]]
+ERR-STAR: error: invalid regex: repetition-operator operand invalid
+
+//------------------------------------------------
+RUN: %ProtectFileCheckOutput \
+RUN: not FileCheck -check-prefix=CHECK-PLUS %s < /dev/null 2>&1 | \
+RUN:   FileCheck -check-prefix=ERR-PLUS %s
+
+CHECK-PLUS: [[BOOM:+]]
+ERR-PLUS: error: invalid regex: repetition-operator operand invalid
+
+//------------------------------------------------
Index: llvm/lib/FileCheck/FileCheck.cpp
===================================================================
--- llvm/lib/FileCheck/FileCheck.cpp
+++ llvm/lib/FileCheck/FileCheck.cpp
@@ -1034,7 +1034,8 @@
       bool IsLegacyLineExpr = false;
       StringRef DefName;
       StringRef SubstStr;
-      std::string MatchRegexp;
+      StringRef MatchRegexp;
+      std::string WildcardRegexp;
       size_t SubstInsertIdx = RegExStr.size();
 
       // Parse string variable or legacy @LINE expression.
@@ -1078,7 +1079,7 @@
             return true;
           }
           DefName = Name;
-          MatchRegexp = MatchStr.str();
+          MatchRegexp = MatchStr;
         } else {
           if (IsPseudo) {
             MatchStr = OrigMatchStr;
@@ -1117,7 +1118,8 @@
           SubstStr = MatchStr;
         else {
           ExpressionFormat Format = ExpressionPointer->getFormat();
-          MatchRegexp = cantFail(Format.getWildcardRegex());
+          WildcardRegexp = cantFail(Format.getWildcardRegex());
+          MatchRegexp = WildcardRegexp;
         }
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109050.369902.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210901/20a93f02/attachment.bin>


More information about the llvm-commits mailing list