diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp --- a/llvm/lib/FileCheck/FileCheck.cpp +++ b/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; } } diff --git a/llvm/test/FileCheck/invalid-regex.txt b/llvm/test/FileCheck/invalid-regex.txt new file mode 100644 --- /dev/null +++ b/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 + +//------------------------------------------------