llvm-project/llvm/test/FileCheck
Florian Hahn a3d357e504
[FileCheck] Use StringRef for MatchRegexp to fix crash.
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
2021-09-01 14:27:14 +02:00
..
Inputs
comment
dump-input Fix PR46880: Fail CHECK-NOT with undefined variable 2021-04-20 14:42:46 +01:00
match-time-error-propagation Fix PR46880: Fail CHECK-NOT with undefined variable 2021-04-20 14:42:46 +01:00
allow-unused-prefixes.txt
bad-char.txt
check-a-b-has-b.txt
check-b-a-has-b.txt
check-count.txt
check-dag-multi-prefix-2.txt
check-dag-multi-prefix.txt
check-dag-not-dag.txt
check-dag-overlap-torture.txt
check-dag-overlap.txt
check-dag-substring-prefix.txt
check-dag-xfails.txt
check-dag.txt
check-empty-tag.txt
check-empty.txt
check-empty2.txt
check-ignore-case.txt
check-label-dag-capture.txt
check-label-dag.txt
check-label.txt
check-literal.txt
check-multi-prefix-label.txt
check-multiple-prefixes-mixed.txt
check-multiple-prefixes-nomatch-2.txt
check-multiple-prefixes-nomatch.txt
check-multiple-prefixes-substr.txt
check-not-diaginfo.txt
check-prefixes.txt
check-substring-multi-prefix-2.txt
check-substring-multi-prefix.txt
dos-style-eol.txt
empty-regex-match-at-start.txt
envvar-opts.txt
first-character-match.txt
implicit-check-not.txt
invalid-regex.txt [FileCheck] Use StringRef for MatchRegexp to fix crash. 2021-09-01 14:27:14 +02:00
line-count-2.txt
line-count.txt
lit.local.cfg
match-full-lines.txt
multiple-check-not-failures.txt
multiple-missing-prefixes.txt
next-no-match.txt
no-check-file.txt
no-multi-suffixes.txt
numeric-defines-diagnostics.txt
numeric-defines.txt
numeric-expression.txt Fix PR46880: Fail CHECK-NOT with undefined variable 2021-04-20 14:42:46 +01:00
opt-color.txt
regex-brackets.txt
regex-no-match.txt
same.txt
separate-multi-prefix.txt
simple-var-capture.txt [FileCheck] Fix PR49531: invalid use of string var 2021-03-24 18:49:58 +00:00
string-defines-diagnostics.txt
string-defines.txt
two-checks-for-same-match.txt
validate-check-prefix.txt
var-ref-same-line.txt
var-scope.txt Fix PR46880: Fail CHECK-NOT with undefined variable 2021-04-20 14:42:46 +01:00
verbose.txt