
If MatchRegexp is an invalid regex, an error message will be printed using SourceManager::PrintMessage via AddRegExToRegEx. PrintMessage relies on the input being a StringRef into a string managed by SourceManager. At the moment, a StringRef to a std::string allocated in the caller of AddRegExToRegEx is passed. If the regex is invalid, this StringRef is passed to PrintMessage, where it will crash, because it does not point to a string managed via SourceMgr. This patch fixes the crash by turning MatchRegexp into a StringRef If we use MatchStr, we directly use that StringRef, which points into a string from SourceMgr. Otherwise, MatchRegexp gets assigned Format.getWildcardRegex(), which returns a std::string. To extend the lifetime, assign it to a std::string variable WildcardRegexp and assign MatchRegexp to a stringref to WildcardRegexp. WildcardRegexp should always be valid, so we should never have to print an error message via the SoureMgr I think. Fixes PR49319. Reviewed By: thopre Differential Revision: https://reviews.llvm.org/D109050
20 lines
742 B
Plaintext
20 lines
742 B
Plaintext
# 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
|
|
|
|
//------------------------------------------------
|