Add an assert() to catch possible regexp errors.

llvm-svn: 367651
This commit is contained in:
Rui Ueyama 2019-08-02 05:11:19 +00:00
parent 96a7a225f5
commit c1981b2b26
1 changed files with 6 additions and 5 deletions

View File

@ -124,13 +124,14 @@ std::string ErrorHandler::getLocation(const Twine &msg) {
std::string str = msg.str();
for (std::regex &re : regexes) {
std::smatch match;
if (!std::regex_search(str, match, re))
std::smatch m;
if (!std::regex_search(str, m, re))
continue;
assert(m.size() == 2 || m.size() == 3);
if (match.size() > 2)
return match.str(1) + "(" + match.str(2) + ")";
return match.str(1);
if (m.size() == 2)
return m.str(1);
return m.str(1) + "(" + m.str(2) + ")";
}
return logName;