diff options
author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-05 20:45:04 +0000 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-04-05 20:45:04 +0000 |
commit | 2707ee3256a654e8d40bd9082e6047c65a5e3283 (patch) | |
tree | a257f62d4c2218352d645eefc0746d45e19f3e48 | |
parent | f45d3278d3dbc6fdff47a57213c9267d72289f17 (diff) |
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/
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265459 91177308-0d34-0410-b5e6-96231b3b80d8
30 files changed, 323 insertions, 523 deletions
diff --git a/lib/Support/APFloat.cpp b/lib/Support/APFloat.cpp index e2debfc5466..a8e14d6c08b 100644 --- a/lib/Support/APFloat.cpp +++ b/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 @@ namespace llvm { 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 @@ decDigitValue(unsigned int c) 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 @@ readExponent(StringRef::iterator begin, StringRef::iterator end) /* 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 @@ totalExponent(StringRef::iterator p, StringRef::iterator end, return exponent; } -StringRef::iterator +static StringRef::iterator skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot) { @@ -257,7 +249,7 @@ struct decimalInfo { int normalizedExponent; }; -void +static void interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D) { @@ -316,7 +308,7 @@ interpretDecimal(StringRef::iterator begin, StringRef::iterator end, /* 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 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, /* 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 @@ lostFractionThroughTruncation(const integerPart *parts, } /* 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 @@ shiftRight(integerPart *dst, unsigned int parts, unsigned int bits) } /* Combine the effect of two lost fractions. */ -lostFraction +static lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant) { @@ -403,7 +395,7 @@ combineLostFractions(lostFraction moreSignificant, 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 @@ HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2) /* 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 @@ ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest) /* 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 @@ powerOf5(integerPart *dst, unsigned int power) /* 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 @@ partAsHex (char *dst, integerPart part, unsigned int count, } /* Write out an unsigned decimal integer. */ -char * +static char * writeUnsignedDecimal (char *dst, unsigned int n) { char buff[40], *p; @@ -571,7 +563,7 @@ writeUnsignedDecimal (char *dst, unsigned int n) } /* Write out a signed decimal integer. */ -char * +static char * writeSignedDecimal (char *dst, int value) { if (value < 0) { @@ -583,8 +575,6 @@ writeSignedDecimal (char *dst, int value) return dst; } -} // end anonymous namespace - /* Constructors. */ void APFloat::initialize(const fltSemantics *ourSemantics) @@ -862,13 +852,11 @@ APFloat::semanticsPrecision(const fltSemantics &semantics) { return semantics.precision; } - APFloat::ExponentType APFloat::semanticsMaxExponent(const fltSemantics &semantics) { return semantics.maxExponent; } - APFloat::ExponentType APFloat::semanticsMinExponent(const fltSemantics &semantics) { @@ -1919,6 +1907,7 @@ APFloat::opStatus APFloat::roundToIntegral(roundingMode rounding_mode) { return fs; } + /* Comparison requires normalized numbers. */ APFloat::cmpResult APFloat::compare(const APFloat &rhs) const @@ -2569,16 +2558,14 @@ APFloat::convertFromDecimalString(StringRef str, roundingMode rounding_mode) /* 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 @@ APFloat::initFromQuadrupleAPInt(const APInt &api) 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 @@ APFloat::APFloat(double d) { } namespace { - void append(SmallVectorImpl<char> &Buffer, StringRef Str) { Buffer.append(Str.begin(), Str.end()); } @@ -3535,6 +3521,7 @@ namespace { significand = significand.trunc(significand.getActiveBits()); } + void AdjustToPrecision(SmallVectorImpl<char> &buffer, int &exp, unsigned FormatPrecision) { unsigned N = buffer.size(); @@ -3579,8 +3566,7 @@ namespace { exp += FirstSignificant; buffer.erase(&buffer[0], &buffer[FirstSignificant]); } - -} // end anonymous namespace +} void APFloat::toString(SmallVectorImpl<char> &Str, unsigned FormatPrecision, diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index 1c5e8d93934..98865f5e065 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/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 @@ public: Next = CurrentContext->get(); CurrentContext->set(this); } - ~CrashRecoveryContextImpl() { if (!SwitchedThread) CurrentContext->set(Next); @@ -75,13 +70,13 @@ public: } }; -ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex; -bool gCrashRecoveryEnabled = false; +} -ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> - tlIsRecoveringFromCrash; +static ManagedStatic<sys::Mutex> gCrashRecoveryContextMutex; +static bool gCrashRecoveryEnabled = false; -} // end anonymous namespace +static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> + tlIsRecoveringFromCrash; CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} @@ -167,9 +162,7 @@ CrashRecoveryContext::unregisterCleanup(CrashRecoveryContextCleanup *cleanup) { // 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 @@ LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) // 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 @@ void CrashRecoveryContext::Disable() { // 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 @@ void CrashRecoverySignalHandler(int Signal) { const_cast<CrashRecoveryContextImpl*>(CRCI)->HandleCrash(); } -} // end anonymous namespace - void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -346,16 +334,14 @@ void CrashRecoveryContext::HandleCrash() { 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 @@ bool hasThreadBackgroundPriority() { #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 @@ void RunSafelyOnThread_Dispatch(void *UserData) { 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/lib/Support/Errno.cpp b/lib/Support/Errno.cpp index 888887cb938..3ba2a1277d0 100644 --- a/lib/Support/Errno.cpp +++ b/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 @@ namespace sys { 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 @@ std::string StrError(int errnum) { return str; } -} // namespace sys -} // namespace llvm +} // namespace sys +} // namespace llvm diff --git a/lib/Support/Host.cpp b/lib/Support/Host.cpp index 5962e5ee1df..1ca8eac7184 100644 --- a/lib/Support/Host.cpp +++ b/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 @@ ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) { /// 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 @@ bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, /// 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 @@ bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, unsigned *rEAX, #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 @@ bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) { #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 @@ void DetectX86FamilyModel(unsigned EAX, unsigned &Family, unsigned &Model) { } } -} // 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/lib/Support/MathExtras.cpp b/lib/Support/MathExtras.cpp index 6b9d048f636..ba0924540ce 100644 --- a/lib/Support/MathExtras.cpp +++ b/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 @@ namespace llvm { const float huge_valf = HUGE_VALF; #endif -} // end namespace llvm +} diff --git a/lib/Support/Mutex.cpp b/lib/Support/Mutex.cpp index db30c73de51..c8d3844d0c9 100644 --- a/lib/Support/Mutex.cpp +++ b/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 @@ MutexImpl::tryacquire() return errorcode == 0; } -} // end namespace llvm +} #elif defined(LLVM_ON_UNIX) #include "Unix/Mutex.inc" diff --git a/lib/Support/RWMutex.cpp b/lib/Support/RWMutex.cpp index 2a3239a22b2..3b6309cef21 100644 --- a/lib/Support/RWMutex.cpp +++ b/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 @@ RWMutexImpl::writer_release() return errorcode == 0; } -} // end namespace llvm +} #elif defined(LLVM_ON_UNIX) #include "Unix/RWMutex.inc" diff --git a/lib/Support/SHA1.cpp b/lib/Support/SHA1.cpp index 5ff2eed34c4..980c3bbffac 100644 --- a/lib/Support/SHA1.cpp +++ b/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 @@ void SHA1::init() { 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/lib/Support/SearchForAddressOfSpecialSymbol.cpp b/lib/Support/SearchForAddressOfSpecialSymbol.cpp index 711760b2479..55f3320f640 100644 --- a/lib/Support/SearchForAddressOfSpecialSymbol.cpp +++ b/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 @@ void *DoSearch(const char* symbolName) { return nullptr; } -} // end anonymous namespace - namespace llvm { - void *SearchForAddressOfSpecialSymbol(const char* symbolName) { return DoSearch(symbolName); } - -} // end namespace llvm +} // namespace llvm diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 8d1dfc76aea..3cedf64d4b0 100644 --- a/lib/Support/Unix/Path.inc +++ b/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 @@ namespace fs { #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 @@ test_dir(char ret[PATH_MAX], const char *dir, const char *bin) return 0; } -char * +static char * getprogpath(char ret[PATH_MAX], const char *bin) { char *pv, *s, *t; @@ -142,9 +138,6 @@ getprogpath(char ret[PATH_MAX], const char *bin) 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 @@ std::error_code resize_file(int FD, uint64_t Size) { 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 @@ int convertAccessMode(AccessMode Mode) { 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 @@ std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { 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 @@ std::error_code fillStatus(int StatRet, const struct stat &Status, 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 @@ bool home_directory(SmallVectorImpl<char> &result) { 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 @@ bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) { 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 @@ bool getUserCacheDir(SmallVectorImpl<char> &Result) { 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 @@ const char *getEnvTempDir() { 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 @@ const char *getDefaultTempDir(bool ErasedOnReboot) { return "/var/tmp"; } -} // end anonymous namespace - void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl<char> &Result) { Result.clear(); diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc index 350b145c28c..cad81f8074f 100644 --- a/lib/Support/Unix/Process.inc +++ b/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 @@ std::pair<TimeValue, TimeValue> getRUsageTimes() { #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 @@ Process::GetArgumentVector(SmallVectorImpl<const char *> &ArgsOut, } namespace { - class FDCloser { public: FDCloser(int &FD) : FD(FD), KeepOpen(false) {} @@ -208,8 +205,7 @@ private: int &FD; bool KeepOpen; }; - -} // end anonymous namespace +} std::error_code Process::FixupStandardFileDescriptors() { int NullFD = -1; @@ -304,9 +300,7 @@ bool Process::FileDescriptorIsDisplayed(int fd) { #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 @@ unsigned getColumns(int FileID) { return Columns; } -} // end anonymous namespace - unsigned Process::StandardOutColumns() { if (!StandardOutIsDisplayed()) return 0; @@ -352,13 +344,11 @@ extern "C" int del_curterm(struct term *termp); 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 @@ bool terminalHasColors(int fd) { 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 @@ const char *Process::ResetColor() { } #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 @@ unsigned GetRandomNumberSeed() { TimeValue Now = TimeValue::now(); return hash_combine(Now.seconds(), Now.nanoseconds(), ::getpid()); } - -} // end anonymous namespace - #endif unsigned llvm::sys::Process::GetRandomNumber() { diff --git a/lib/Support/Unix/Program.inc b/lib/Support/Unix/Program.inc index ee7df0a86b8..7d3537e2072 100644 --- a/lib/Support/Unix/Program.inc +++ b/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 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, 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 @@ bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { } #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 @@ bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, } #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 @@ void SetMemoryLimits (unsigned size) #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 @@ ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, 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 @@ bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<co } return true; } - -} // end namespace llvm +} diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 8be91cd5fb8..061cdb3da21 100644 --- a/lib/Support/Unix/Signals.inc +++ b/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 { - -RETSIGTYPE SignalHandler(int Sig); // defined below. +static 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 @@ const int KillSigs[] = { #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 @@ void RegisterHandler(int Signal) { ++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 @@ void RegisterHandlers() { 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 @@ void UnregisterHandlers() { 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 @@ void RemoveFilesToRemove() { } // 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 @@ RETSIGTYPE SignalHandler(int Sig) { #endif } -} // end anonymous namespace - void llvm::sys::RunInterruptHandlers() { sys::SmartScopedLock<true> Guard(*SignalsMutex); RemoveFilesToRemove(); @@ -264,9 +264,7 @@ struct DlIteratePhdrData { 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 @@ int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { 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 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) { #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 @@ void llvm::sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) { #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/lib/Support/Unix/ThreadLocal.inc b/lib/Support/Unix/ThreadLocal.inc index 78c694c908d..31c3f3835b2 100644 --- a/lib/Support/Unix/ThreadLocal.inc +++ b/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 @@ void ThreadLocalImpl::removeInstance() { 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/lib/Support/Unix/Unix.h b/lib/Support/Unix/Unix.h index 832d65bcc3a..871e612f6c1 100644 --- a/lib/Support/Unix/Unix.h +++ b/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 @@ static inline bool MakeErrMsg( return true; } -#endif // LLVM_LIB_SUPPORT_UNIX_UNIX_H +#endif diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 16f6367f41a..4105191147a 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -34,8 +34,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include <cstdint> - +#include <stdint.h> using namespace llvm; #define DEBUG_TYPE "x86-isel" @@ -142,7 +141,7 @@ namespace { } #endif }; -} // end anonymous namespace +} namespace { //===--------------------------------------------------------------------===// @@ -302,6 +301,7 @@ namespace { // Walk all the users of the immediate. for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); (UI != UE) && (UseCount < 2); ++UI) { + SDNode *User = *UI; // This user is already selected. Count it as a legitimate use and @@ -393,7 +393,8 @@ namespace { return true; } }; -} // end anonymous namespace +} + bool X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { @@ -458,12 +459,10 @@ X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { return true; } -namespace { - /// Replace the original chain operand of the call with /// load's chain operand and move load below the call's chain operand. -void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, - SDValue OrigChain) { +static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, + SDValue Call, SDValue OrigChain) { SmallVector<SDValue, 8> Ops; SDValue Chain = OrigChain.getOperand(0); if (Chain.getNode() == Load.getNode()) @@ -497,7 +496,7 @@ void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, /// Return the CALLSEQ_START by reference as a second output. /// In the case of a tail call, there isn't a callseq node between the call /// chain and the load. -bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { +static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { // The transformation is somewhat dangerous if the call's chain was glued to // the call. After MoveBelowOrigChain the load is moved between the call and // the chain, this can create a cycle if the load is not folded. So it is @@ -534,8 +533,6 @@ bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { return false; } -} // end anonymous namespace - void X86DAGToDAGISel::PreprocessISelDAG() { // OptFor[Min]Size are used in pattern predicates that isel is matching. OptForSize = MF->getFunction()->optForSize(); @@ -654,6 +651,7 @@ void X86DAGToDAGISel::PreprocessISelDAG() { } } + /// Emit any code that needs to be executed only in the main function. void X86DAGToDAGISel::emitSpecialCodeForMain() { if (Subtarget->isTargetCygMing()) { @@ -678,9 +676,7 @@ void X86DAGToDAGISel::EmitFunctionEntryCode() { emitSpecialCodeForMain(); } -namespace { - -bool isDispSafeForFrameIndex(int64_t Val) { +static bool isDispSafeForFrameIndex(int64_t Val) { // On 64-bit platforms, we can run into an issue where a frame index // includes a displacement that, when added to the explicit displacement, // will overflow the displacement field. Assuming that the frame index @@ -690,8 +686,6 @@ bool isDispSafeForFrameIndex(int64_t Val) { return isInt<31>(Val); } -} // end anonymous namespace - bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset, X86ISelAddressMode &AM) { // Cannot combine ExternalSymbol displacements with integer offsets. @@ -711,6 +705,7 @@ bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset, } AM.Disp = Val; return false; + } bool X86DAGToDAGISel::matchLoadInAddress(LoadSDNode *N, X86ISelAddressMode &AM){ @@ -901,14 +896,12 @@ bool X86DAGToDAGISel::matchAdd(SDValue N, X86ISelAddressMode &AM, return true; } -namespace { - // Insert a node into the DAG at least before the Pos node's position. This // will reposition the node as needed, and will assign it a node ID that is <= // the Pos node's ID. Note that this does *not* preserve the uniqueness of node // IDs! The selection DAG must no longer depend on their uniqueness when this // is used. -void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { +static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { if (N.getNode()->getNodeId() == -1 || N.getNode()->getNodeId() > Pos.getNode()->getNodeId()) { DAG.RepositionNode(Pos.getNode()->getIterator(), N.getNode()); @@ -920,9 +913,10 @@ void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { // safe. This allows us to convert the shift and and into an h-register // extract and a scaled index. Returns false if the simplification is // performed. -bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, + uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !isa<ConstantSDNode>(Shift.getOperand(1)) || !Shift.hasOneUse()) @@ -962,9 +956,10 @@ bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, // Transforms "(X << C1) & C2" to "(X & (C2>>C1)) << C1" if safe and if this // allows us to fold the shift into this addressing mode. Returns false if the // transform succeeded. -bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, + uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SHL || !isa<ConstantSDNode>(Shift.getOperand(1))) return true; @@ -1028,8 +1023,10 @@ bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, // Note that this function assumes the mask is provided as a mask *after* the // value is shifted. The input chain may or may not match that, but computing // such a mask is trivial. -bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, - SDValue Shift, SDValue X, X86ISelAddressMode &AM) { +static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, + uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !Shift.hasOneUse() || !isa<ConstantSDNode>(Shift.getOperand(1))) return true; @@ -1107,8 +1104,6 @@ bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, return false; } -} // end anonymous namespace - bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM, unsigned Depth) { SDLoc dl(N); @@ -1423,6 +1418,7 @@ bool X86DAGToDAGISel::matchAddressBase(SDValue N, X86ISelAddressMode &AM) { bool X86DAGToDAGISel::selectVectorAddr(SDNode *Parent, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, SDValue &Segment) { + MaskedGatherScatterSDNode *Mgs = dyn_cast<MaskedGatherScatterSDNode>(Parent); if (!Mgs) return false; @@ -1545,6 +1541,7 @@ bool X86DAGToDAGISel::selectScalarSSELoad(SDNode *Root, return false; } + bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) { if (const ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N)) { uint64_t ImmVal = CN->getZExtValue(); @@ -1698,6 +1695,7 @@ bool X86DAGToDAGISel::selectTLSADDRAddr(SDValue N, SDValue &Base, return true; } + bool X86DAGToDAGISel::tryFoldLoad(SDNode *P, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, @@ -1720,11 +1718,9 @@ SDNode *X86DAGToDAGISel::getGlobalBaseReg() { return CurDAG->getRegister(GlobalBaseReg, TLI->getPointerTy(DL)).getNode(); } -namespace { - /// Test whether the given X86ISD::CMP node has any uses which require the SF /// or OF bits to be accurate. -bool hasNoSignedComparisonUses(SDNode *N) { +static bool hasNoSignedComparisonUses(SDNode *N) { // Examine each user of the node. for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); UI != UE; ++UI) { @@ -1786,9 +1782,10 @@ bool hasNoSignedComparisonUses(SDNode *N) { /// Check whether or not the chain ending in StoreNode is suitable for doing /// the {load; increment or decrement; store} to modify transformation. -bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, - SDValue StoredVal, SelectionDAG *CurDAG, - LoadSDNode* &LoadNode, SDValue &InputChain) { +static bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, + SDValue StoredVal, SelectionDAG *CurDAG, + LoadSDNode* &LoadNode, SDValue &InputChain) { + // is the value stored the result of a DEC or INC? if (!(Opc == X86ISD::DEC || Opc == X86ISD::INC)) return false; @@ -1870,7 +1867,7 @@ bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, /// Get the appropriate X86 opcode for an in-memory increment or decrement. /// Opc should be X86ISD::DEC or X86ISD::INC. -unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { +static unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { if (Opc == X86ISD::DEC) { if (LdVT == MVT::i64) return X86::DEC64m; if (LdVT == MVT::i32) return X86::DEC32m; @@ -1886,8 +1883,6 @@ unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { llvm_unreachable("unrecognized size for LdVT"); } -} // end anonymous namespace - /// Customized ISel for GATHER operations. SDNode *X86DAGToDAGISel::selectGather(SDNode *Node, unsigned Opc) { // Operands of Gather: VSrc, Base, VIdx, VMask, Scale diff --git a/tools/llvm-c-test/echo.cpp b/tools/llvm-c-test/echo.cpp index b0e47d8f544..1922b429eb2 100644 --- a/tools/llvm-c-test/echo.cpp +++ b/tools/llvm-c-test/echo.cpp @@ -16,18 +16,12 @@ //===----------------------------------------------------------------------===// #include "llvm-c-test.h" -#include "llvm-c/Core.h" -#include "llvm-c/ErrorHandling.h" #include "llvm-c/Target.h" -#include "llvm-c/Types.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Hashing.h" -#include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" -#include <cstdio> -#include <cstdlib> -#include <cstring> +#include <stdio.h> +#include <stdlib.h> using namespace llvm; @@ -45,16 +39,13 @@ struct CAPIDenseMap<T*> { uintptr_t Val = static_cast<uintptr_t>(-1); return reinterpret_cast<T*>(Val); } - static inline T* getTombstoneKey() { uintptr_t Val = static_cast<uintptr_t>(-2); return reinterpret_cast<T*>(Val); } - static unsigned getHashValue(const T *PtrVal) { return hash_value(PtrVal); } - static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; } }; @@ -163,9 +154,7 @@ struct TypeCloner { } }; -namespace { - -ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) { +static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) { unsigned Count = LLVMCountParams(Src); if (Count != LLVMCountParams(Dst)) report_fatal_error("Parameter count mismatch"); @@ -223,8 +212,6 @@ ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) { return VMap; } -} // end anonymous namespace - LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) { if (!LLVMIsAConstant(Cst)) report_fatal_error("Expected a constant"); @@ -723,9 +710,7 @@ struct FunCloner { } }; -namespace { - -void declare_symbols(LLVMModuleRef Src, LLVMModuleRef M) { +static void declare_symbols(LLVMModuleRef Src, LLVMModuleRef M) { LLVMValueRef Begin = LLVMGetFirstGlobal(Src); LLVMValueRef End = LLVMGetLastGlobal(Src); @@ -789,7 +774,7 @@ FunDecl: } } -void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) { +static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) { LLVMValueRef Begin = LLVMGetFirstGlobal(Src); LLVMValueRef End = LLVMGetLastGlobal(Src); @@ -876,8 +861,6 @@ FunClone: } } -} // end anonymous namespace - int llvm_echo(void) { LLVMEnablePrettyStackTrace(); diff --git a/tools/llvm-c-test/llvm-c-test.h b/tools/llvm-c-test/llvm-c-test.h index fa5a9d04cca..60edc0df4d1 100644 --- a/tools/llvm-c-test/llvm-c-test.h +++ b/tools/llvm-c-test/llvm-c-test.h @@ -10,15 +10,10 @@ |* Header file for llvm-c-test *| |* *| \*===----------------------------------------------------------------------===*/ - #ifndef LLVM_C_TEST_H #define LLVM_C_TEST_H -#ifdef __cplusplus -#include <cstdbool> -#else #include <stdbool.h> -#endif #include "llvm-c/Core.h" #ifdef __cplusplus @@ -56,6 +51,6 @@ int llvm_echo(void); #ifdef __cplusplus } -#endif +#endif /* !defined(__cplusplus) */ -#endif // LLVM_C_TEST_H +#endif diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp index 9f398d2d04c..781185af849 100644 --- a/tools/llvm-readobj/COFFDumper.cpp +++ b/tools/llvm-readobj/COFFDumper.cpp @@ -40,14 +40,9 @@ #include "llvm/Support/Win64EH.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <cassert> -#include <cstdint> -#include <ctime> -#include <memory> -#include <string> -#include <tuple> +#include <cstring> #include <system_error> -#include <vector> +#include <time.h> using namespace llvm; using namespace llvm::object; @@ -76,7 +71,6 @@ public: void printCOFFBaseReloc() override; void printCodeViewDebugInfo() override; void printStackMap() const override; - private: void printSymbol(const SymbolRef &Sym); void printRelocation(const SectionRef &Section, const RelocationRef &Reloc, @@ -150,7 +144,8 @@ private: StringSet<> TypeNames; }; -} // end anonymous namespace +} // namespace + namespace llvm { @@ -165,7 +160,7 @@ std::error_code createCOFFDumper(const object::ObjectFile *Obj, return readobj_error::success; } -} // end namespace llvm +} // namespace llvm // Given a a section and an offset into this section the function returns the // symbol used for the relocation at the offset. @@ -248,9 +243,7 @@ void COFFDumper::printBinaryBlockWithRelocs(StringRef Label, } } -namespace { - -const EnumEntry<COFF::MachineTypes> ImageFileMachineType[] = { +static const EnumEntry<COFF::MachineTypes> ImageFileMachineType[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_UNKNOWN ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AM33 ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_AMD64 ), @@ -274,7 +267,7 @@ const EnumEntry<COFF::MachineTypes> ImageFileMachineType[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_WCEMIPSV2) }; -const EnumEntry<COFF::Characteristics> ImageFileCharacteristics[] = { +static const EnumEntry<COFF::Characteristics> ImageFileCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_RELOCS_STRIPPED ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_EXECUTABLE_IMAGE ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_LINE_NUMS_STRIPPED ), @@ -292,7 +285,7 @@ const EnumEntry<COFF::Characteristics> ImageFileCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_HI ) }; -const EnumEntry<COFF::WindowsSubsystem> PEWindowsSubsystem[] = { +static const EnumEntry<COFF::WindowsSubsystem> PEWindowsSubsystem[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_UNKNOWN ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_NATIVE ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_WINDOWS_GUI ), @@ -306,7 +299,7 @@ const EnumEntry<COFF::WindowsSubsystem> PEWindowsSubsystem[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_XBOX ), }; -const EnumEntry<COFF::DLLCharacteristics> PEDLLCharacteristics[] = { +static const EnumEntry<COFF::DLLCharacteristics> PEDLLCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY ), @@ -320,7 +313,7 @@ const EnumEntry<COFF::DLLCharacteristics> PEDLLCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE), }; -const EnumEntry<COFF::SectionCharacteristics> +static const EnumEntry<COFF::SectionCharacteristics> ImageSectionCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NOLOAD ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NO_PAD ), @@ -360,7 +353,7 @@ ImageSectionCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_WRITE ) }; -const EnumEntry<COFF::SymbolBaseType> ImageSymType[] = { +static const EnumEntry<COFF::SymbolBaseType> ImageSymType[] = { { "Null" , COFF::IMAGE_SYM_TYPE_NULL }, { "Void" , COFF::IMAGE_SYM_TYPE_VOID }, { "Char" , COFF::IMAGE_SYM_TYPE_CHAR }, @@ -379,14 +372,14 @@ const EnumEntry<COFF::SymbolBaseType> ImageSymType[] = { { "DWord" , COFF::IMAGE_SYM_TYPE_DWORD } }; -const EnumEntry<COFF::SymbolComplexType> ImageSymDType[] = { +static const EnumEntry<COFF::SymbolComplexType> ImageSymDType[] = { { "Null" , COFF::IMAGE_SYM_DTYPE_NULL }, { "Pointer" , COFF::IMAGE_SYM_DTYPE_POINTER }, { "Function", COFF::IMAGE_SYM_DTYPE_FUNCTION }, { "Array" , COFF::IMAGE_SYM_DTYPE_ARRAY } }; -const EnumEntry<COFF::SymbolStorageClass> ImageSymClass[] = { +static const EnumEntry<COFF::SymbolStorageClass> ImageSymClass[] = { { "EndOfFunction" , COFF::IMAGE_SYM_CLASS_END_OF_FUNCTION }, { "Null" , COFF::IMAGE_SYM_CLASS_NULL }, { "Automatic" , COFF::IMAGE_SYM_CLASS_AUTOMATIC }, @@ -416,7 +409,7 @@ const EnumEntry<COFF::SymbolStorageClass> ImageSymClass[] = { { "CLRToken" , COFF::IMAGE_SYM_CLASS_CLR_TOKEN } }; -const EnumEntry<COFF::COMDATType> ImageCOMDATSelect[] = { +static const EnumEntry<COFF::COMDATType> ImageCOMDATSelect[] = { { "NoDuplicates", COFF::IMAGE_COMDAT_SELECT_NODUPLICATES }, { "Any" , COFF::IMAGE_COMDAT_SELECT_ANY }, { "SameSize" , COFF::IMAGE_COMDAT_SELECT_SAME_SIZE }, @@ -426,14 +419,14 @@ const EnumEntry<COFF::COMDATType> ImageCOMDATSelect[] = { { "Newest" , COFF::IMAGE_COMDAT_SELECT_NEWEST } }; -const EnumEntry<COFF::WeakExternalCharacteristics> +static const EnumEntry<COFF::WeakExternalCharacteristics> WeakExternalCharacteristics[] = { { "NoLibrary", COFF::IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY }, { "Library" , COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY }, { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS } }; -const EnumEntry<CompileSym3::Flags> CompileSym3Flags[] = { +static const EnumEntry<CompileSym3::Flags> CompileSym3Flags[] = { LLVM_READOBJ_ENUM_ENT(CompileSym3, EC), LLVM_READOBJ_ENUM_ENT(CompileSym3, NoDbgInfo), LLVM_READOBJ_ENUM_ENT(CompileSym3, LTCG), @@ -448,7 +441,7 @@ const EnumEntry<CompileSym3::Flags> CompileSym3Flags[] = { LLVM_READOBJ_ENUM_ENT(CompileSym3, Exp), }; -const EnumEntry<codeview::SourceLanguage> SourceLanguages[] = { +static const EnumEntry<codeview::SourceLanguage> SourceLanguages[] = { LLVM_READOBJ_ENUM_ENT(SourceLanguage, C), LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cpp), LLVM_READOBJ_ENUM_ENT(SourceLanguage, Fortran), @@ -468,7 +461,7 @@ const EnumEntry<codeview::SourceLanguage> SourceLanguages[] = { LLVM_READOBJ_ENUM_ENT(SourceLanguage, HLSL), }; -const EnumEntry<uint32_t> SubSectionTypes[] = { +static const EnumEntry<uint32_t> SubSectionTypes[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Symbols), LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Lines), LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, StringTable), @@ -484,7 +477,7 @@ const EnumEntry<uint32_t> SubSectionTypes[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CoffSymbolRVA), }; -const EnumEntry<unsigned> CPUTypeNames[] = { +static const EnumEntry<unsigned> CPUTypeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8080), LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8086), LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel80286), @@ -546,7 +539,7 @@ const EnumEntry<unsigned> CPUTypeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, D3D11_Shader), }; -const EnumEntry<uint8_t> ProcSymFlags[] = { +static const EnumEntry<uint8_t> ProcSymFlags[] = { LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFP), LLVM_READOBJ_ENUM_ENT(ProcFlags, HasIRET), LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFRET), @@ -557,7 +550,7 @@ const EnumEntry<uint8_t> ProcSymFlags[] = { LLVM_READOBJ_ENUM_ENT(ProcFlags, HasOptimizedDebugInfo), }; -const EnumEntry<uint32_t> FrameProcSymFlags[] = { +static const EnumEntry<uint32_t> FrameProcSymFlags[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasAlloca), LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasSetJmp), LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasLongJmp), @@ -583,13 +576,13 @@ const EnumEntry<uint32_t> FrameProcSymFlags[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfw), }; -const EnumEntry<uint32_t> FrameDataFlags[] = { +static const EnumEntry<uint32_t> FrameDataFlags[] = { LLVM_READOBJ_ENUM_ENT(FrameData, HasSEH), LLVM_READOBJ_ENUM_ENT(FrameData, HasEH), LLVM_READOBJ_ENUM_ENT(FrameData, IsFunctionStart), }; -const EnumEntry<uint16_t> LocalFlags[] = { +static const EnumEntry<uint16_t> LocalFlags[] = { LLVM_READOBJ_ENUM_ENT(LocalSym, IsParameter), LLVM_READOBJ_ENUM_ENT(LocalSym, IsAddressTaken), LLVM_READOBJ_ENUM_ENT(LocalSym, IsCompilerGenerated), @@ -603,14 +596,14 @@ const EnumEntry<uint16_t> LocalFlags[] = { LLVM_READOBJ_ENUM_ENT(LocalSym, IsEnregisteredStatic), }; -const EnumEntry<uint16_t> FrameCookieKinds[] = { +static const EnumEntry<uint16_t> FrameCookieKinds[] = { LLVM_READOBJ_ENUM_ENT(FrameCookieSym, Copy), LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorStackPointer), LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorFramePointer), LLVM_READOBJ_ENUM_ENT(FrameCookieSym, XorR13), }; -const EnumEntry<uint16_t> ClassOptionNames[] = { +static const EnumEntry<uint16_t> ClassOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Packed), LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasConstructorOrDestructor), LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasOverloadedOperator), @@ -625,14 +618,14 @@ const EnumEntry<uint16_t> ClassOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Intrinsic), }; -const EnumEntry<uint8_t> MemberAccessNames[] = { +static const EnumEntry<uint8_t> MemberAccessNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, None), LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Private), LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Protected), LLVM_READOBJ_ENUM_CLASS_ENT(MemberAccess, Public), }; -const EnumEntry<uint16_t> MethodOptionNames[] = { +static const EnumEntry<uint16_t> MethodOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Pseudo), LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoInherit), LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoConstruct), @@ -640,7 +633,7 @@ const EnumEntry<uint16_t> MethodOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Sealed), }; -const EnumEntry<uint16_t> MemberKindNames[] = { +static const EnumEntry<uint16_t> MemberKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Vanilla), LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Virtual), LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Static), @@ -653,7 +646,7 @@ const EnumEntry<uint16_t> MemberKindNames[] = { /// The names here all end in "*". If the simple type is a pointer type, we /// return the whole name. Otherwise we lop off the last character in our /// StringRef. -const EnumEntry<SimpleTypeKind> SimpleTypeNames[] = { +static const EnumEntry<SimpleTypeKind> SimpleTypeNames[] = { {"void*", SimpleTypeKind::Void}, {"<not translated>*", SimpleTypeKind::NotTranslated}, {"HRESULT*", SimpleTypeKind::HResult}, @@ -694,12 +687,12 @@ const EnumEntry<SimpleTypeKind> SimpleTypeNames[] = { {"__bool64*", SimpleTypeKind::Boolean64}, }; -const EnumEntry<TypeLeafKind> LeafTypeNames[] = { +static const EnumEntry<TypeLeafKind> LeafTypeNames[] = { #define LEAF_TYPE(name, val) LLVM_READOBJ_ENUM_ENT(TypeLeafKind, name), #include "llvm/DebugInfo/CodeView/CVLeafTypes.def" }; -const EnumEntry<uint8_t> PtrKindNames[] = { +static const EnumEntry<uint8_t> PtrKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near16), LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Far16), LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Huge16), @@ -715,7 +708,7 @@ const EnumEntry<uint8_t> PtrKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near64), }; -const EnumEntry<uint8_t> PtrModeNames[] = { +static const EnumEntry<uint8_t> PtrModeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, Pointer), LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, LValueReference), LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, PointerToDataMember), @@ -723,7 +716,7 @@ const EnumEntry<uint8_t> PtrModeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, RValueReference), }; -const EnumEntry<uint16_t> PtrMemberRepNames[] = { +static const EnumEntry<uint16_t> PtrMemberRepNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, Unknown), LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, SingleInheritanceData), @@ -741,13 +734,13 @@ const EnumEntry<uint16_t> PtrMemberRepNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, GeneralFunction), }; -const EnumEntry<uint16_t> TypeModifierNames[] = { +static const EnumEntry<uint16_t> TypeModifierNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Const), LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Volatile), LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Unaligned), }; -const EnumEntry<uint8_t> CallingConventions[] = { +static const EnumEntry<uint8_t> CallingConventions[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearC), LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarC), LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearPascal), @@ -774,13 +767,13 @@ const EnumEntry<uint8_t> CallingConventions[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearVector), }; -const EnumEntry<uint8_t> FunctionOptionEnum[] = { +static const EnumEntry<uint8_t> FunctionOptionEnum[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, CxxReturnUdt), LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, Constructor), LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, ConstructorWithVirtualBases), }; -const EnumEntry<uint8_t> FileChecksumKindNames[] = { +static const EnumEntry<uint8_t> FileChecksumKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, None), LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, MD5), LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA1), @@ -788,7 +781,7 @@ const EnumEntry<uint8_t> FileChecksumKindNames[] = { }; template <typename T> -std::error_code getSymbolAuxData(const COFFObjectFile *Obj, +static std::error_code getSymbolAuxData(const COFFObjectFile *Obj, COFFSymbolRef Symbol, uint8_t AuxSymbolIdx, const T *&Aux) { ArrayRef<uint8_t> AuxData = Obj->getSymbolAuxData(Symbol); @@ -797,8 +790,6 @@ std::error_code getSymbolAuxData(const COFFObjectFile *Obj, return readobj_error::success; } -} // end anonymous namespace - void COFFDumper::cacheRelocations() { if (RelocCached) return; @@ -949,13 +940,11 @@ void COFFDumper::printCodeViewDebugInfo() { } } -namespace { - /// Consumes sizeof(T) bytes from the given byte sequence. Returns an error if /// there are not enough bytes remaining. Reinterprets the consumed bytes as a /// T object and points 'Res' at them. template <typename T> -std::error_code consumeObject(StringRef &Data, const T *&Res) { +static std::error_code consumeObject(StringRef &Data, const T *&Res) { if (Data.size() < sizeof(*Res)) return object_error::parse_failed; Res = reinterpret_cast<const T *>(Data.data()); @@ -963,7 +952,7 @@ std::error_code consumeObject(StringRef &Data, const T *&Res) { return std::error_code(); } -std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { +static std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { const ulittle32_t *IntPtr; if (auto EC = consumeObject(Data, IntPtr)) return EC; @@ -971,8 +960,6 @@ std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { return std::error_code(); } -} // end anonymous namespace - void COFFDumper::initializeFileAndStringTables(StringRef Data) { while (!Data.empty() && (CVFileChecksumTable.data() == nullptr || CVStringTable.data() == nullptr)) { @@ -1195,9 +1182,7 @@ void COFFDumper::printCodeViewSymbolSection(StringRef SectionName, } } -namespace { - -std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { +static std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { // Used to avoid overload ambiguity on APInt construtor. bool FalseVal = false; if (Data.size() < 2) @@ -1263,8 +1248,6 @@ std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { return object_error::parse_failed; } -} // end anonymous namespace - /// Decode an unsigned integer numeric leaf value. std::error_code decodeUIntLeaf(StringRef &Data, uint64_t &Num) { APSInt N; @@ -1330,10 +1313,11 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, break; } - case S_PROC_ID_END: + case S_PROC_ID_END: { W.startLine() << "ProcEnd\n"; InFunctionScope = false; break; + } case S_BLOCK32: { DictScope S(W, "BlockStart"); @@ -1353,10 +1337,11 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, break; } - case S_END: + case S_END: { W.startLine() << "BlockEnd\n"; InFunctionScope = false; break; + } case S_LABEL32: { DictScope S(W, "Label"); @@ -1530,7 +1515,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, printLocalVariableAddrGap(SymData); break; } - case S_DEFRANGE_SUBFIELD: { DictScope S(W, "DefRangeSubfield"); const DefRangeSubfieldSym *DefRangeSubfield; @@ -1545,7 +1529,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, printLocalVariableAddrGap(SymData); break; } - case S_DEFRANGE_REGISTER: { DictScope S(W, "DefRangeRegister"); const DefRangeRegisterSym *DefRangeRegister; @@ -1557,7 +1540,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, printLocalVariableAddrGap(SymData); break; } - case S_DEFRANGE_SUBFIELD_REGISTER: { DictScope S(W, "DefRangeSubfieldRegister"); const DefRangeSubfieldRegisterSym *DefRangeSubfieldRegisterSym; @@ -1572,7 +1554,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, printLocalVariableAddrGap(SymData); break; } - case S_DEFRANGE_FRAMEPOINTER_REL: { DictScope S(W, "DefRangeFramePointerRel"); const DefRangeFramePointerRelSym *DefRangeFramePointerRel; @@ -1583,7 +1564,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, printLocalVariableAddrGap(SymData); break; } - case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE: { DictScope S(W, "DefRangeFramePointerRelFullScope"); const DefRangeFramePointerRelFullScopeSym @@ -1592,7 +1572,6 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection, W.printNumber("Offset", DefRangeFramePointerRelFullScope->Offset); break; } - case S_DEFRANGE_REGISTER_REL: { DictScope S(W, "DefRangeRegisterRel"); const DefRangeRegisterRelSym *DefRangeRegisterRel; @@ -1966,9 +1945,7 @@ void COFFDumper::printFileNameForOffset(StringRef Label, uint32_t FileOffset) { W.printHex(Label, getFileNameForFileOffset(FileOffset), FileOffset); } -namespace { - -StringRef getLeafTypeName(TypeLeafKind LT) { +static StringRef getLeafTypeName(TypeLeafKind LT) { switch (LT) { case LF_STRING_ID: return "StringId"; case LF_FIELDLIST: return "FieldList"; @@ -1997,8 +1974,6 @@ StringRef getLeafTypeName(TypeLeafKind LT) { return "UnknownLeaf"; } -} // end anonymous namespace - void COFFDumper::printCodeViewTypeSection(StringRef SectionName, const SectionRef &Section) { ListScope D(W, "CodeViewTypes"); @@ -2225,7 +2200,7 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName, break; } - case LF_METHODLIST: + case LF_METHODLIST: { while (!LeafData.empty()) { const MethodListEntry *Method; error(consumeObject(LeafData, Method)); @@ -2239,6 +2214,7 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName, } } break; + } case LF_FUNC_ID: { const FuncId *Func; @@ -2380,9 +2356,7 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName, } } -namespace { - -StringRef skipPadding(StringRef Data) { +static StringRef skipPadding(StringRef Data) { if (Data.empty()) return Data; uint8_t Leaf = Data.front(); @@ -2393,8 +2367,6 @@ StringRef skipPadding(StringRef Data) { return Data.drop_front(Leaf & 0x0F); } -} // end anonymous namespace - void COFFDumper::printMemberAttributes(MemberAttributes Attrs) { W.printEnum("AccessSpecifier", uint8_t(Attrs.getAccess()), makeArrayRef(MemberAccessNames)); @@ -2659,9 +2631,7 @@ void COFFDumper::printSymbols() { void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); } -namespace { - -ErrorOr<StringRef> +static ErrorOr<StringRef> getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber, const coff_section *Section) { if (Section) { @@ -2679,8 +2649,6 @@ getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber, return StringRef(""); } -} // end anonymous namespace - void COFFDumper::printSymbol(const SymbolRef &Sym) { DictScope D(W, "Symbol"); @@ -2925,9 +2893,7 @@ void COFFDumper::printCOFFDirectives() { } } -namespace { - -StringRef getBaseRelocTypeName(uint8_t Type) { +static StringRef getBaseRelocTypeName(uint8_t Type) { switch (Type) { case COFF::IMAGE_REL_BASED_ABSOLUTE: return "ABSOLUTE"; case COFF::IMAGE_REL_BASED_HIGH: return "HIGH"; @@ -2940,8 +2906,6 @@ StringRef getBaseRelocTypeName(uint8_t Type) { } } -} // end anonymous namespace - void COFFDumper::printCOFFBaseReloc() { ListScope D(W, "BaseReloc"); for (const BaseRelocRef &I : Obj->base_relocs()) { diff --git a/tools/sancov/sancov.cc b/tools/sancov/sancov.cc index 0d2b48ca868..0baaae16cfe 100644 --- a/tools/sancov/sancov.cc +++ b/tools/sancov/sancov.cc @@ -1,4 +1,4 @@ -//===-- sancov.cc ---------------------------------------------------------===// +//===-- sancov.cc --------------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -10,13 +10,7 @@ // This file is a command-line tool for reading and analyzing sanitizer // coverage. //===----------------------------------------------------------------------===// - -#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/ADT/Triple.h" #include "llvm/ADT/Twine.h" #include "llvm/DebugInfo/Symbolize/Symbolize.h" #include "llvm/MC/MCAsmInfo.h" @@ -53,13 +47,9 @@ #include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <cstdint> -#include <cstdlib> -#include <map> -#include <memory> #include <set> +#include <stdio.h> #include <string> -#include <tuple> #include <utility> #include <vector> @@ -93,28 +83,28 @@ cl::opt<ActionType> Action( "Print coverage statistics."), clEnumValEnd)); -cl::list<std::string> +static cl::list<std::string> ClInputFiles(cl::Positional, cl::OneOrMore, cl::desc("(<binary file>|<.sancov file>)...")); -cl::opt<bool> ClDemangle("demangle", cl::init(true), - cl::desc("Print demangled function name.")); +static cl::opt<bool> ClDemangle("demangle", cl::init(true), + cl::desc("Print demangled function name.")); -cl::opt<std::string> ClStripPathPrefix( +static cl::opt<std::string> ClStripPathPrefix( "strip_path_prefix", cl::init(""), cl::desc("Strip this prefix from file paths in reports.")); -cl::opt<std::string> +static cl::opt<std::string> ClBlacklist("blacklist", cl::init(""), cl::desc("Blacklist file (sanitizer blacklist format).")); -cl::opt<bool> ClUseDefaultBlacklist( +static cl::opt<bool> ClUseDefaultBlacklist( "use_default_blacklist", cl::init(true), cl::Hidden, cl::desc("Controls if default blacklist should be used.")); -const char *const DefaultBlacklistStr = "fun:__sanitizer_.*\n" - "src:/usr/include/.*\n" - "src:.*/libc\\+\\+/.*\n"; +static const char *const DefaultBlacklistStr = "fun:__sanitizer_.*\n" + "src:/usr/include/.*\n" + "src:.*/libc\\+\\+/.*\n"; // --------- FORMAT SPECIFICATION --------- @@ -123,37 +113,37 @@ struct FileHeader { uint32_t Magic; }; -const uint32_t BinCoverageMagic = 0xC0BFFFFF; -const uint32_t Bitness32 = 0xFFFFFF32; -const uint32_t Bitness64 = 0xFFFFFF64; +static const uint32_t BinCoverageMagic = 0xC0BFFFFF; +static const uint32_t Bitness32 = 0xFFFFFF32; +static const uint32_t Bitness64 = 0xFFFFFF64; // --------- ERROR HANDLING --------- -void Fail(const llvm::Twine &E) { +static void Fail(const llvm::Twine &E) { errs() << "Error: " << E << "\n"; exit(1); } -void FailIfError(std::error_code Error) { +static void FailIfError(std::error_code Error) { if (!Error) return; errs() << "Error: " << Error.message() << "(" << Error.value() << ")\n"; exit(1); } -template <typename T> -void FailIfError(const ErrorOr<T> &E) { +template <typename T> static void FailIfError(const ErrorOr<T> &E) { FailIfError(E.getError()); } -void FailIfNotEmpty(const llvm::Twine &E) { +static void FailIfNotEmpty(const llvm::Twine &E) { if (E.str().empty()) return; Fail(E); } template <typename T> -void FailIfEmpty(const std::unique_ptr<T> &Ptr, const std::string &Message) { +static void FailIfEmpty(const std::unique_ptr<T> &Ptr, + const std::string &Message) { if (Ptr.get()) return; Fail(Message); @@ -164,7 +154,7 @@ void FailIfEmpty(const std::unique_ptr<T> &Ptr, const std::string &Message) { // Produces std::map<K, std::vector<E>> grouping input // elements by FuncTy result. template <class RangeTy, class FuncTy> -inline auto group_by(const RangeTy &R, FuncTy F) +static inline auto group_by(const RangeTy &R, FuncTy F) -> std::map<typename std::decay<decltype(F(*R.begin()))>::type, std::vector<typename std::decay<decltype(*R.begin())>::type>> { std::map<typename std::decay<decltype(F(*R.begin()))>::type, @@ -177,7 +167,8 @@ inline auto group_by(const RangeTy &R, FuncTy F) } template <typename T> -void readInts(const char *Start, const char *End, std::set<uint64_t> *Ints) { +static void readInts(const char *Start, const char *End, + std::set<uint64_t> *Ints) { const T *S = reinterpret_cast<const T *>(Start); const T *E = reinterpret_cast<const T *>(End); std::copy(S, E, std::inserter(*Ints, Ints->end())); @@ -220,7 +211,7 @@ std::string stripPathPrefix(std::string Path) { return Path.substr(Pos + ClStripPathPrefix.size()); } -std::unique_ptr<symbolize::LLVMSymbolizer> createSymbolizer() { +static std::unique_ptr<symbolize::LLVMSymbolizer> createSymbolizer() { symbolize::LLVMSymbolizer::Options SymbolizerOptions; SymbolizerOptions.Demangle = ClDemangle; SymbolizerOptions.UseSymbolTable = true; @@ -285,9 +276,9 @@ private: }; // Collect all debug info for given addresses. -std::vector<AddrInfo> getAddrInfo(std::string ObjectFile, - const std::set<uint64_t> &Addrs, - bool InlinedCode) { +static std::vector<AddrInfo> getAddrInfo(std::string ObjectFile, + const std::set<uint64_t> &Addrs, + bool InlinedCode) { std::vector<AddrInfo> Result; auto Symbolizer(createSymbolizer()); Blacklists B; @@ -315,7 +306,7 @@ std::vector<AddrInfo> getAddrInfo(std::string ObjectFile, // Locate __sanitizer_cov* function addresses that are used for coverage // reporting. -std::set<uint64_t> +static std::set<uint64_t> findSanitizerCovFunctions(const object::ObjectFile &O) { std::set<uint64_t> Result; @@ -340,8 +331,8 @@ findSanitizerCovFunctions(const object::ObjectFile &O) { // Locate addresses of all coverage points in a file. Coverage point // is defined as the 'address of instruction following __sanitizer_cov // call - 1'. -void getObjectCoveragePoints(const object::ObjectFile &O, - std::set<uint64_t> *Addrs) { +static void getObjectCoveragePoints(const object::ObjectFile &O, + std::set<uint64_t> *Addrs) { Triple TheTriple("unknown-unknown-unknown"); TheTriple.setArch(Triple::ArchType(O.getArch())); auto TripleName = TheTriple.getTriple(); @@ -413,7 +404,7 @@ void getObjectCoveragePoints(const object::ObjectFile &O, } } -void +static void visitObjectFiles(const object::Archive &A, std::function<void(const object::ObjectFile &)> Fn) { for (auto &ErrorOrChild : A.children()) { @@ -428,7 +419,7 @@ visitObjectFiles(const object::Archive &A, } } -void +static void visitObjectFiles(std::string FileName, std::function<void(const object::ObjectFile &)> Fn) { ErrorOr<object::OwningBinary<object::Binary>> BinaryOrErr = @@ -464,7 +455,7 @@ std::set<uint64_t> getCoveragePoints(std::string FileName) { return Result; } -void printCovPoints(std::string ObjFile, raw_ostream &OS) { +static void printCovPoints(std::string ObjFile, raw_ostream &OS) { for (uint64_t Addr : getCoveragePoints(ObjFile)) { OS << "0x"; OS.write_hex(Addr); @@ -472,7 +463,7 @@ void printCovPoints(std::string ObjFile, raw_ostream &OS) { } } -std::string escapeHtml(const std::string &S) { +static std::string escapeHtml(const std::string &S) { std::string Result; Result.reserve(S.size()); for (char Ch : S) { @@ -502,7 +493,7 @@ std::string escapeHtml(const std::string &S) { // Adds leading zeroes wrapped in 'lz' style. // Leading zeroes help locate 000% coverage. -std::string formatHtmlPct(size_t Pct) { +static std::string formatHtmlPct(size_t Pct) { Pct = std::max(std::size_t{0}, std::min(std::size_t{100}, Pct)); std::string Num = std::to_string(Pct); @@ -513,7 +504,7 @@ std::string formatHtmlPct(size_t Pct) { return Zeroes + Num; } -std::string anchorName(std::string Anchor) { +static std::string anchorName(std::string Anchor) { llvm::MD5 Hasher; llvm::MD5::MD5Result Hash; Hasher.update(Anchor); @@ -524,7 +515,7 @@ std::string anchorName(std::string Anchor) { return HexString.str().str(); } -ErrorOr<bool> isCoverageFile(std::string FileName) { +static ErrorOr<bool> isCoverageFile(std::string FileName) { ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr = MemoryBuffer::getFile(FileName); if (!BufOrErr) { @@ -551,7 +542,7 @@ struct CoverageStats { size_t CovFns; }; -raw_ostream &operator<<(raw_ostream &OS, const CoverageStats &Stats) { +static raw_ostream &operator<<(raw_ostream &OS, const CoverageStats &Stats) { OS << "all-edges: " << Stats.AllPoints << "\n"; OS << "cov-edges: " << Stats.CovPoints << "\n"; OS << "all-functions: " << Stats.AllFns << "\n"; @@ -831,8 +822,8 @@ private: std::vector<AddrInfo> CovAddrInfo; }; -void printFunctionLocs(const SourceCoverageData::FunctionLocs &FnLocs, - raw_ostream &OS) { +static void printFunctionLocs(const SourceCoverageData::FunctionLocs &FnLocs, + raw_ostream &OS) { for (const auto &Fns : FnLocs) { for (const auto &Fn : Fns.second) { OS << stripPathPrefix(Fns.first.FileName) << ":" << Fns.first.Line << " " @@ -1191,7 +1182,7 @@ private: const std::set<std::string> CoverageFiles; }; -} // end anonymous namespace +} // namespace int main(int argc, char **argv) { // Print stack trace if we signal out. diff --git a/tools/sanstats/sanstats.cpp b/tools/sanstats/sanstats.cpp index 95f5424ba66..3a8cc9aea8c 100644 --- a/tools/sanstats/sanstats.cpp +++ b/tools/sanstats/sanstats.cpp @@ -12,26 +12,20 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/StringRef.h" #include "llvm/DebugInfo/Symbolize/Symbolize.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Transforms/Utils/SanitizerStats.h" -#include <cassert> -#include <cstdint> -#include <memory> -#include <string> +#include <stdint.h> using namespace llvm; -namespace { +static cl::opt<std::string> ClInputFile(cl::Positional, cl::Required, + cl::desc("<filename>")); -cl::opt<std::string> ClInputFile(cl::Positional, cl::Required, - cl::desc("<filename>")); - -cl::opt<bool> ClDemangle("demangle", cl::init(false), - cl::desc("Print demangled function name.")); +static cl::opt<bool> ClDemangle("demangle", cl::init(false), + cl::desc("Print demangled function name.")); inline uint64_t KindFromData(uint64_t Data, char SizeofPtr) { return Data >> (SizeofPtr * 8 - kSanitizerStatKindBits); @@ -69,7 +63,7 @@ const char *ReadModule(char SizeofPtr, const char *Begin, const char *End) { SymbolizerOptions.UseSymbolTable = true; symbolize::LLVMSymbolizer Symbolizer(SymbolizerOptions); - while (true) { + while (1) { uint64_t Addr = ReadLE(SizeofPtr, Begin, End); Begin += SizeofPtr; uint64_t Data = ReadLE(SizeofPtr, Begin, End); @@ -115,8 +109,6 @@ const char *ReadModule(char SizeofPtr, const char *Begin, const char *End) { } } -} // end anonymous namespace - int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "Sanitizer Statistics Processing Tool"); diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp index 95639940160..da8c04483f9 100644 --- a/unittests/ADT/SCCIteratorTest.cpp +++ b/unittests/ADT/SCCIteratorTest.cpp @@ -10,10 +10,7 @@ #include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/GraphTraits.h" #include "gtest/gtest.h" -#include <cassert> -#include <climits> -#include <utility> -#include <vector> +#include <limits.h> using namespace llvm; @@ -30,14 +27,13 @@ private: static void ValidateIndex(unsigned Idx) { assert(Idx < N && "Invalid node index!"); } - public: + /// NodeSubset - A subset of the graph's nodes. class NodeSubset { typedef unsigned char BitVector; // Where the limitation N <= 8 comes from. BitVector Elements; NodeSubset(BitVector e) : Elements(e) {} - public: /// NodeSubset - Default constructor, creates an empty subset. NodeSubset() : Elements(0) { @@ -102,8 +98,8 @@ public: private: /// Nodes - The list of nodes for this graph. NodeType Nodes[N]; - public: + /// Graph - Default constructor. Creates an empty graph. Graph() { // Let each node know which node it is. This allows us to find the start of @@ -170,7 +166,6 @@ public: NodeSubset Children; ChildIterator(); // Disable default constructor. - protected: ChildIterator(NodeType *F, NodeSubset C) : FirstNode(F), Children(C) {} @@ -346,4 +341,4 @@ TEST(SCCIteratorTest, AllSmallGraphs) { } } -} // end namespace llvm +} diff --git a/unittests/ADT/SmallStringTest.cpp b/unittests/ADT/SmallStringTest.cpp index b04437873e6..995ef8e8127 100644 --- a/unittests/ADT/SmallStringTest.cpp +++ b/unittests/ADT/SmallStringTest.cpp @@ -12,9 +12,10 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" #include "gtest/gtest.h" +#include <climits> +#include <cstring> +#include <stdarg.h> using namespace llvm; @@ -203,4 +204,4 @@ TEST(StringRefTest, Comparisons) { EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0")); } -} // end anonymous namespace +} diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index bf9de88ffc0..7367ad470e3 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -15,10 +15,8 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" #include "gtest/gtest.h" -#include <cstdarg> -#include <cstdlib> #include <list> -#include <utility> +#include <stdarg.h> using namespace llvm; @@ -143,10 +141,9 @@ int Constructable::numCopyAssignmentCalls; int Constructable::numMoveAssignmentCalls; struct NonCopyable { - NonCopyable() = default; - NonCopyable(NonCopyable &&) = default; + NonCopyable() {} + NonCopyable(NonCopyable &&) {} NonCopyable &operator=(NonCopyable &&) { return *this; } - private: NonCopyable(const NonCopyable &) = delete; NonCopyable &operator=(const NonCopyable &) = delete; @@ -203,6 +200,7 @@ protected: VectorT otherVector; }; + typedef ::testing::Types<SmallVector<Constructable, 0>, SmallVector<Constructable, 1>, SmallVector<Constructable, 2>, @@ -524,6 +522,7 @@ TYPED_TEST(SmallVectorTest, InsertRepeatedTest) { this->assertValuesInOrder(this->theVector, 6u, 1, 16, 16, 2, 3, 4); } + TYPED_TEST(SmallVectorTest, InsertRepeatedAtEndTest) { SCOPED_TRACE("InsertRepeatedTest"); @@ -582,6 +581,7 @@ TYPED_TEST(SmallVectorTest, InsertRangeTest) { this->assertValuesInOrder(this->theVector, 6u, 1, 77, 77, 77, 2, 3); } + TYPED_TEST(SmallVectorTest, InsertRangeAtEndTest) { SCOPED_TRACE("InsertRangeTest"); @@ -748,14 +748,11 @@ TEST(SmallVectorCustomTest, NoAssignTest) { struct MovedFrom { bool hasValue; - MovedFrom() : hasValue(true) { } - MovedFrom(MovedFrom&& m) : hasValue(m.hasValue) { m.hasValue = false; } - MovedFrom &operator=(MovedFrom&& m) { hasValue = m.hasValue; m.hasValue = false; @@ -778,7 +775,6 @@ enum EmplaceableArgState { EAS_RValue, EAS_Failure }; - template <int I> struct EmplaceableArg { EmplaceableArgState State; EmplaceableArg() : State(EAS_Defaulted) {} @@ -928,4 +924,4 @@ TEST(SmallVectorTest, InitializerList) { EXPECT_TRUE(makeArrayRef(V2).equals({4, 5, 3, 2})); } -} // end anonymous namespace +} // end namespace diff --git a/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp index fa7d7780a8a..776d26970a3 100644 --- a/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp +++ b/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp @@ -13,10 +13,10 @@ #include "llvm-c/OrcBindings.h" #include "llvm-c/Target.h" #include "llvm-c/TargetMachine.h" -#include "llvm/ADT/Triple.h" -#include <cstring> -#include <memory> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> namespace llvm { @@ -157,4 +157,4 @@ TEST_F(OrcCAPIExecutionTest, TestDirectCallbacksAPI) { LLVMOrcDisposeInstance(JIT); } -} // end namespace llvm +} // namespace llvm diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp index bb8a9487402..eac669f467b 100644 --- a/unittests/Support/CommandLineTest.cpp +++ b/unittests/Support/CommandLineTest.cpp @@ -7,17 +7,12 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringMap.h" -#include "llvm/ADT/StringRef.h" #include "llvm/Config/config.h" -#include "llvm/Support/Allocator.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/StringSaver.h" #include "gtest/gtest.h" -#include <cstdlib> +#include <stdlib.h> #include <string> using namespace llvm; @@ -25,7 +20,7 @@ using namespace llvm; namespace { class TempEnvVar { -public: + public: TempEnvVar(const char *name, const char *value) : name(name) { const char *old_value = getenv(name); @@ -46,14 +41,13 @@ public: #endif } -private: + private: const char *const name; }; template <typename T> class StackOption : public cl::opt<T> { typedef cl::opt<T> Base; - public: // One option... template<class M0t> @@ -75,6 +69,7 @@ public: ~StackOption() override { this->removeArgument(); } }; + cl::OptionCategory TestCategory("Test Options", "Description"); TEST(CommandLineTest, ModifyExisitingOption) { StackOption<int> TestOption("test-option", cl::desc("old description")); @@ -270,4 +265,4 @@ TEST(CommandLineTest, HideUnrelatedOptionsMulti) { << "Hid default option that should be visable."; } -} // end anonymous namespace +} // anonymous namespace diff --git a/unittests/Support/ProgramTest.cpp b/unittests/Support/ProgramTest.cpp index cee9f0bddae..deadaadec1d 100644 --- a/unittests/Support/ProgramTest.cpp +++ b/unittests/Support/ProgramTest.cpp @@ -7,19 +7,13 @@ // //===----------------------------------------------------------------------===// -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringRef.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Program.h" -#include "llvm/Support/raw_ostream.h" #include "gtest/gtest.h" -#include <cstdlib> -#include <cstring> -#include <string> -#include <vector> +#include <stdlib.h> #if defined(__APPLE__) # include <crt_externs.h> #elif !defined(_MSC_VER) @@ -51,7 +45,6 @@ void sleep_for(unsigned int seconds) { GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ } else { \ } - // From TestMain.cpp. extern const char *TestMainArgv0; @@ -60,9 +53,9 @@ namespace { using namespace llvm; using namespace sys; -cl::opt<std::string> +static cl::opt<std::string> ProgramTestStringArg1("program-test-string-arg1"); -cl::opt<std::string> +static cl::opt<std::string> ProgramTestStringArg2("program-test-string-arg2"); class ProgramEnvTest : public testing::Test { @@ -316,6 +309,7 @@ TEST(ProgramTest, TestExecuteNegative) { ASSERT_TRUE(ExecutionFailed); ASSERT_FALSE(Error.empty()); } + } #ifdef LLVM_ON_WIN32 diff --git a/unittests/Support/StreamingMemoryObjectTest.cpp b/unittests/Support/StreamingMemoryObjectTest.cpp index cb1520b2edc..836dfa9084f 100644 --- a/unittests/Support/StreamingMemoryObjectTest.cpp +++ b/unittests/Support/StreamingMemoryObjectTest.cpp @@ -11,7 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/StreamingMemoryObject.h" #include "gtest/gtest.h" -#include <cstring> +#include <string.h> using namespace llvm; @@ -65,4 +65,4 @@ TEST(StreamingMemoryObjectTest, getPointer) { EXPECT_TRUE(std::equal(InputBuffer, InputBuffer + 8, O.getPointer(0, 20))); } -} // end anonymous namespace +} // end namespace diff --git a/unittests/Support/TimeValueTest.cpp b/unittests/Support/TimeValueTest.cpp index 59af5c3044d..3d2b9780c06 100644 --- a/unittests/Support/TimeValueTest.cpp +++ b/unittests/Support/TimeValueTest.cpp @@ -9,12 +9,9 @@ #include "gtest/gtest.h" #include "llvm/Support/TimeValue.h" -#include <cstdint> -#include <cstdlib> -#include <ctime> +#include <time.h> using namespace llvm; - namespace { TEST(TimeValue, time_t) { @@ -40,4 +37,4 @@ TEST(TimeValue, Win32FILETIME) { EXPECT_EQ(ft1970, epoch.toWin32Time()); } -} // end anonymous namespace +} diff --git a/unittests/Support/TimerTest.cpp b/unittests/Support/TimerTest.cpp index 8f05b353476..f556a3f72c6 100644 --- a/unittests/Support/TimerTest.cpp +++ b/unittests/Support/TimerTest.cpp @@ -13,7 +13,7 @@ #if LLVM_ON_WIN32 #include <windows.h> #else -#include <ctime> +#include <time.h> #endif using namespace llvm; @@ -62,4 +62,4 @@ TEST(Timer, CheckIfTriggered) { EXPECT_FALSE(T1.hasTriggered()); } -} // end anonymous namespace +} // end anon namespace |