Revert "Fix Clang-tidy modernize-deprecated-headers warnings in remaining files; other minor fixes."

This reverts commit r265454 since it broke the build.  E.g.:

  http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_build/22413/

llvm-svn: 265459
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index e2debfc..a8e14d6 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -14,19 +14,14 @@
 
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/Hashing.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include <algorithm>
-#include <cassert>
-#include <cstdint>
 #include <cstring>
-#include <limits>
+#include <limits.h>
 
 using namespace llvm;
 
@@ -98,21 +93,18 @@
   const unsigned int maxPowerOfFiveExponent = maxExponent + maxPrecision - 1;
   const unsigned int maxPowerOfFiveParts = 2 + ((maxPowerOfFiveExponent * 815)
                                                 / (351 * integerPartWidth));
-
-} // end namespace llvm
-
-namespace {
+}
 
 /* A bunch of private, handy routines.  */
 
-inline unsigned int
+static inline unsigned int
 partCountForBits(unsigned int bits)
 {
   return ((bits) + integerPartWidth - 1) / integerPartWidth;
 }
 
 /* Returns 0U-9U.  Return values >= 10U are not digits.  */
-inline unsigned int
+static inline unsigned int
 decDigitValue(unsigned int c)
 {
   return c - '0';
@@ -123,7 +115,7 @@
 
    If the exponent overflows, returns a large exponent with the
    appropriate sign.  */
-int
+static int
 readExponent(StringRef::iterator begin, StringRef::iterator end)
 {
   bool isNegative;
@@ -167,7 +159,7 @@
 
 /* This is ugly and needs cleaning up, but I don't immediately see
    how whilst remaining safe.  */
-int
+static int
 totalExponent(StringRef::iterator p, StringRef::iterator end,
               int exponentAdjustment)
 {
@@ -216,7 +208,7 @@
   return exponent;
 }
 
-StringRef::iterator
+static StringRef::iterator
 skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end,
                            StringRef::iterator *dot)
 {
@@ -257,7 +249,7 @@
   int normalizedExponent;
 };
 
-void
+static void
 interpretDecimal(StringRef::iterator begin, StringRef::iterator end,
                  decimalInfo *D)
 {
@@ -316,7 +308,7 @@
 /* Return the trailing fraction of a hexadecimal number.
    DIGITVALUE is the first hex digit of the fraction, P points to
    the next digit.  */
-lostFraction
+static lostFraction
 trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end,
                             unsigned int digitValue)
 {
@@ -347,7 +339,7 @@
 
 /* Return the fraction lost were a bignum truncated losing the least
    significant BITS bits.  */
-lostFraction
+static lostFraction
 lostFractionThroughTruncation(const integerPart *parts,
                               unsigned int partCount,
                               unsigned int bits)
@@ -369,7 +361,7 @@
 }
 
 /* Shift DST right BITS bits noting lost fraction.  */
-lostFraction
+static lostFraction
 shiftRight(integerPart *dst, unsigned int parts, unsigned int bits)
 {
   lostFraction lost_fraction;
@@ -382,7 +374,7 @@
 }
 
 /* Combine the effect of two lost fractions.  */
-lostFraction
+static lostFraction
 combineLostFractions(lostFraction moreSignificant,
                      lostFraction lessSignificant)
 {
@@ -403,7 +395,7 @@
 
    See "How to Read Floating Point Numbers Accurately" by William D
    Clinger.  */
-unsigned int
+static unsigned int
 HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2)
 {
   assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8));
@@ -417,7 +409,7 @@
 /* The number of ulps from the boundary (zero, or half if ISNEAREST)
    when the least significant BITS are truncated.  BITS cannot be
    zero.  */
-integerPart
+static integerPart
 ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest)
 {
   unsigned int count, partBits;
@@ -462,7 +454,7 @@
 
 /* Place pow(5, power) in DST, and return the number of parts used.
    DST must be at least one part larger than size of the answer.  */
-unsigned int
+static unsigned int
 powerOf5(integerPart *dst, unsigned int power)
 {
   static const integerPart firstEightPowers[] = { 1, 5, 25, 125, 625, 3125,
@@ -525,17 +517,17 @@
 
 /* Zero at the end to avoid modular arithmetic when adding one; used
    when rounding up during hexadecimal output.  */
-const char hexDigitsLower[] = "0123456789abcdef0";
-const char hexDigitsUpper[] = "0123456789ABCDEF0";
-const char infinityL[] = "infinity";
-const char infinityU[] = "INFINITY";
-const char NaNL[] = "nan";
-const char NaNU[] = "NAN";
+static const char hexDigitsLower[] = "0123456789abcdef0";
+static const char hexDigitsUpper[] = "0123456789ABCDEF0";
+static const char infinityL[] = "infinity";
+static const char infinityU[] = "INFINITY";
+static const char NaNL[] = "nan";
+static const char NaNU[] = "NAN";
 
 /* Write out an integerPart in hexadecimal, starting with the most
    significant nibble.  Write out exactly COUNT hexdigits, return
    COUNT.  */
-unsigned int
+static unsigned int
 partAsHex (char *dst, integerPart part, unsigned int count,
            const char *hexDigitChars)
 {
@@ -553,7 +545,7 @@
 }
 
 /* Write out an unsigned decimal integer.  */
-char *
+static char *
 writeUnsignedDecimal (char *dst, unsigned int n)
 {
   char buff[40], *p;
@@ -571,7 +563,7 @@
 }
 
 /* Write out a signed decimal integer.  */
-char *
+static char *
 writeSignedDecimal (char *dst, int value)
 {
   if (value < 0) {
@@ -583,8 +575,6 @@
   return dst;
 }
 
-} // end anonymous namespace
-
 /* Constructors.  */
 void
 APFloat::initialize(const fltSemantics *ourSemantics)
@@ -862,13 +852,11 @@
 {
   return semantics.precision;
 }
-
 APFloat::ExponentType
 APFloat::semanticsMaxExponent(const fltSemantics &semantics)
 {
   return semantics.maxExponent;
 }
-
 APFloat::ExponentType
 APFloat::semanticsMinExponent(const fltSemantics &semantics)
 {
@@ -1919,6 +1907,7 @@
   return fs;
 }
 
+
 /* Comparison requires normalized numbers.  */
 APFloat::cmpResult
 APFloat::compare(const APFloat &rhs) const
@@ -2569,16 +2558,14 @@
 
   /* Check whether the normalized exponent is high enough to overflow
      max during the log-rebasing in the max-exponent check below. */
-  } else if (D.normalizedExponent - 1 >
-              std::numeric_limits<int>::max() / 42039) {
+  } else if (D.normalizedExponent - 1 > INT_MAX / 42039) {
     fs = handleOverflow(rounding_mode);
 
   /* If it wasn't, then it also wasn't high enough to overflow max
      during the log-rebasing in the min-exponent check.  Check that it
      won't overflow min in either check, then perform the min-exponent
      check. */
-  } else if ((D.normalizedExponent - 1 <
-               std::numeric_limits<int>::min() / 42039) ||
+  } else if (D.normalizedExponent - 1 < INT_MIN / 42039 ||
              (D.normalizedExponent + 1) * 28738 <=
                8651 * (semantics->minExponent - (int) semantics->precision)) {
     /* Underflow to zero and round.  */
@@ -3232,7 +3219,7 @@
   uint64_t mysignificand2 = i2 & 0xffffffffffffLL;
 
   initialize(&APFloat::IEEEquad);
-  assert(partCount() == 2);
+  assert(partCount()==2);
 
   sign = static_cast<unsigned int>(i2>>63);
   if (myexponent==0 &&
@@ -3498,7 +3485,6 @@
 }
 
 namespace {
-
   void append(SmallVectorImpl<char> &Buffer, StringRef Str) {
     Buffer.append(Str.begin(), Str.end());
   }
@@ -3535,6 +3521,7 @@
     significand = significand.trunc(significand.getActiveBits());
   }
 
+
   void AdjustToPrecision(SmallVectorImpl<char> &buffer,
                          int &exp, unsigned FormatPrecision) {
     unsigned N = buffer.size();
@@ -3579,8 +3566,7 @@
     exp += FirstSignificant;
     buffer.erase(&buffer[0], &buffer[FirstSignificant]);
   }
-
-} // end anonymous namespace
+}
 
 void APFloat::toString(SmallVectorImpl<char> &Str,
                        unsigned FormatPrecision,
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index 1c5e8d9..98865f5 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -8,23 +8,19 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/ThreadLocal.h"
-#include "llvm/Support/Threading.h"
-#include <cassert>
-#include <csetjmp>
-
+#include <setjmp.h>
 using namespace llvm;
 
 namespace {
 
 struct CrashRecoveryContextImpl;
 
-ManagedStatic<
+static ManagedStatic<
     sys::ThreadLocal<const CrashRecoveryContextImpl> > CurrentContext;
 
 struct CrashRecoveryContextImpl {
@@ -46,7 +42,6 @@
     Next = CurrentContext->get();
     CurrentContext->set(this);
   }
-
   ~CrashRecoveryContextImpl() {
     if (!SwitchedThread)
       CurrentContext->set(Next);
@@ -75,14 +70,14 @@
   }
 };
 
-ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex;
-bool gCrashRecoveryEnabled = false;
+}
 
-ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>>
+static ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex;
+static bool gCrashRecoveryEnabled = false;
+
+static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>>
        tlIsRecoveringFromCrash;
 
-} // end anonymous namespace
-
 CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {}
 
 CrashRecoveryContext::~CrashRecoveryContext() {
@@ -167,9 +162,7 @@
 // SetUnhandledExceptionFilter API, but there's a risk of that
 // being entirely overwritten (it's not a chain).
 
-namespace {
-
-LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo)
+static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo)
 {
   // Lookup the current thread local recovery object.
   const CrashRecoveryContextImpl *CRCI = CurrentContext->get();
@@ -197,9 +190,7 @@
 // CrashRecoveryContext at all.  So we make use of a thread-local
 // exception table.  The handles contained in here will either be
 // non-NULL, valid VEH handles, or NULL.
-sys::ThreadLocal<const void> sCurrentExceptionHandle;
-
-} // end anonymous namespace
+static sys::ThreadLocal<const void> sCurrentExceptionHandle;
 
 void CrashRecoveryContext::Enable() {
   sys::ScopedLock L(*gCrashRecoveryContextMutex);
@@ -248,15 +239,14 @@
 // reliable fashion -- if we get a signal outside of a crash recovery context we
 // simply disable crash recovery and raise the signal again.
 
-#include <csignal>
+#include <signal.h>
 
-namespace {
+static const int Signals[] =
+    { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP };
+static const unsigned NumSignals = array_lengthof(Signals);
+static struct sigaction PrevActions[NumSignals];
 
-const int Signals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP };
-const unsigned NumSignals = array_lengthof(Signals);
-struct sigaction PrevActions[NumSignals];
-
-void CrashRecoverySignalHandler(int Signal) {
+static void CrashRecoverySignalHandler(int Signal) {
   // Lookup the current thread local recovery object.
   const CrashRecoveryContextImpl *CRCI = CurrentContext->get();
 
@@ -288,8 +278,6 @@
     const_cast<CrashRecoveryContextImpl*>(CRCI)->HandleCrash();
 }
 
-} // end anonymous namespace
-
 void CrashRecoveryContext::Enable() {
   sys::ScopedLock L(*gCrashRecoveryContextMutex);
 
@@ -346,16 +334,14 @@
   CRCI->HandleCrash();
 }
 
-namespace {
-
 // FIXME: Portability.
-void setThreadBackgroundPriority() {
+static void setThreadBackgroundPriority() {
 #ifdef __APPLE__
   setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
 #endif
 }
 
-bool hasThreadBackgroundPriority() {
+static bool hasThreadBackgroundPriority() {
 #ifdef __APPLE__
   return getpriority(PRIO_DARWIN_THREAD, 0) == 1;
 #else
@@ -363,14 +349,16 @@
 #endif
 }
 
+namespace {
 struct RunSafelyOnThreadInfo {
   function_ref<void()> Fn;
   CrashRecoveryContext *CRC;
   bool UseBackgroundPriority;
   bool Result;
 };
+}
 
-void RunSafelyOnThread_Dispatch(void *UserData) {
+static void RunSafelyOnThread_Dispatch(void *UserData) {
   RunSafelyOnThreadInfo *Info =
     reinterpret_cast<RunSafelyOnThreadInfo*>(UserData);
 
@@ -379,9 +367,6 @@
 
   Info->Result = Info->CRC->RunSafely(Info->Fn);
 }
-
-} // end anonymous namespace
-
 bool CrashRecoveryContext::RunSafelyOnThread(function_ref<void()> Fn,
                                              unsigned RequestedStackSize) {
   bool UseBackgroundPriority = hasThreadBackgroundPriority();
diff --git a/llvm/lib/Support/Errno.cpp b/llvm/lib/Support/Errno.cpp
index 888887c..3ba2a12 100644
--- a/llvm/lib/Support/Errno.cpp
+++ b/llvm/lib/Support/Errno.cpp
@@ -14,9 +14,11 @@
 #include "llvm/Support/Errno.h"
 #include "llvm/Config/config.h"     // Get autoconf configuration settings
 #include "llvm/Support/raw_ostream.h"
-#include <cerrno>
-#include <cstring>
-#include <string>
+#include <string.h>
+
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
 
 //===----------------------------------------------------------------------===//
 //=== WARNING: Implementation here must contain only TRULY operating system
@@ -30,7 +32,7 @@
 std::string StrError() {
   return StrError(errno);
 }
-#endif // HAVE_ERRNO_H
+#endif  // HAVE_ERRNO_H
 
 std::string StrError(int errnum) {
   std::string str;
@@ -70,5 +72,5 @@
   return str;
 }
 
-} // namespace sys
-} // namespace llvm
+}  // namespace sys
+}  // namespace llvm
diff --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 5962e5e..1ca8eac 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -19,8 +19,8 @@
 #include "llvm/Config/config.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/FileSystem.h"
-#include <cstring>
-#include <string>
+#include "llvm/Support/raw_ostream.h"
+#include <string.h>
 
 // Include the platform-specific parts of this class.
 #ifdef LLVM_ON_UNIX
@@ -49,10 +49,8 @@
 
 using namespace llvm;
 
-namespace {
-
 #if defined(__linux__)
-ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) {
+static ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) {
   // Note: We cannot mmap /proc/cpuinfo here and then process the resulting
   // memory buffer because the 'file' has 0 size (it can be read from only
   // as a stream).
@@ -76,8 +74,8 @@
 
 /// GetX86CpuIDAndInfo - Execute the specified cpuid and return the 4 values in the
 /// specified arguments.  If we can't run cpuid on the host, return true.
-bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
-                        unsigned *rECX, unsigned *rEDX) {
+static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX,
+                               unsigned *rECX, unsigned *rEDX) {
 #if defined(__GNUC__) || defined(__clang__)
   #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
     // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
@@ -122,8 +120,9 @@
 /// GetX86CpuIDAndInfoEx - Execute the specified cpuid with subleaf and return the
 /// 4 values in the specified arguments.  If we can't run cpuid on the host,
 /// return true.
-bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, unsigned *rEAX,
-                          unsigned *rEBX, unsigned *rECX, unsigned *rEDX) {
+static bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf,
+                                 unsigned *rEAX, unsigned *rEBX, unsigned *rECX,
+                                 unsigned *rEDX) {
 #if defined(__x86_64__) || defined(_M_AMD64) || defined (_M_X64)
   #if defined(__GNUC__)
     // gcc doesn't know cpuid would clobber ebx/rbx. Preseve it manually.
@@ -183,7 +182,7 @@
 #endif
 }
 
-bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) {
+static bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) {
 #if defined(__GNUC__)
   // Check xgetbv; this uses a .byte sequence instead of the instruction
   // directly because older assemblers do not include support for xgetbv and
@@ -200,7 +199,8 @@
 #endif
 }
 
-void DetectX86FamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) {
+static void DetectX86FamilyModel(unsigned EAX, unsigned &Family,
+                                 unsigned &Model) {
   Family = (EAX >> 8) & 0xf; // Bits 8 - 11
   Model  = (EAX >> 4) & 0xf; // Bits 4 - 7
   if (Family == 6 || Family == 0xf) {
@@ -212,8 +212,6 @@
   }
 }
 
-} // end anonymous namespace
-
 StringRef sys::getHostCPUName() {
   unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0;
   if (GetX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX))
diff --git a/llvm/lib/Support/MathExtras.cpp b/llvm/lib/Support/MathExtras.cpp
index 6b9d048..ba09245 100644
--- a/llvm/lib/Support/MathExtras.cpp
+++ b/llvm/lib/Support/MathExtras.cpp
@@ -1,4 +1,4 @@
-//===-- MathExtras.cpp - Implement the MathExtras header ------------------===//
+//===-- MathExtras.cpp - Implement the MathExtras header --------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -16,7 +16,7 @@
 #ifdef _MSC_VER
 #include <limits>
 #else
-#include <cmath>
+#include <math.h>
 #endif
 
 namespace llvm {
@@ -29,4 +29,4 @@
   const float huge_valf = HUGE_VALF;
 #endif
 
-} // end namespace llvm
+}
diff --git a/llvm/lib/Support/Mutex.cpp b/llvm/lib/Support/Mutex.cpp
index db30c73..c8d3844 100644
--- a/llvm/lib/Support/Mutex.cpp
+++ b/llvm/lib/Support/Mutex.cpp
@@ -22,26 +22,22 @@
 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
 // Define all methods as no-ops if threading is explicitly disabled
 namespace llvm {
-
 using namespace sys;
-
 MutexImpl::MutexImpl( bool recursive) { }
 MutexImpl::~MutexImpl() { }
 bool MutexImpl::acquire() { return true; }
 bool MutexImpl::release() { return true; }
 bool MutexImpl::tryacquire() { return true; }
-
-} // end namespace llvm
+}
 #else
 
 #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_MUTEX_LOCK)
 
 #include <cassert>
-#include <cstdlib>
 #include <pthread.h>
+#include <stdlib.h>
 
 namespace llvm {
-
 using namespace sys;
 
 // Construct a Mutex using pthread calls
@@ -114,7 +110,7 @@
   return errorcode == 0;
 }
 
-} // end namespace llvm
+}
 
 #elif defined(LLVM_ON_UNIX)
 #include "Unix/Mutex.inc"
diff --git a/llvm/lib/Support/RWMutex.cpp b/llvm/lib/Support/RWMutex.cpp
index 2a3239a..3b6309c 100644
--- a/llvm/lib/Support/RWMutex.cpp
+++ b/llvm/lib/Support/RWMutex.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/Config/config.h"
 #include "llvm/Support/RWMutex.h"
+#include <cstring>
 
 //===----------------------------------------------------------------------===//
 //=== WARNING: Implementation here must contain only TRULY operating system
@@ -22,27 +23,23 @@
 #if !defined(LLVM_ENABLE_THREADS) || LLVM_ENABLE_THREADS == 0
 // Define all methods as no-ops if threading is explicitly disabled
 namespace llvm {
-
 using namespace sys;
-
 RWMutexImpl::RWMutexImpl() { }
 RWMutexImpl::~RWMutexImpl() { }
 bool RWMutexImpl::reader_acquire() { return true; }
 bool RWMutexImpl::reader_release() { return true; }
 bool RWMutexImpl::writer_acquire() { return true; }
 bool RWMutexImpl::writer_release() { return true; }
-
-} // end namespace llvm
+}
 #else
 
 #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_RWLOCK_INIT)
 
 #include <cassert>
-#include <cstdlib>
 #include <pthread.h>
+#include <stdlib.h>
 
 namespace llvm {
-
 using namespace sys;
 
 // Construct a RWMutex using pthread calls
@@ -116,7 +113,7 @@
   return errorcode == 0;
 }
 
-} // end namespace llvm
+}
 
 #elif defined(LLVM_ON_UNIX)
 #include "Unix/RWMutex.inc"
diff --git a/llvm/lib/Support/SHA1.cpp b/llvm/lib/Support/SHA1.cpp
index 5ff2eed..980c3bb 100644
--- a/llvm/lib/Support/SHA1.cpp
+++ b/llvm/lib/Support/SHA1.cpp
@@ -1,4 +1,4 @@
-//===--- SHA1.h - Private copy of the SHA1 implementation -------*- C++ -*-===//
+//======- SHA1.h - Private copy of the SHA1 implementation ---*- C++ -* ======//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -13,14 +13,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/SHA1.h"
-
-#include <cstring>
-
 using namespace llvm;
 
+#include <stdint.h>
+#include <string.h>
+
 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
 #define SHA_BIG_ENDIAN
 #endif
@@ -47,14 +46,10 @@
   InternalState.BufferOffset = 0;
 }
 
-namespace {
-
-uint32_t rol32(uint32_t number, uint8_t bits) {
+static uint32_t rol32(uint32_t number, uint8_t bits) {
   return ((number << bits) | (number >> (32 - bits)));
 }
 
-} // end anonymous namespace
-
 void SHA1::hashBlock() {
   uint8_t i;
   uint32_t a, b, c, d, e, t;
diff --git a/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp b/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp
index 711760b..55f3320 100644
--- a/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp
+++ b/llvm/lib/Support/SearchForAddressOfSpecialSymbol.cpp
@@ -14,12 +14,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <cstring>
-
-namespace {
+#include <string.h>
 
 // Must declare the symbols in the global namespace.
-void *DoSearch(const char* symbolName) {
+static void *DoSearch(const char* symbolName) {
 #define EXPLICIT_SYMBOL(SYM) \
    extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
 
@@ -53,12 +51,8 @@
   return nullptr;
 }
 
-} // end anonymous namespace
-
 namespace llvm {
-
 void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
   return DoSearch(symbolName);
 }
-
-} // end namespace llvm
+}  // namespace llvm
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc
index 8d1dfc7..3cedf64 100644
--- a/llvm/lib/Support/Unix/Path.inc
+++ b/llvm/lib/Support/Unix/Path.inc
@@ -17,9 +17,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "Unix.h"
-#include <cassert>
-#include <climits>
-#include <cstdio>
+#include <limits.h>
+#include <stdio.h>
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -87,10 +86,7 @@
 #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
     defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
     defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__)
-
-namespace {
-
-int
+static int
 test_dir(char ret[PATH_MAX], const char *dir, const char *bin)
 {
   struct stat sb;
@@ -105,7 +101,7 @@
   return 0;
 }
 
-char *
+static char *
 getprogpath(char ret[PATH_MAX], const char *bin)
 {
   char *pv, *s, *t;
@@ -142,9 +138,6 @@
   free(pv);
   return nullptr;
 }
-
-} // end anonymous namespace
-
 #endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__
 
 /// GetMainExecutable - Return the path to the main executable, given the
@@ -337,9 +330,7 @@
   return std::error_code();
 }
 
-namespace {
-
-int convertAccessMode(AccessMode Mode) {
+static int convertAccessMode(AccessMode Mode) {
   switch (Mode) {
   case AccessMode::Exist:
     return F_OK;
@@ -351,8 +342,6 @@
   llvm_unreachable("invalid enum");
 }
 
-} // end anonymous namespace
-
 std::error_code access(const Twine &Path, AccessMode Mode) {
   SmallString<128> PathStorage;
   StringRef P = Path.toNullTerminatedStringRef(PathStorage);
@@ -392,10 +381,8 @@
   return std::error_code();
 }
 
-namespace {
-
-std::error_code fillStatus(int StatRet, const struct stat &Status,
-                           file_status &Result) {
+static std::error_code fillStatus(int StatRet, const struct stat &Status,
+                             file_status &Result) {
   if (StatRet != 0) {
     std::error_code ec(errno, std::generic_category());
     if (ec == errc::no_such_file_or_directory)
@@ -429,8 +416,6 @@
   return std::error_code();
 }
 
-} // end anonymous namespace
-
 std::error_code status(const Twine &Path, file_status &Result) {
   SmallString<128> PathStorage;
   StringRef P = Path.toNullTerminatedStringRef(PathStorage);
@@ -612,9 +597,7 @@
   return false;
 }
 
-namespace {
-
-bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
+static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
   #if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
   // On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR.
   // macros defined in <unistd.h> on darwin >= 9
@@ -639,7 +622,7 @@
   return false;
 }
 
-bool getUserCacheDir(SmallVectorImpl<char> &Result) {
+static bool getUserCacheDir(SmallVectorImpl<char> &Result) {
   // First try using XDG_CACHE_HOME env variable,
   // as specified in XDG Base Directory Specification at
   // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
@@ -662,7 +645,7 @@
   return false;
 }
 
-const char *getEnvTempDir() {
+static const char *getEnvTempDir() {
   // Check whether the temporary directory is specified by an environment
   // variable.
   const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"};
@@ -674,7 +657,7 @@
   return nullptr;
 }
 
-const char *getDefaultTempDir(bool ErasedOnReboot) {
+static const char *getDefaultTempDir(bool ErasedOnReboot) {
 #ifdef P_tmpdir
   if ((bool)P_tmpdir)
     return P_tmpdir;
@@ -685,8 +668,6 @@
   return "/var/tmp";
 }
 
-} // end anonymous namespace
-
 void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) {
   Result.clear();
 
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 350b145..cad81f8 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -30,7 +30,9 @@
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#include <csignal>
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 // DragonFlyBSD, OpenBSD, and Bitrig have deprecated <malloc.h> for
 // <stdlib.h> instead. Unix.h includes this for us already.
 #if defined(HAVE_MALLOC_H) && !defined(__DragonFly__) && \
@@ -58,9 +60,7 @@
 using namespace llvm;
 using namespace sys;
 
-namespace {
-
-std::pair<TimeValue, TimeValue> getRUsageTimes() {
+static std::pair<TimeValue, TimeValue> getRUsageTimes() {
 #if defined(HAVE_GETRUSAGE)
   struct rusage RU;
   ::getrusage(RUSAGE_SELF, &RU);
@@ -79,8 +79,6 @@
 #endif
 }
 
-} // end anonymous namespace
-
 // On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
 // offset in mmap(3) should be aligned to the AllocationGranularity.
 unsigned Process::getPageSize() {
@@ -191,7 +189,6 @@
 }
 
 namespace {
-
 class FDCloser {
 public:
   FDCloser(int &FD) : FD(FD), KeepOpen(false) {}
@@ -208,8 +205,7 @@
   int &FD;
   bool KeepOpen;
 };
-
-} // end anonymous namespace
+}
 
 std::error_code Process::FixupStandardFileDescriptors() {
   int NullFD = -1;
@@ -304,9 +300,7 @@
 #endif
 }
 
-namespace {
-
-unsigned getColumns(int FileID) {
+static unsigned getColumns(int FileID) {
   // If COLUMNS is defined in the environment, wrap to that many columns.
   if (const char *ColumnsStr = std::getenv("COLUMNS")) {
     int Columns = std::atoi(ColumnsStr);
@@ -326,8 +320,6 @@
   return Columns;
 }
 
-} // end anonymous namespace
-
 unsigned Process::StandardOutColumns() {
   if (!StandardOutIsDisplayed())
     return 0;
@@ -352,13 +344,11 @@
 extern "C" int tigetnum(char *capname);
 #endif
 
-namespace {
-
 #ifdef HAVE_TERMINFO
-ManagedStatic<sys::Mutex> TermColorMutex;
+static ManagedStatic<sys::Mutex> TermColorMutex;
 #endif
 
-bool terminalHasColors(int fd) {
+static bool terminalHasColors(int fd) {
 #ifdef HAVE_TERMINFO
   // First, acquire a global lock because these C routines are thread hostile.
   MutexGuard G(*TermColorMutex);
@@ -398,8 +388,6 @@
   return false;
 }
 
-} // end anonymous namespace
-
 bool Process::FileDescriptorHasColors(int fd) {
   // A file descriptor has colors if it is displayed and the terminal has
   // colors.
@@ -440,10 +428,7 @@
 }
 
 #if !defined(HAVE_DECL_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM
-
-namespace {
-
-unsigned GetRandomNumberSeed() {
+static unsigned GetRandomNumberSeed() {
   // Attempt to get the initial seed from /dev/urandom, if possible.
   int urandomFD = open("/dev/urandom", O_RDONLY);
 
@@ -465,9 +450,6 @@
   TimeValue Now = TimeValue::now();
   return hash_combine(Now.seconds(), Now.nanoseconds(), ::getpid());
 }
-
-} // end anonymous namespace
-
 #endif
 
 unsigned llvm::sys::Process::GetRandomNumber() {
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc
index ee7df0a..7d3537e 100644
--- a/llvm/lib/Support/Unix/Program.inc
+++ b/llvm/lib/Support/Unix/Program.inc
@@ -1,4 +1,4 @@
-//===- llvm/Support/Unix/Program.cpp ----------------------------*- C++ -*-===//
+//===- llvm/Support/Unix/Program.cpp -----------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -30,7 +30,9 @@
 #if HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
-#include <csignal>
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #if HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -94,9 +96,7 @@
   return errc::no_such_file_or_directory;
 }
 
-namespace {
-
-bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) {
+static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) {
   if (!Path) // Noop
     return false;
   std::string File;
@@ -125,8 +125,8 @@
 }
 
 #ifdef HAVE_POSIX_SPAWN
-bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg,
-                   posix_spawn_file_actions_t *FileActions) {
+static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg,
+                          posix_spawn_file_actions_t *FileActions) {
   if (!Path) // Noop
     return false;
   const char *File;
@@ -144,10 +144,10 @@
 }
 #endif
 
-void TimeOutHandler(int Sig) {
+static void TimeOutHandler(int Sig) {
 }
 
-void SetMemoryLimits (unsigned size)
+static void SetMemoryLimits (unsigned size)
 {
 #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT
   struct rlimit r;
@@ -176,9 +176,7 @@
 #endif
 }
 
-} // end anonymous namespace
-
-} // end namespace llvm
+}
 
 static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
                     const char **envp, const StringRef **redirects,
@@ -421,12 +419,12 @@
   return WaitResult;
 }
 
-std::error_code sys::ChangeStdinToBinary() {
+  std::error_code sys::ChangeStdinToBinary(){
   // Do nothing, as Unix doesn't differentiate between text and binary.
     return std::error_code();
 }
 
-std::error_code sys::ChangeStdoutToBinary() {
+  std::error_code sys::ChangeStdoutToBinary(){
   // Do nothing, as Unix doesn't differentiate between text and binary.
     return std::error_code();
 }
@@ -468,5 +466,4 @@
   }
   return true;
 }
-
-} // end namespace llvm
+}
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 8be91cd..061cdb3 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -1,4 +1,4 @@
-//===- Signals.cpp - Generic Unix Signals Implementation --------*- C++ -*-===//
+//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -27,7 +27,9 @@
 #if HAVE_EXECINFO_H
 # include <execinfo.h>         // For backtrace().
 #endif
-#include <csignal>
+#if HAVE_SIGNAL_H
+#include <signal.h>
+#endif
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
@@ -46,27 +48,25 @@
 
 using namespace llvm;
 
-namespace {
+static RETSIGTYPE SignalHandler(int Sig);  // defined below.
 
-RETSIGTYPE SignalHandler(int Sig);  // defined below.
-
-ManagedStatic<SmartMutex<true> > SignalsMutex;
+static ManagedStatic<SmartMutex<true> > SignalsMutex;
 
 /// InterruptFunction - The function to call if ctrl-c is pressed.
-void (*InterruptFunction)() = nullptr;
+static void (*InterruptFunction)() = nullptr;
 
-ManagedStatic<std::vector<std::string>> FilesToRemove;
+static ManagedStatic<std::vector<std::string>> FilesToRemove;
 
 // IntSigs - Signals that represent requested termination. There's no bug
 // or failure, or if there is, it's not our direct responsibility. For whatever
 // reason, our continued execution is no longer desirable.
-const int IntSigs[] = {
+static const int IntSigs[] = {
   SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
 };
 
 // KillSigs - Signals that represent that we have a bug, and our prompt
 // termination has been ordered.
-const int KillSigs[] = {
+static const int KillSigs[] = {
   SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT
 #ifdef SIGSYS
   , SIGSYS
@@ -82,13 +82,14 @@
 #endif
 };
 
-unsigned NumRegisteredSignals = 0;
-struct {
+static unsigned NumRegisteredSignals = 0;
+static struct {
   struct sigaction SA;
   int SigNo;
 } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)];
 
-void RegisterHandler(int Signal) {
+
+static void RegisterHandler(int Signal) {
   assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) &&
          "Out of space for signal handlers!");
 
@@ -105,7 +106,7 @@
   ++NumRegisteredSignals;
 }
 
-void RegisterHandlers() {
+static void RegisterHandlers() {
   // We need to dereference the signals mutex during handler registration so
   // that we force its construction. This is to prevent the first use being
   // during handling an actual signal because you can't safely call new in a
@@ -119,7 +120,7 @@
   for (auto S : KillSigs) RegisterHandler(S);
 }
 
-void UnregisterHandlers() {
+static void UnregisterHandlers() {
   // Restore all of the signal handlers to how they were before we showed up.
   for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i)
     sigaction(RegisteredSignalInfo[i].SigNo,
@@ -127,11 +128,12 @@
   NumRegisteredSignals = 0;
 }
 
+
 /// RemoveFilesToRemove - Process the FilesToRemove list. This function
 /// should be called with the SignalsMutex lock held.
 /// NB: This must be an async signal safe function. It cannot allocate or free
 /// memory, even in debug builds.
-void RemoveFilesToRemove() {
+static void RemoveFilesToRemove() {
   // Avoid constructing ManagedStatic in the signal handler.
   // If FilesToRemove is not constructed, there are no files to remove.
   if (!FilesToRemove.isConstructed())
@@ -162,7 +164,7 @@
 }
 
 // SignalHandler - The signal handler that runs.
-RETSIGTYPE SignalHandler(int Sig) {
+static RETSIGTYPE SignalHandler(int Sig) {
   // Restore the signal behavior to default, so that the program actually
   // crashes when we return and the signal reissues.  This also ensures that if
   // we crash in our signal handler that the program will terminate immediately
@@ -207,8 +209,6 @@
 #endif
 }
 
-} // end anonymous namespace
-
 void llvm::sys::RunInterruptHandlers() {
   sys::SmartScopedLock<true> Guard(*SignalsMutex);
   RemoveFilesToRemove();
@@ -264,9 +264,7 @@
   const char *main_exec_name;
 };
 
-namespace {
-
-int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
+static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
   DlIteratePhdrData *data = (DlIteratePhdrData*)arg;
   const char *name = data->first ? data->main_exec_name : info->dlpi_name;
   data->first = false;
@@ -289,8 +287,6 @@
   return 0;
 }
 
-} // end anonymous namespace
-
 /// If this is an ELF platform, we can find all loaded modules and their virtual
 /// addresses with dl_iterate_phdr.
 static bool findModulesAndOffsets(void **StackTrace, int Depth,
@@ -379,14 +375,10 @@
 #endif
 }
 
-namespace {
-
-void PrintStackTraceSignalHandler(void *) {
+static void PrintStackTraceSignalHandler(void *) {
   PrintStackTrace(llvm::errs());
 }
 
-} // end anonymous namespace
-
 void llvm::sys::DisableSystemDialogsOnCrash() {}
 
 /// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or
@@ -411,6 +403,9 @@
 #endif
 }
 
+
+/***/
+
 // On Darwin, raise sends a signal to the main thread instead of the current
 // thread. This has the unfortunate effect that assert() and abort() will end up
 // bypassing our crash recovery attempts. We work around this for anything in
diff --git a/llvm/lib/Support/Unix/ThreadLocal.inc b/llvm/lib/Support/Unix/ThreadLocal.inc
index 78c694c..31c3f38 100644
--- a/llvm/lib/Support/Unix/ThreadLocal.inc
+++ b/llvm/lib/Support/Unix/ThreadLocal.inc
@@ -19,11 +19,10 @@
 #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC)
 
 #include <cassert>
-#include <cstdlib>
 #include <pthread.h>
+#include <stdlib.h>
 
 namespace llvm {
-
 using namespace sys;
 
 ThreadLocalImpl::ThreadLocalImpl() : data() {
@@ -57,19 +56,14 @@
   setInstance(nullptr);
 }
 
-} // end namespace llvm
+}
 #else
-
 namespace llvm {
-
 using namespace sys;
-
 ThreadLocalImpl::ThreadLocalImpl() : data() { }
 ThreadLocalImpl::~ThreadLocalImpl() { }
 void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
 void *ThreadLocalImpl::getInstance() { return data; }
 void ThreadLocalImpl::removeInstance() { setInstance(0); }
-
-} // end namespace llvm
-
+}
 #endif
diff --git a/llvm/lib/Support/Unix/Unix.h b/llvm/lib/Support/Unix/Unix.h
index 832d65b..871e612 100644
--- a/llvm/lib/Support/Unix/Unix.h
+++ b/llvm/lib/Support/Unix/Unix.h
@@ -1,4 +1,4 @@
-//===- llvm/Support/Unix/Unix.h - Common Unix Include File ------*- C++ -*-===//
+//===- llvm/Support/Unix/Unix.h - Common Unix Include File -------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -22,7 +22,7 @@
 #include "llvm/Config/config.h"     // Get autoconf configuration settings
 #include "llvm/Support/Errno.h"
 #include <algorithm>
-#include <cassert>
+#include <assert.h>
 #include <cerrno>
 #include <cstdio>
 #include <cstdlib>
@@ -42,7 +42,7 @@
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
 #endif
-#include <ctime>
+#include <time.h>
 
 #ifdef HAVE_DLFCN_H
 # include <dlfcn.h>
@@ -65,4 +65,4 @@
   return true;
 }
 
-#endif // LLVM_LIB_SUPPORT_UNIX_UNIX_H
+#endif