[llvm] r327256 - Fix compilation on Darwin with expensive checks.

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 12 04:01:06 PDT 2018


Author: jdevlieghere
Date: Mon Mar 12 04:01:05 2018
New Revision: 327256

URL: http://llvm.org/viewvc/llvm-project?rev=327256&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/Regex.cpp

Modified: llvm/trunk/lib/Support/Regex.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Regex.cpp?rev=327256&r1=327255&r2=327256&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Regex.cpp (original)
+++ llvm/trunk/lib/Support/Regex.cpp Mon Mar 12 04:01:05 2018
@@ -12,11 +12,16 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/Regex.h"
-#include "regex_impl.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #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;
 
 Regex::Regex() : preg(nullptr), error(REG_BADPAT) {}
@@ -25,7 +30,7 @@ Regex::Regex(StringRef regex, unsigned F
   unsigned flags = 0;
   preg = new llvm_regex();
   preg->re_endp = regex.end();
-  if (Flags & IgnoreCase) 
+  if (Flags & IgnoreCase)
     flags |= REG_ICASE;
   if (Flags & Newline)
     flags |= REG_NEWLINE;
@@ -51,9 +56,9 @@ Regex::~Regex() {
 bool Regex::isValid(std::string &Error) const {
   if (!error)
     return true;
-  
+
   size_t len = llvm_regerror(error, preg, nullptr, 0);
-  
+
   Error.resize(len - 1);
   llvm_regerror(error, preg, &Error[0], len);
   return false;
@@ -91,7 +96,7 @@ bool Regex::match(StringRef String, Smal
 
   if (Matches) { // match position requested
     Matches->clear();
-    
+
     for (unsigned i = 0; i != nmatch; ++i) {
       if (pm[i].rm_so == -1) {
         // this group didn't match




More information about the llvm-commits mailing list