Fix compilation on Darwin with expensive checks.

After r327219 was landed, the bot with expensive checks on GreenDragon
started failing. The problem was missing symbols `regex_t` and
`regmatch_t` in `xlocale/_regex.h`. The latter was included because
after the change in r327219, `random` is needed, which transitively
includes `xlocale.h.` which in turn conditionally includes
`xlocale/_regex.h` when _REGEX_H_ is defined. Because this is the header
guard in `regex_impl.h` and because `regex_impl.h` was included before
the other LLVM includes, `xlocale/_regex.h` was included without the
necessary types being available.

This commit fixes this by moving the include of `regex_impl.h` all the
way down. I also added a comment to stress the significance of its
position.

llvm-svn: 327256
This commit is contained in:
Jonas Devlieghere 2018-03-12 11:01:05 +00:00
parent 9c95dfe658
commit 2b8b90a768
1 changed files with 10 additions and 5 deletions

View File

@ -12,11 +12,16 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/Regex.h" #include "llvm/Support/Regex.h"
#include "regex_impl.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h" #include "llvm/ADT/Twine.h"
#include <string> #include <string>
// Important this comes last because it defines "_REGEX_H_". At least on
// Darwin, if included before any header that (transitively) includes
// xlocale.h, this will cause trouble, because of missing regex-related types.
#include "regex_impl.h"
using namespace llvm; using namespace llvm;
Regex::Regex() : preg(nullptr), error(REG_BADPAT) {} Regex::Regex() : preg(nullptr), error(REG_BADPAT) {}
@ -25,7 +30,7 @@ Regex::Regex(StringRef regex, unsigned Flags) {
unsigned flags = 0; unsigned flags = 0;
preg = new llvm_regex(); preg = new llvm_regex();
preg->re_endp = regex.end(); preg->re_endp = regex.end();
if (Flags & IgnoreCase) if (Flags & IgnoreCase)
flags |= REG_ICASE; flags |= REG_ICASE;
if (Flags & Newline) if (Flags & Newline)
flags |= REG_NEWLINE; flags |= REG_NEWLINE;
@ -51,9 +56,9 @@ Regex::~Regex() {
bool Regex::isValid(std::string &Error) const { bool Regex::isValid(std::string &Error) const {
if (!error) if (!error)
return true; return true;
size_t len = llvm_regerror(error, preg, nullptr, 0); size_t len = llvm_regerror(error, preg, nullptr, 0);
Error.resize(len - 1); Error.resize(len - 1);
llvm_regerror(error, preg, &Error[0], len); llvm_regerror(error, preg, &Error[0], len);
return false; return false;
@ -91,7 +96,7 @@ bool Regex::match(StringRef String, SmallVectorImpl<StringRef> *Matches){
if (Matches) { // match position requested if (Matches) { // match position requested
Matches->clear(); Matches->clear();
for (unsigned i = 0; i != nmatch; ++i) { for (unsigned i = 0; i != nmatch; ++i) {
if (pm[i].rm_so == -1) { if (pm[i].rm_so == -1) {
// this group didn't match // this group didn't match