components/llvm/patches/022-google-test-harness-22643565.patch
author Stefan Teleman <stefan.teleman@oracle.com>
Wed, 10 Feb 2016 11:54:12 -0800
changeset 5434 9f55c805ce9d
permissions -rw-r--r--
PSARC/2013/188 Clang/LLVM 15777690 clang/llvm compiler infrastructure in Solaris 21851513 severe memory corruption in the LLVM command-line parsing module 22031298 toxic bugs in LLVM ilist/plist end up eliminating entire MachineBasicBlocks 22065707 LLVM SPARC assembler generator emits wrong ELF Section flags 22346218 LLVM's assembler printer on SPARC needs a lot of work 21870061 partial template specializations in CommandLine.h are buggy 21874261 the Google Test Harness doesn't know how to count threads in Solaris 21697459 memory corruption in LLVM IR Code Generator 21341968 llc on SPARC should not need to be passed -march=sparc or -march=sparcv9 21870103 TableGen makes incorrect assumptions about anonymous namespace instantiation 21870087 naming convention for the InputFile key is inconsistent across LLVM utilities 21870099 128 bytes for a filesystem path is definitely not enough 21870067 lli makes incorrect assumptions about anonymous namespace instantiation order 21870065 llc makes incorrect assumptions about anonymous namespace instantiation order 21870283 llvm::sys::Process::GetArgumentVector should overload for std::vector 21874221 clang C++ does not properly initialize the C++ Standard Library's iostreams

# - 22643565 - llvm's Google test harness needs some attention
# For upstream - maytbe.
--- utils/unittest/googletest/src/gtest-port.cc	2013-11-18 16:57:56.000000000 -0800
+++ utils/unittest/googletest/src/gtest-port.cc	2016-02-01 11:34:55.170628325 -0800
@@ -51,6 +51,13 @@
 # include <mach/vm_map.h>
 #endif  // GTEST_OS_MAC
 
+#if GTEST_OS_SOLARIS
+# include <strings.h>
+# include <sys/types.h>
+# include <dirent.h>
+# include <unistd.h>
+#endif
+
 #include "gtest/gtest-spi.h"
 #include "gtest/gtest-message.h"
 #include "gtest/internal/gtest-internal.h"
@@ -101,9 +108,36 @@
 #else
 
 size_t GetThreadCount() {
+  size_t NumThreads = 1U;
+
+#if GTEST_OS_SOLARIS
+  char lwpdir[PATH_MAX+1];
+  (void) std::memset(lwpdir, 0, sizeof(lwpdir));
+  (void) std::sprintf(lwpdir, "/proc/%i/lwp/", static_cast<int>(getpid()));
+
+  struct dirent *DE;
+  DIR *D = ::opendir(lwpdir);
+  if (!D)
+    return NumThreads;
+
+  while ((DE = ::readdir(D)) != NULL) {
+    if (DE->d_name[0] == '.') {
+      if ((DE->d_name[1] == '\0') ||
+          ((DE->d_name[1] == '.') && (DE->d_name[2] == '\0')))
+        continue;
+    }
+
+    NumThreads =
+      static_cast<size_t>(std::max<int>(NumThreads, std::atoi(DE->d_name)));
+  }
+
+  ::rewinddir(D);
+  ::closedir(D);
+#endif
+
   // There's no portable way to detect the number of threads, so we just
   // return 0 to indicate that we cannot detect it.
-  return 0;
+  return NumThreads;
 }
 
 #endif  // GTEST_OS_MAC
--- utils/unittest/googletest/include/gtest/internal/gtest-port.h	2014-02-19 07:18:30.000000000 -0800
+++ utils/unittest/googletest/include/gtest/internal/gtest-port.h	2016-02-01 11:15:20.899289723 -0800
@@ -238,7 +238,7 @@
 # endif  // ANDROID
 #elif defined __MVS__
 # define GTEST_OS_ZOS 1
-#elif defined(__sun) && defined(__SVR4)
+#elif (defined(__sun) || defined(__sun__)) && defined(__SVR4)
 # define GTEST_OS_SOLARIS 1
 #elif defined(_AIX)
 # define GTEST_OS_AIX 1