Index: llvm/trunk/lib/Support/APFloat.cpp =================================================================== --- llvm/trunk/lib/Support/APFloat.cpp +++ llvm/trunk/lib/Support/APFloat.cpp @@ -14,14 +14,19 @@ #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 +#include +#include #include -#include +#include using namespace llvm; @@ -93,18 +98,21 @@ 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. */ -static inline unsigned int +inline unsigned int partCountForBits(unsigned int bits) { return ((bits) + integerPartWidth - 1) / integerPartWidth; } /* Returns 0U-9U. Return values >= 10U are not digits. */ -static inline unsigned int +inline unsigned int decDigitValue(unsigned int c) { return c - '0'; @@ -115,7 +123,7 @@ If the exponent overflows, returns a large exponent with the appropriate sign. */ -static int +int readExponent(StringRef::iterator begin, StringRef::iterator end) { bool isNegative; @@ -159,7 +167,7 @@ /* This is ugly and needs cleaning up, but I don't immediately see how whilst remaining safe. */ -static int +int totalExponent(StringRef::iterator p, StringRef::iterator end, int exponentAdjustment) { @@ -208,7 +216,7 @@ return exponent; } -static StringRef::iterator +StringRef::iterator skipLeadingZeroesAndAnyDot(StringRef::iterator begin, StringRef::iterator end, StringRef::iterator *dot) { @@ -249,7 +257,7 @@ int normalizedExponent; }; -static void +void interpretDecimal(StringRef::iterator begin, StringRef::iterator end, decimalInfo *D) { @@ -308,7 +316,7 @@ /* Return the trailing fraction of a hexadecimal number. DIGITVALUE is the first hex digit of the fraction, P points to the next digit. */ -static lostFraction +lostFraction trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end, unsigned int digitValue) { @@ -339,7 +347,7 @@ /* Return the fraction lost were a bignum truncated losing the least significant BITS bits. */ -static lostFraction +lostFraction lostFractionThroughTruncation(const integerPart *parts, unsigned int partCount, unsigned int bits) @@ -361,7 +369,7 @@ } /* Shift DST right BITS bits noting lost fraction. */ -static lostFraction +lostFraction shiftRight(integerPart *dst, unsigned int parts, unsigned int bits) { lostFraction lost_fraction; @@ -374,7 +382,7 @@ } /* Combine the effect of two lost fractions. */ -static lostFraction +lostFraction combineLostFractions(lostFraction moreSignificant, lostFraction lessSignificant) { @@ -395,7 +403,7 @@ See "How to Read Floating Point Numbers Accurately" by William D Clinger. */ -static unsigned int +unsigned int HUerrBound(bool inexactMultiply, unsigned int HUerr1, unsigned int HUerr2) { assert(HUerr1 < 2 || HUerr2 < 2 || (HUerr1 + HUerr2 < 8)); @@ -409,7 +417,7 @@ /* The number of ulps from the boundary (zero, or half if ISNEAREST) when the least significant BITS are truncated. BITS cannot be zero. */ -static integerPart +integerPart ulpsFromBoundary(const integerPart *parts, unsigned int bits, bool isNearest) { unsigned int count, partBits; @@ -454,7 +462,7 @@ /* Place pow(5, power) in DST, and return the number of parts used. DST must be at least one part larger than size of the answer. */ -static unsigned int +unsigned int powerOf5(integerPart *dst, unsigned int power) { static const integerPart firstEightPowers[] = { 1, 5, 25, 125, 625, 3125, @@ -517,17 +525,17 @@ /* Zero at the end to avoid modular arithmetic when adding one; used when rounding up during hexadecimal output. */ -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"; +const char hexDigitsLower[] = "0123456789abcdef0"; +const char hexDigitsUpper[] = "0123456789ABCDEF0"; +const char infinityL[] = "infinity"; +const char infinityU[] = "INFINITY"; +const char NaNL[] = "nan"; +const char NaNU[] = "NAN"; /* Write out an integerPart in hexadecimal, starting with the most significant nibble. Write out exactly COUNT hexdigits, return COUNT. */ -static unsigned int +unsigned int partAsHex (char *dst, integerPart part, unsigned int count, const char *hexDigitChars) { @@ -545,7 +553,7 @@ } /* Write out an unsigned decimal integer. */ -static char * +char * writeUnsignedDecimal (char *dst, unsigned int n) { char buff[40], *p; @@ -563,7 +571,7 @@ } /* Write out a signed decimal integer. */ -static char * +char * writeSignedDecimal (char *dst, int value) { if (value < 0) { @@ -575,6 +583,8 @@ return dst; } +} // end anonymous namespace + /* Constructors. */ void APFloat::initialize(const fltSemantics *ourSemantics) @@ -852,11 +862,13 @@ { return semantics.precision; } + APFloat::ExponentType APFloat::semanticsMaxExponent(const fltSemantics &semantics) { return semantics.maxExponent; } + APFloat::ExponentType APFloat::semanticsMinExponent(const fltSemantics &semantics) { @@ -1907,7 +1919,6 @@ return fs; } - /* Comparison requires normalized numbers. */ APFloat::cmpResult APFloat::compare(const APFloat &rhs) const @@ -2558,14 +2569,16 @@ /* 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 > INT_MAX / 42039) { + } else if (D.normalizedExponent - 1 > + std::numeric_limits::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 < INT_MIN / 42039 || + } else if ((D.normalizedExponent - 1 < + std::numeric_limits::min() / 42039) || (D.normalizedExponent + 1) * 28738 <= 8651 * (semantics->minExponent - (int) semantics->precision)) { /* Underflow to zero and round. */ @@ -3219,7 +3232,7 @@ uint64_t mysignificand2 = i2 & 0xffffffffffffLL; initialize(&APFloat::IEEEquad); - assert(partCount()==2); + assert(partCount() == 2); sign = static_cast(i2>>63); if (myexponent==0 && @@ -3485,6 +3498,7 @@ } namespace { + void append(SmallVectorImpl &Buffer, StringRef Str) { Buffer.append(Str.begin(), Str.end()); } @@ -3521,7 +3535,6 @@ significand = significand.trunc(significand.getActiveBits()); } - void AdjustToPrecision(SmallVectorImpl &buffer, int &exp, unsigned FormatPrecision) { unsigned N = buffer.size(); @@ -3566,7 +3579,8 @@ exp += FirstSignificant; buffer.erase(&buffer[0], &buffer[FirstSignificant]); } -} + +} // end anonymous namespace void APFloat::toString(SmallVectorImpl &Str, unsigned FormatPrecision, Index: llvm/trunk/lib/Support/CrashRecoveryContext.cpp =================================================================== --- llvm/trunk/lib/Support/CrashRecoveryContext.cpp +++ llvm/trunk/lib/Support/CrashRecoveryContext.cpp @@ -8,19 +8,23 @@ //===----------------------------------------------------------------------===// #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 +#include "llvm/Support/Threading.h" +#include +#include + using namespace llvm; namespace { struct CrashRecoveryContextImpl; -static ManagedStatic< +ManagedStatic< sys::ThreadLocal > CurrentContext; struct CrashRecoveryContextImpl { @@ -42,6 +46,7 @@ Next = CurrentContext->get(); CurrentContext->set(this); } + ~CrashRecoveryContextImpl() { if (!SwitchedThread) CurrentContext->set(Next); @@ -70,14 +75,14 @@ } }; -} +ManagedStatic gCrashRecoveryContextMutex; +bool gCrashRecoveryEnabled = false; -static ManagedStatic gCrashRecoveryContextMutex; -static bool gCrashRecoveryEnabled = false; - -static ManagedStatic> +ManagedStatic> tlIsRecoveringFromCrash; +} // end anonymous namespace + CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} CrashRecoveryContext::~CrashRecoveryContext() { @@ -162,7 +167,9 @@ // SetUnhandledExceptionFilter API, but there's a risk of that // being entirely overwritten (it's not a chain). -static LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) +namespace { + +LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -190,7 +197,9 @@ // 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. -static sys::ThreadLocal sCurrentExceptionHandle; +sys::ThreadLocal sCurrentExceptionHandle; + +} // end anonymous namespace void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -239,14 +248,15 @@ // reliable fashion -- if we get a signal outside of a crash recovery context we // simply disable crash recovery and raise the signal again. -#include +#include -static const int Signals[] = - { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; -static const unsigned NumSignals = array_lengthof(Signals); -static struct sigaction PrevActions[NumSignals]; +namespace { -static void CrashRecoverySignalHandler(int Signal) { +const int Signals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; +const unsigned NumSignals = array_lengthof(Signals); +struct sigaction PrevActions[NumSignals]; + +void CrashRecoverySignalHandler(int Signal) { // Lookup the current thread local recovery object. const CrashRecoveryContextImpl *CRCI = CurrentContext->get(); @@ -278,6 +288,8 @@ const_cast(CRCI)->HandleCrash(); } +} // end anonymous namespace + void CrashRecoveryContext::Enable() { sys::ScopedLock L(*gCrashRecoveryContextMutex); @@ -334,14 +346,16 @@ CRCI->HandleCrash(); } +namespace { + // FIXME: Portability. -static void setThreadBackgroundPriority() { +void setThreadBackgroundPriority() { #ifdef __APPLE__ setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG); #endif } -static bool hasThreadBackgroundPriority() { +bool hasThreadBackgroundPriority() { #ifdef __APPLE__ return getpriority(PRIO_DARWIN_THREAD, 0) == 1; #else @@ -349,16 +363,14 @@ #endif } -namespace { struct RunSafelyOnThreadInfo { function_ref Fn; CrashRecoveryContext *CRC; bool UseBackgroundPriority; bool Result; }; -} -static void RunSafelyOnThread_Dispatch(void *UserData) { +void RunSafelyOnThread_Dispatch(void *UserData) { RunSafelyOnThreadInfo *Info = reinterpret_cast(UserData); @@ -367,6 +379,9 @@ Info->Result = Info->CRC->RunSafely(Info->Fn); } + +} // end anonymous namespace + bool CrashRecoveryContext::RunSafelyOnThread(function_ref Fn, unsigned RequestedStackSize) { bool UseBackgroundPriority = hasThreadBackgroundPriority(); Index: llvm/trunk/lib/Support/Errno.cpp =================================================================== --- llvm/trunk/lib/Support/Errno.cpp +++ llvm/trunk/lib/Support/Errno.cpp @@ -14,11 +14,9 @@ #include "llvm/Support/Errno.h" #include "llvm/Config/config.h" // Get autoconf configuration settings #include "llvm/Support/raw_ostream.h" -#include - -#if HAVE_ERRNO_H -#include -#endif +#include +#include +#include //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system @@ -32,7 +30,7 @@ std::string StrError() { return StrError(errno); } -#endif // HAVE_ERRNO_H +#endif // HAVE_ERRNO_H std::string StrError(int errnum) { std::string str; @@ -72,5 +70,5 @@ return str; } -} // namespace sys -} // namespace llvm +} // namespace sys +} // namespace llvm Index: llvm/trunk/lib/Support/Host.cpp =================================================================== --- llvm/trunk/lib/Support/Host.cpp +++ llvm/trunk/lib/Support/Host.cpp @@ -19,8 +19,8 @@ #include "llvm/Config/config.h" #include "llvm/Support/Debug.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/raw_ostream.h" -#include +#include +#include // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX @@ -49,8 +49,10 @@ using namespace llvm; +namespace { + #if defined(__linux__) -static ssize_t LLVM_ATTRIBUTE_UNUSED readCpuInfo(void *Buf, size_t Size) { +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). @@ -74,8 +76,8 @@ /// GetX86CpuIDAndInfo - Execute the specified cpuid and return the 4 values in the /// specified arguments. If we can't run cpuid on the host, return true. -static bool GetX86CpuIDAndInfo(unsigned value, unsigned *rEAX, unsigned *rEBX, - unsigned *rECX, unsigned *rEDX) { +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. @@ -120,9 +122,8 @@ /// 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. -static bool GetX86CpuIDAndInfoEx(unsigned value, unsigned subleaf, - unsigned *rEAX, unsigned *rEBX, unsigned *rECX, - unsigned *rEDX) { +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. @@ -182,7 +183,7 @@ #endif } -static bool GetX86XCR0(unsigned *rEAX, unsigned *rEDX) { +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 @@ -199,8 +200,7 @@ #endif } -static void DetectX86FamilyModel(unsigned EAX, unsigned &Family, - unsigned &Model) { +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,6 +212,8 @@ } } +} // end anonymous namespace + StringRef sys::getHostCPUName() { unsigned EAX = 0, EBX = 0, ECX = 0, EDX = 0; if (GetX86CpuIDAndInfo(0x1, &EAX, &EBX, &ECX, &EDX)) Index: llvm/trunk/lib/Support/MathExtras.cpp =================================================================== --- llvm/trunk/lib/Support/MathExtras.cpp +++ llvm/trunk/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 #else -#include +#include #endif namespace llvm { @@ -29,4 +29,4 @@ const float huge_valf = HUGE_VALF; #endif -} +} // end namespace llvm Index: llvm/trunk/lib/Support/Mutex.cpp =================================================================== --- llvm/trunk/lib/Support/Mutex.cpp +++ llvm/trunk/lib/Support/Mutex.cpp @@ -22,22 +22,26 @@ #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 +#include #include -#include namespace llvm { + using namespace sys; // Construct a Mutex using pthread calls @@ -110,7 +114,7 @@ return errorcode == 0; } -} +} // end namespace llvm #elif defined(LLVM_ON_UNIX) #include "Unix/Mutex.inc" Index: llvm/trunk/lib/Support/RWMutex.cpp =================================================================== --- llvm/trunk/lib/Support/RWMutex.cpp +++ llvm/trunk/lib/Support/RWMutex.cpp @@ -13,7 +13,6 @@ #include "llvm/Config/config.h" #include "llvm/Support/RWMutex.h" -#include //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system @@ -23,23 +22,27 @@ #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 +#include #include -#include namespace llvm { + using namespace sys; // Construct a RWMutex using pthread calls @@ -113,7 +116,7 @@ return errorcode == 0; } -} +} // end namespace llvm #elif defined(LLVM_ON_UNIX) #include "Unix/RWMutex.inc" Index: llvm/trunk/lib/Support/SHA1.cpp =================================================================== --- llvm/trunk/lib/Support/SHA1.cpp +++ llvm/trunk/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,12 +13,13 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Host.h" #include "llvm/Support/SHA1.h" -using namespace llvm; -#include -#include +#include + +using namespace llvm; #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN #define SHA_BIG_ENDIAN @@ -46,10 +47,14 @@ InternalState.BufferOffset = 0; } -static uint32_t rol32(uint32_t number, uint8_t bits) { +namespace { + +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; Index: llvm/trunk/lib/Support/SearchForAddressOfSpecialSymbol.cpp =================================================================== --- llvm/trunk/lib/Support/SearchForAddressOfSpecialSymbol.cpp +++ llvm/trunk/lib/Support/SearchForAddressOfSpecialSymbol.cpp @@ -14,10 +14,12 @@ // //===----------------------------------------------------------------------===// -#include +#include + +namespace { // Must declare the symbols in the global namespace. -static void *DoSearch(const char* symbolName) { +void *DoSearch(const char* symbolName) { #define EXPLICIT_SYMBOL(SYM) \ extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM @@ -51,8 +53,12 @@ return nullptr; } +} // end anonymous namespace + namespace llvm { + void *SearchForAddressOfSpecialSymbol(const char* symbolName) { return DoSearch(symbolName); } -} // namespace llvm + +} // end namespace llvm Index: llvm/trunk/lib/Support/Unix/Path.inc =================================================================== --- llvm/trunk/lib/Support/Unix/Path.inc +++ llvm/trunk/lib/Support/Unix/Path.inc @@ -17,8 +17,9 @@ //===----------------------------------------------------------------------===// #include "Unix.h" -#include -#include +#include +#include +#include #if HAVE_SYS_STAT_H #include #endif @@ -86,7 +87,10 @@ #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \ defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \ defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) -static int + +namespace { + +int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { struct stat sb; @@ -101,7 +105,7 @@ return 0; } -static char * +char * getprogpath(char ret[PATH_MAX], const char *bin) { char *pv, *s, *t; @@ -138,6 +142,9 @@ free(pv); return nullptr; } + +} // end anonymous namespace + #endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__ /// GetMainExecutable - Return the path to the main executable, given the @@ -330,7 +337,9 @@ return std::error_code(); } -static int convertAccessMode(AccessMode Mode) { +namespace { + +int convertAccessMode(AccessMode Mode) { switch (Mode) { case AccessMode::Exist: return F_OK; @@ -342,6 +351,8 @@ llvm_unreachable("invalid enum"); } +} // end anonymous namespace + std::error_code access(const Twine &Path, AccessMode Mode) { SmallString<128> PathStorage; StringRef P = Path.toNullTerminatedStringRef(PathStorage); @@ -381,8 +392,10 @@ return std::error_code(); } -static std::error_code fillStatus(int StatRet, const struct stat &Status, - file_status &Result) { +namespace { + +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) @@ -416,6 +429,8 @@ 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); @@ -597,7 +612,9 @@ return false; } -static bool getDarwinConfDir(bool TempDir, SmallVectorImpl &Result) { +namespace { + +bool getDarwinConfDir(bool TempDir, SmallVectorImpl &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 on darwin >= 9 @@ -622,7 +639,7 @@ return false; } -static bool getUserCacheDir(SmallVectorImpl &Result) { +bool getUserCacheDir(SmallVectorImpl &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 @@ -645,7 +662,7 @@ return false; } -static const char *getEnvTempDir() { +const char *getEnvTempDir() { // Check whether the temporary directory is specified by an environment // variable. const char *EnvironmentVariables[] = {"TMPDIR", "TMP", "TEMP", "TEMPDIR"}; @@ -657,7 +674,7 @@ return nullptr; } -static const char *getDefaultTempDir(bool ErasedOnReboot) { +const char *getDefaultTempDir(bool ErasedOnReboot) { #ifdef P_tmpdir if ((bool)P_tmpdir) return P_tmpdir; @@ -668,6 +685,8 @@ return "/var/tmp"; } +} // end anonymous namespace + void system_temp_directory(bool ErasedOnReboot, SmallVectorImpl &Result) { Result.clear(); Index: llvm/trunk/lib/Support/Unix/Process.inc =================================================================== --- llvm/trunk/lib/Support/Unix/Process.inc +++ llvm/trunk/lib/Support/Unix/Process.inc @@ -30,9 +30,7 @@ #ifdef HAVE_SYS_STAT_H #include #endif -#if HAVE_SIGNAL_H -#include -#endif +#include // DragonFlyBSD, OpenBSD, and Bitrig have deprecated for // instead. Unix.h includes this for us already. #if defined(HAVE_MALLOC_H) && !defined(__DragonFly__) && \ @@ -60,7 +58,9 @@ using namespace llvm; using namespace sys; -static std::pair getRUsageTimes() { +namespace { + +std::pair getRUsageTimes() { #if defined(HAVE_GETRUSAGE) struct rusage RU; ::getrusage(RUSAGE_SELF, &RU); @@ -79,6 +79,8 @@ #endif } +} // end anonymous namespace + // On Cygwin, getpagesize() returns 64k(AllocationGranularity) and // offset in mmap(3) should be aligned to the AllocationGranularity. unsigned Process::getPageSize() { @@ -189,6 +191,7 @@ } namespace { + class FDCloser { public: FDCloser(int &FD) : FD(FD), KeepOpen(false) {} @@ -205,7 +208,8 @@ int &FD; bool KeepOpen; }; -} + +} // end anonymous namespace std::error_code Process::FixupStandardFileDescriptors() { int NullFD = -1; @@ -300,7 +304,9 @@ #endif } -static unsigned getColumns(int FileID) { +namespace { + +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); @@ -320,6 +326,8 @@ return Columns; } +} // end anonymous namespace + unsigned Process::StandardOutColumns() { if (!StandardOutIsDisplayed()) return 0; @@ -344,11 +352,13 @@ extern "C" int tigetnum(char *capname); #endif +namespace { + #ifdef HAVE_TERMINFO -static ManagedStatic TermColorMutex; +ManagedStatic TermColorMutex; #endif -static bool terminalHasColors(int fd) { +bool terminalHasColors(int fd) { #ifdef HAVE_TERMINFO // First, acquire a global lock because these C routines are thread hostile. MutexGuard G(*TermColorMutex); @@ -388,6 +398,8 @@ return false; } +} // end anonymous namespace + bool Process::FileDescriptorHasColors(int fd) { // A file descriptor has colors if it is displayed and the terminal has // colors. @@ -428,7 +440,10 @@ } #if !defined(HAVE_DECL_ARC4RANDOM) || !HAVE_DECL_ARC4RANDOM -static unsigned GetRandomNumberSeed() { + +namespace { + +unsigned GetRandomNumberSeed() { // Attempt to get the initial seed from /dev/urandom, if possible. int urandomFD = open("/dev/urandom", O_RDONLY); @@ -450,6 +465,9 @@ TimeValue Now = TimeValue::now(); return hash_combine(Now.seconds(), Now.nanoseconds(), ::getpid()); } + +} // end anonymous namespace + #endif unsigned llvm::sys::Process::GetRandomNumber() { Index: llvm/trunk/lib/Support/Unix/Program.inc =================================================================== --- llvm/trunk/lib/Support/Unix/Program.inc +++ llvm/trunk/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,9 +30,7 @@ #if HAVE_SYS_RESOURCE_H #include #endif -#if HAVE_SIGNAL_H -#include -#endif +#include #if HAVE_FCNTL_H #include #endif @@ -96,7 +94,9 @@ return errc::no_such_file_or_directory; } -static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { +namespace { + +bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { if (!Path) // Noop return false; std::string File; @@ -125,8 +125,8 @@ } #ifdef HAVE_POSIX_SPAWN -static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, - posix_spawn_file_actions_t *FileActions) { +bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg, + posix_spawn_file_actions_t *FileActions) { if (!Path) // Noop return false; const char *File; @@ -144,10 +144,10 @@ } #endif -static void TimeOutHandler(int Sig) { +void TimeOutHandler(int Sig) { } -static void SetMemoryLimits (unsigned size) +void SetMemoryLimits (unsigned size) { #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT struct rlimit r; @@ -176,7 +176,9 @@ #endif } -} +} // end anonymous namespace + +} // end namespace llvm static bool Execute(ProcessInfo &PI, StringRef Program, const char **args, const char **envp, const StringRef **redirects, @@ -419,12 +421,12 @@ return WaitResult; } - std::error_code sys::ChangeStdinToBinary(){ +std::error_code sys::ChangeStdinToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); } - std::error_code sys::ChangeStdoutToBinary(){ +std::error_code sys::ChangeStdoutToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); } @@ -466,4 +468,5 @@ } return true; } -} + +} // end namespace llvm Index: llvm/trunk/lib/Support/Unix/Signals.inc =================================================================== --- llvm/trunk/lib/Support/Unix/Signals.inc +++ llvm/trunk/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,9 +27,7 @@ #if HAVE_EXECINFO_H # include // For backtrace(). #endif -#if HAVE_SIGNAL_H -#include -#endif +#include #if HAVE_SYS_STAT_H #include #endif @@ -48,25 +46,27 @@ using namespace llvm; -static RETSIGTYPE SignalHandler(int Sig); // defined below. +namespace { + +RETSIGTYPE SignalHandler(int Sig); // defined below. -static ManagedStatic > SignalsMutex; +ManagedStatic > SignalsMutex; /// InterruptFunction - The function to call if ctrl-c is pressed. -static void (*InterruptFunction)() = nullptr; +void (*InterruptFunction)() = nullptr; -static ManagedStatic> FilesToRemove; +ManagedStatic> 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. -static const int IntSigs[] = { +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. -static const int KillSigs[] = { +const int KillSigs[] = { SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT #ifdef SIGSYS , SIGSYS @@ -82,14 +82,13 @@ #endif }; -static unsigned NumRegisteredSignals = 0; -static struct { +unsigned NumRegisteredSignals = 0; +struct { struct sigaction SA; int SigNo; } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)]; - -static void RegisterHandler(int Signal) { +void RegisterHandler(int Signal) { assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && "Out of space for signal handlers!"); @@ -106,7 +105,7 @@ ++NumRegisteredSignals; } -static void RegisterHandlers() { +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 @@ -120,7 +119,7 @@ for (auto S : KillSigs) RegisterHandler(S); } -static void UnregisterHandlers() { +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, @@ -128,12 +127,11 @@ 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. -static void RemoveFilesToRemove() { +void RemoveFilesToRemove() { // Avoid constructing ManagedStatic in the signal handler. // If FilesToRemove is not constructed, there are no files to remove. if (!FilesToRemove.isConstructed()) @@ -164,7 +162,7 @@ } // SignalHandler - The signal handler that runs. -static RETSIGTYPE SignalHandler(int Sig) { +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 @@ -209,6 +207,8 @@ #endif } +} // end anonymous namespace + void llvm::sys::RunInterruptHandlers() { sys::SmartScopedLock Guard(*SignalsMutex); RemoveFilesToRemove(); @@ -264,7 +264,9 @@ const char *main_exec_name; }; -static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { +namespace { + +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; @@ -287,6 +289,8 @@ 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, @@ -375,10 +379,14 @@ #endif } -static void PrintStackTraceSignalHandler(void *) { +namespace { + +void PrintStackTraceSignalHandler(void *) { PrintStackTrace(llvm::errs()); } +} // end anonymous namespace + void llvm::sys::DisableSystemDialogsOnCrash() {} /// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or @@ -403,9 +411,6 @@ #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 Index: llvm/trunk/lib/Support/Unix/ThreadLocal.inc =================================================================== --- llvm/trunk/lib/Support/Unix/ThreadLocal.inc +++ llvm/trunk/lib/Support/Unix/ThreadLocal.inc @@ -19,10 +19,11 @@ #if defined(HAVE_PTHREAD_H) && defined(HAVE_PTHREAD_GETSPECIFIC) #include +#include #include -#include namespace llvm { + using namespace sys; ThreadLocalImpl::ThreadLocalImpl() : data() { @@ -56,14 +57,19 @@ 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(d);} void *ThreadLocalImpl::getInstance() { return data; } void ThreadLocalImpl::removeInstance() { setInstance(0); } -} + +} // end namespace llvm + #endif Index: llvm/trunk/lib/Support/Unix/Unix.h =================================================================== --- llvm/trunk/lib/Support/Unix/Unix.h +++ llvm/trunk/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 -#include +#include #include #include #include @@ -42,7 +42,7 @@ #ifdef HAVE_SYS_TIME_H # include #endif -#include +#include #ifdef HAVE_DLFCN_H # include @@ -65,4 +65,4 @@ return true; } -#endif +#endif // LLVM_LIB_SUPPORT_UNIX_UNIX_H Index: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp =================================================================== --- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp +++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -34,7 +34,8 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include +#include + using namespace llvm; #define DEBUG_TYPE "x86-isel" @@ -141,7 +142,7 @@ } #endif }; -} +} // end anonymous namespace namespace { //===--------------------------------------------------------------------===// @@ -301,7 +302,6 @@ // 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,8 +393,7 @@ return true; } }; -} - +} // end anonymous namespace bool X86DAGToDAGISel::IsProfitableToFold(SDValue N, SDNode *U, SDNode *Root) const { @@ -459,10 +458,12 @@ 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. -static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, - SDValue Call, SDValue OrigChain) { +void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, + SDValue OrigChain) { SmallVector Ops; SDValue Chain = OrigChain.getOperand(0); if (Chain.getNode() == Load.getNode()) @@ -496,7 +497,7 @@ /// 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. -static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) { +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 @@ -533,6 +534,8 @@ return false; } +} // end anonymous namespace + void X86DAGToDAGISel::PreprocessISelDAG() { // OptFor[Min]Size are used in pattern predicates that isel is matching. OptForSize = MF->getFunction()->optForSize(); @@ -651,7 +654,6 @@ } } - /// Emit any code that needs to be executed only in the main function. void X86DAGToDAGISel::emitSpecialCodeForMain() { if (Subtarget->isTargetCygMing()) { @@ -676,7 +678,9 @@ emitSpecialCodeForMain(); } -static bool isDispSafeForFrameIndex(int64_t Val) { +namespace { + +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 @@ -686,6 +690,8 @@ return isInt<31>(Val); } +} // end anonymous namespace + bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t Offset, X86ISelAddressMode &AM) { // Cannot combine ExternalSymbol displacements with integer offsets. @@ -705,7 +711,6 @@ } AM.Disp = Val; return false; - } bool X86DAGToDAGISel::matchLoadInAddress(LoadSDNode *N, X86ISelAddressMode &AM){ @@ -896,12 +901,14 @@ 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. -static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N) { +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()); @@ -913,10 +920,9 @@ // 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. -static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !isa(Shift.getOperand(1)) || !Shift.hasOneUse()) @@ -956,10 +962,9 @@ // 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. -static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, + X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SHL || !isa(Shift.getOperand(1))) return true; @@ -1023,10 +1028,8 @@ // 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. -static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, - uint64_t Mask, - SDValue Shift, SDValue X, - X86ISelAddressMode &AM) { +bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, + SDValue Shift, SDValue X, X86ISelAddressMode &AM) { if (Shift.getOpcode() != ISD::SRL || !Shift.hasOneUse() || !isa(Shift.getOperand(1))) return true; @@ -1104,6 +1107,8 @@ return false; } +} // end anonymous namespace + bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM, unsigned Depth) { SDLoc dl(N); @@ -1418,7 +1423,6 @@ bool X86DAGToDAGISel::selectVectorAddr(SDNode *Parent, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, SDValue &Segment) { - MaskedGatherScatterSDNode *Mgs = dyn_cast(Parent); if (!Mgs) return false; @@ -1541,7 +1545,6 @@ return false; } - bool X86DAGToDAGISel::selectMOV64Imm32(SDValue N, SDValue &Imm) { if (const ConstantSDNode *CN = dyn_cast(N)) { uint64_t ImmVal = CN->getZExtValue(); @@ -1695,7 +1698,6 @@ return true; } - bool X86DAGToDAGISel::tryFoldLoad(SDNode *P, SDValue N, SDValue &Base, SDValue &Scale, SDValue &Index, SDValue &Disp, @@ -1718,9 +1720,11 @@ 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. -static bool hasNoSignedComparisonUses(SDNode *N) { +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) { @@ -1782,10 +1786,9 @@ /// Check whether or not the chain ending in StoreNode is suitable for doing /// the {load; increment or decrement; store} to modify transformation. -static bool isLoadIncOrDecStore(StoreSDNode *StoreNode, unsigned Opc, - SDValue StoredVal, SelectionDAG *CurDAG, - LoadSDNode* &LoadNode, SDValue &InputChain) { - +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; @@ -1867,7 +1870,7 @@ /// Get the appropriate X86 opcode for an in-memory increment or decrement. /// Opc should be X86ISD::DEC or X86ISD::INC. -static unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { +unsigned getFusedLdStOpcode(EVT &LdVT, unsigned Opc) { if (Opc == X86ISD::DEC) { if (LdVT == MVT::i64) return X86::DEC64m; if (LdVT == MVT::i32) return X86::DEC32m; @@ -1883,6 +1886,8 @@ 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 Index: llvm/trunk/tools/llvm-c-test/echo.cpp =================================================================== --- llvm/trunk/tools/llvm-c-test/echo.cpp +++ llvm/trunk/tools/llvm-c-test/echo.cpp @@ -16,12 +16,18 @@ //===----------------------------------------------------------------------===// #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 -#include +#include +#include +#include using namespace llvm; @@ -39,13 +45,16 @@ uintptr_t Val = static_cast(-1); return reinterpret_cast(Val); } + static inline T* getTombstoneKey() { uintptr_t Val = static_cast(-2); return reinterpret_cast(Val); } + static unsigned getHashValue(const T *PtrVal) { return hash_value(PtrVal); } + static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; } }; @@ -154,7 +163,9 @@ } }; -static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) { +namespace { + +ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) { unsigned Count = LLVMCountParams(Src); if (Count != LLVMCountParams(Dst)) report_fatal_error("Parameter count mismatch"); @@ -212,6 +223,8 @@ return VMap; } +} // end anonymous namespace + LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) { if (!LLVMIsAConstant(Cst)) report_fatal_error("Expected a constant"); @@ -710,7 +723,9 @@ } }; -static void declare_symbols(LLVMModuleRef Src, LLVMModuleRef M) { +namespace { + +void declare_symbols(LLVMModuleRef Src, LLVMModuleRef M) { LLVMValueRef Begin = LLVMGetFirstGlobal(Src); LLVMValueRef End = LLVMGetLastGlobal(Src); @@ -774,7 +789,7 @@ } } -static void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) { +void clone_symbols(LLVMModuleRef Src, LLVMModuleRef M) { LLVMValueRef Begin = LLVMGetFirstGlobal(Src); LLVMValueRef End = LLVMGetLastGlobal(Src); @@ -861,6 +876,8 @@ } } +} // end anonymous namespace + int llvm_echo(void) { LLVMEnablePrettyStackTrace(); Index: llvm/trunk/tools/llvm-c-test/llvm-c-test.h =================================================================== --- llvm/trunk/tools/llvm-c-test/llvm-c-test.h +++ llvm/trunk/tools/llvm-c-test/llvm-c-test.h @@ -10,10 +10,15 @@ |* Header file for llvm-c-test *| |* *| \*===----------------------------------------------------------------------===*/ + #ifndef LLVM_C_TEST_H #define LLVM_C_TEST_H +#ifdef __cplusplus +#include +#else #include +#endif #include "llvm-c/Core.h" #ifdef __cplusplus @@ -51,6 +56,6 @@ #ifdef __cplusplus } -#endif /* !defined(__cplusplus) */ - #endif + +#endif // LLVM_C_TEST_H Index: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp @@ -40,9 +40,14 @@ #include "llvm/Support/Win64EH.h" #include "llvm/Support/raw_ostream.h" #include -#include +#include +#include +#include +#include +#include +#include #include -#include +#include using namespace llvm; using namespace llvm::object; @@ -71,6 +76,7 @@ void printCOFFBaseReloc() override; void printCodeViewDebugInfo() override; void printStackMap() const override; + private: void printSymbol(const SymbolRef &Sym); void printRelocation(const SectionRef &Section, const RelocationRef &Reloc, @@ -144,8 +150,7 @@ StringSet<> TypeNames; }; -} // namespace - +} // end anonymous namespace namespace llvm { @@ -160,7 +165,7 @@ return readobj_error::success; } -} // namespace llvm +} // end namespace llvm // Given a a section and an offset into this section the function returns the // symbol used for the relocation at the offset. @@ -243,7 +248,9 @@ } } -static const EnumEntry ImageFileMachineType[] = { +namespace { + +const EnumEntry 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 ), @@ -267,7 +274,7 @@ LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_MACHINE_WCEMIPSV2) }; -static const EnumEntry ImageFileCharacteristics[] = { +const EnumEntry 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 ), @@ -285,7 +292,7 @@ LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_FILE_BYTES_REVERSED_HI ) }; -static const EnumEntry PEWindowsSubsystem[] = { +const EnumEntry 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 ), @@ -299,7 +306,7 @@ LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SUBSYSTEM_XBOX ), }; -static const EnumEntry PEDLLCharacteristics[] = { +const EnumEntry 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 ), @@ -313,7 +320,7 @@ LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE), }; -static const EnumEntry +const EnumEntry ImageSectionCharacteristics[] = { LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NOLOAD ), LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_TYPE_NO_PAD ), @@ -353,7 +360,7 @@ LLVM_READOBJ_ENUM_ENT(COFF, IMAGE_SCN_MEM_WRITE ) }; -static const EnumEntry ImageSymType[] = { +const EnumEntry ImageSymType[] = { { "Null" , COFF::IMAGE_SYM_TYPE_NULL }, { "Void" , COFF::IMAGE_SYM_TYPE_VOID }, { "Char" , COFF::IMAGE_SYM_TYPE_CHAR }, @@ -372,14 +379,14 @@ { "DWord" , COFF::IMAGE_SYM_TYPE_DWORD } }; -static const EnumEntry ImageSymDType[] = { +const EnumEntry 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 } }; -static const EnumEntry ImageSymClass[] = { +const EnumEntry ImageSymClass[] = { { "EndOfFunction" , COFF::IMAGE_SYM_CLASS_END_OF_FUNCTION }, { "Null" , COFF::IMAGE_SYM_CLASS_NULL }, { "Automatic" , COFF::IMAGE_SYM_CLASS_AUTOMATIC }, @@ -409,7 +416,7 @@ { "CLRToken" , COFF::IMAGE_SYM_CLASS_CLR_TOKEN } }; -static const EnumEntry ImageCOMDATSelect[] = { +const EnumEntry ImageCOMDATSelect[] = { { "NoDuplicates", COFF::IMAGE_COMDAT_SELECT_NODUPLICATES }, { "Any" , COFF::IMAGE_COMDAT_SELECT_ANY }, { "SameSize" , COFF::IMAGE_COMDAT_SELECT_SAME_SIZE }, @@ -419,14 +426,14 @@ { "Newest" , COFF::IMAGE_COMDAT_SELECT_NEWEST } }; -static const EnumEntry +const EnumEntry WeakExternalCharacteristics[] = { { "NoLibrary", COFF::IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY }, { "Library" , COFF::IMAGE_WEAK_EXTERN_SEARCH_LIBRARY }, { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS } }; -static const EnumEntry CompileSym3Flags[] = { +const EnumEntry CompileSym3Flags[] = { LLVM_READOBJ_ENUM_ENT(CompileSym3, EC), LLVM_READOBJ_ENUM_ENT(CompileSym3, NoDbgInfo), LLVM_READOBJ_ENUM_ENT(CompileSym3, LTCG), @@ -441,7 +448,7 @@ LLVM_READOBJ_ENUM_ENT(CompileSym3, Exp), }; -static const EnumEntry SourceLanguages[] = { +const EnumEntry SourceLanguages[] = { LLVM_READOBJ_ENUM_ENT(SourceLanguage, C), LLVM_READOBJ_ENUM_ENT(SourceLanguage, Cpp), LLVM_READOBJ_ENUM_ENT(SourceLanguage, Fortran), @@ -461,7 +468,7 @@ LLVM_READOBJ_ENUM_ENT(SourceLanguage, HLSL), }; -static const EnumEntry SubSectionTypes[] = { +const EnumEntry SubSectionTypes[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Symbols), LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, Lines), LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, StringTable), @@ -477,7 +484,7 @@ LLVM_READOBJ_ENUM_CLASS_ENT(ModuleSubstreamKind, CoffSymbolRVA), }; -static const EnumEntry CPUTypeNames[] = { +const EnumEntry CPUTypeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8080), LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel8086), LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, Intel80286), @@ -539,7 +546,7 @@ LLVM_READOBJ_ENUM_CLASS_ENT(CPUType, D3D11_Shader), }; -static const EnumEntry ProcSymFlags[] = { +const EnumEntry ProcSymFlags[] = { LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFP), LLVM_READOBJ_ENUM_ENT(ProcFlags, HasIRET), LLVM_READOBJ_ENUM_ENT(ProcFlags, HasFRET), @@ -550,7 +557,7 @@ LLVM_READOBJ_ENUM_ENT(ProcFlags, HasOptimizedDebugInfo), }; -static const EnumEntry FrameProcSymFlags[] = { +const EnumEntry FrameProcSymFlags[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasAlloca), LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasSetJmp), LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, HasLongJmp), @@ -576,13 +583,13 @@ LLVM_READOBJ_ENUM_CLASS_ENT(FrameProcedureOptions, GuardCfw), }; -static const EnumEntry FrameDataFlags[] = { +const EnumEntry FrameDataFlags[] = { LLVM_READOBJ_ENUM_ENT(FrameData, HasSEH), LLVM_READOBJ_ENUM_ENT(FrameData, HasEH), LLVM_READOBJ_ENUM_ENT(FrameData, IsFunctionStart), }; -static const EnumEntry LocalFlags[] = { +const EnumEntry LocalFlags[] = { LLVM_READOBJ_ENUM_ENT(LocalSym, IsParameter), LLVM_READOBJ_ENUM_ENT(LocalSym, IsAddressTaken), LLVM_READOBJ_ENUM_ENT(LocalSym, IsCompilerGenerated), @@ -596,14 +603,14 @@ LLVM_READOBJ_ENUM_ENT(LocalSym, IsEnregisteredStatic), }; -static const EnumEntry FrameCookieKinds[] = { +const EnumEntry 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), }; -static const EnumEntry ClassOptionNames[] = { +const EnumEntry ClassOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Packed), LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasConstructorOrDestructor), LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, HasOverloadedOperator), @@ -618,14 +625,14 @@ LLVM_READOBJ_ENUM_CLASS_ENT(ClassOptions, Intrinsic), }; -static const EnumEntry MemberAccessNames[] = { +const EnumEntry 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), }; -static const EnumEntry MethodOptionNames[] = { +const EnumEntry MethodOptionNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Pseudo), LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoInherit), LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, NoConstruct), @@ -633,7 +640,7 @@ LLVM_READOBJ_ENUM_CLASS_ENT(MethodOptions, Sealed), }; -static const EnumEntry MemberKindNames[] = { +const EnumEntry MemberKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Vanilla), LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Virtual), LLVM_READOBJ_ENUM_CLASS_ENT(MethodKind, Static), @@ -646,7 +653,7 @@ /// 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. -static const EnumEntry SimpleTypeNames[] = { +const EnumEntry SimpleTypeNames[] = { {"void*", SimpleTypeKind::Void}, {"*", SimpleTypeKind::NotTranslated}, {"HRESULT*", SimpleTypeKind::HResult}, @@ -687,12 +694,12 @@ {"__bool64*", SimpleTypeKind::Boolean64}, }; -static const EnumEntry LeafTypeNames[] = { +const EnumEntry LeafTypeNames[] = { #define LEAF_TYPE(name, val) LLVM_READOBJ_ENUM_ENT(TypeLeafKind, name), #include "llvm/DebugInfo/CodeView/CVLeafTypes.def" }; -static const EnumEntry PtrKindNames[] = { +const EnumEntry PtrKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near16), LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Far16), LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Huge16), @@ -708,7 +715,7 @@ LLVM_READOBJ_ENUM_CLASS_ENT(PointerKind, Near64), }; -static const EnumEntry PtrModeNames[] = { +const EnumEntry PtrModeNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, Pointer), LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, LValueReference), LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, PointerToDataMember), @@ -716,7 +723,7 @@ LLVM_READOBJ_ENUM_CLASS_ENT(PointerMode, RValueReference), }; -static const EnumEntry PtrMemberRepNames[] = { +const EnumEntry PtrMemberRepNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, Unknown), LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, SingleInheritanceData), @@ -734,13 +741,13 @@ LLVM_READOBJ_ENUM_CLASS_ENT(PointerToMemberRepresentation, GeneralFunction), }; -static const EnumEntry TypeModifierNames[] = { +const EnumEntry TypeModifierNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Const), LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Volatile), LLVM_READOBJ_ENUM_CLASS_ENT(ModifierOptions, Unaligned), }; -static const EnumEntry CallingConventions[] = { +const EnumEntry CallingConventions[] = { LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearC), LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, FarC), LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearPascal), @@ -767,13 +774,13 @@ LLVM_READOBJ_ENUM_CLASS_ENT(CallingConvention, NearVector), }; -static const EnumEntry FunctionOptionEnum[] = { +const EnumEntry FunctionOptionEnum[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, CxxReturnUdt), LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, Constructor), LLVM_READOBJ_ENUM_CLASS_ENT(FunctionOptions, ConstructorWithVirtualBases), }; -static const EnumEntry FileChecksumKindNames[] = { +const EnumEntry FileChecksumKindNames[] = { LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, None), LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, MD5), LLVM_READOBJ_ENUM_CLASS_ENT(FileChecksumKind, SHA1), @@ -781,7 +788,7 @@ }; template -static std::error_code getSymbolAuxData(const COFFObjectFile *Obj, +std::error_code getSymbolAuxData(const COFFObjectFile *Obj, COFFSymbolRef Symbol, uint8_t AuxSymbolIdx, const T *&Aux) { ArrayRef AuxData = Obj->getSymbolAuxData(Symbol); @@ -790,6 +797,8 @@ return readobj_error::success; } +} // end anonymous namespace + void COFFDumper::cacheRelocations() { if (RelocCached) return; @@ -940,11 +949,13 @@ } } +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 -static std::error_code consumeObject(StringRef &Data, const T *&Res) { +std::error_code consumeObject(StringRef &Data, const T *&Res) { if (Data.size() < sizeof(*Res)) return object_error::parse_failed; Res = reinterpret_cast(Data.data()); @@ -952,7 +963,7 @@ return std::error_code(); } -static std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { +std::error_code consumeUInt32(StringRef &Data, uint32_t &Res) { const ulittle32_t *IntPtr; if (auto EC = consumeObject(Data, IntPtr)) return EC; @@ -960,6 +971,8 @@ return std::error_code(); } +} // end anonymous namespace + void COFFDumper::initializeFileAndStringTables(StringRef Data) { while (!Data.empty() && (CVFileChecksumTable.data() == nullptr || CVStringTable.data() == nullptr)) { @@ -1182,7 +1195,9 @@ } } -static std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { +namespace { + +std::error_code decodeNumerictLeaf(StringRef &Data, APSInt &Num) { // Used to avoid overload ambiguity on APInt construtor. bool FalseVal = false; if (Data.size() < 2) @@ -1248,6 +1263,8 @@ 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; @@ -1313,11 +1330,10 @@ 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"); @@ -1337,11 +1353,10 @@ break; } - case S_END: { + case S_END: W.startLine() << "BlockEnd\n"; InFunctionScope = false; break; - } case S_LABEL32: { DictScope S(W, "Label"); @@ -1515,6 +1530,7 @@ printLocalVariableAddrGap(SymData); break; } + case S_DEFRANGE_SUBFIELD: { DictScope S(W, "DefRangeSubfield"); const DefRangeSubfieldSym *DefRangeSubfield; @@ -1529,6 +1545,7 @@ printLocalVariableAddrGap(SymData); break; } + case S_DEFRANGE_REGISTER: { DictScope S(W, "DefRangeRegister"); const DefRangeRegisterSym *DefRangeRegister; @@ -1540,6 +1557,7 @@ printLocalVariableAddrGap(SymData); break; } + case S_DEFRANGE_SUBFIELD_REGISTER: { DictScope S(W, "DefRangeSubfieldRegister"); const DefRangeSubfieldRegisterSym *DefRangeSubfieldRegisterSym; @@ -1554,6 +1572,7 @@ printLocalVariableAddrGap(SymData); break; } + case S_DEFRANGE_FRAMEPOINTER_REL: { DictScope S(W, "DefRangeFramePointerRel"); const DefRangeFramePointerRelSym *DefRangeFramePointerRel; @@ -1564,6 +1583,7 @@ printLocalVariableAddrGap(SymData); break; } + case S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE: { DictScope S(W, "DefRangeFramePointerRelFullScope"); const DefRangeFramePointerRelFullScopeSym @@ -1572,6 +1592,7 @@ W.printNumber("Offset", DefRangeFramePointerRelFullScope->Offset); break; } + case S_DEFRANGE_REGISTER_REL: { DictScope S(W, "DefRangeRegisterRel"); const DefRangeRegisterRelSym *DefRangeRegisterRel; @@ -1945,7 +1966,9 @@ W.printHex(Label, getFileNameForFileOffset(FileOffset), FileOffset); } -static StringRef getLeafTypeName(TypeLeafKind LT) { +namespace { + +StringRef getLeafTypeName(TypeLeafKind LT) { switch (LT) { case LF_STRING_ID: return "StringId"; case LF_FIELDLIST: return "FieldList"; @@ -1974,6 +1997,8 @@ return "UnknownLeaf"; } +} // end anonymous namespace + void COFFDumper::printCodeViewTypeSection(StringRef SectionName, const SectionRef &Section) { ListScope D(W, "CodeViewTypes"); @@ -2200,7 +2225,7 @@ break; } - case LF_METHODLIST: { + case LF_METHODLIST: while (!LeafData.empty()) { const MethodListEntry *Method; error(consumeObject(LeafData, Method)); @@ -2214,7 +2239,6 @@ } } break; - } case LF_FUNC_ID: { const FuncId *Func; @@ -2356,7 +2380,9 @@ } } -static StringRef skipPadding(StringRef Data) { +namespace { + +StringRef skipPadding(StringRef Data) { if (Data.empty()) return Data; uint8_t Leaf = Data.front(); @@ -2367,6 +2393,8 @@ return Data.drop_front(Leaf & 0x0F); } +} // end anonymous namespace + void COFFDumper::printMemberAttributes(MemberAttributes Attrs) { W.printEnum("AccessSpecifier", uint8_t(Attrs.getAccess()), makeArrayRef(MemberAccessNames)); @@ -2631,7 +2659,9 @@ void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); } -static ErrorOr +namespace { + +ErrorOr getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber, const coff_section *Section) { if (Section) { @@ -2649,6 +2679,8 @@ return StringRef(""); } +} // end anonymous namespace + void COFFDumper::printSymbol(const SymbolRef &Sym) { DictScope D(W, "Symbol"); @@ -2893,7 +2925,9 @@ } } -static StringRef getBaseRelocTypeName(uint8_t Type) { +namespace { + +StringRef getBaseRelocTypeName(uint8_t Type) { switch (Type) { case COFF::IMAGE_REL_BASED_ABSOLUTE: return "ABSOLUTE"; case COFF::IMAGE_REL_BASED_HIGH: return "HIGH"; @@ -2906,6 +2940,8 @@ } } +} // end anonymous namespace + void COFFDumper::printCOFFBaseReloc() { ListScope D(W, "BaseReloc"); for (const BaseRelocRef &I : Obj->base_relocs()) { Index: llvm/trunk/tools/sancov/sancov.cc =================================================================== --- llvm/trunk/tools/sancov/sancov.cc +++ llvm/trunk/tools/sancov/sancov.cc @@ -1,4 +1,4 @@ -//===-- sancov.cc --------------------------------------------===// +//===-- sancov.cc ---------------------------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -10,7 +10,13 @@ // 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" @@ -47,9 +53,13 @@ #include "llvm/Support/raw_ostream.h" #include +#include +#include +#include +#include #include -#include #include +#include #include #include @@ -83,28 +93,28 @@ "Print coverage statistics."), clEnumValEnd)); -static cl::list +cl::list ClInputFiles(cl::Positional, cl::OneOrMore, cl::desc("(|<.sancov file>)...")); -static cl::opt ClDemangle("demangle", cl::init(true), - cl::desc("Print demangled function name.")); +cl::opt ClDemangle("demangle", cl::init(true), + cl::desc("Print demangled function name.")); -static cl::opt ClStripPathPrefix( +cl::opt ClStripPathPrefix( "strip_path_prefix", cl::init(""), cl::desc("Strip this prefix from file paths in reports.")); -static cl::opt +cl::opt ClBlacklist("blacklist", cl::init(""), cl::desc("Blacklist file (sanitizer blacklist format).")); -static cl::opt ClUseDefaultBlacklist( +cl::opt ClUseDefaultBlacklist( "use_default_blacklist", cl::init(true), cl::Hidden, cl::desc("Controls if default blacklist should be used.")); -static const char *const DefaultBlacklistStr = "fun:__sanitizer_.*\n" - "src:/usr/include/.*\n" - "src:.*/libc\\+\\+/.*\n"; +const char *const DefaultBlacklistStr = "fun:__sanitizer_.*\n" + "src:/usr/include/.*\n" + "src:.*/libc\\+\\+/.*\n"; // --------- FORMAT SPECIFICATION --------- @@ -113,37 +123,37 @@ uint32_t Magic; }; -static const uint32_t BinCoverageMagic = 0xC0BFFFFF; -static const uint32_t Bitness32 = 0xFFFFFF32; -static const uint32_t Bitness64 = 0xFFFFFF64; +const uint32_t BinCoverageMagic = 0xC0BFFFFF; +const uint32_t Bitness32 = 0xFFFFFF32; +const uint32_t Bitness64 = 0xFFFFFF64; // --------- ERROR HANDLING --------- -static void Fail(const llvm::Twine &E) { +void Fail(const llvm::Twine &E) { errs() << "Error: " << E << "\n"; exit(1); } -static void FailIfError(std::error_code Error) { +void FailIfError(std::error_code Error) { if (!Error) return; errs() << "Error: " << Error.message() << "(" << Error.value() << ")\n"; exit(1); } -template static void FailIfError(const ErrorOr &E) { +template +void FailIfError(const ErrorOr &E) { FailIfError(E.getError()); } -static void FailIfNotEmpty(const llvm::Twine &E) { +void FailIfNotEmpty(const llvm::Twine &E) { if (E.str().empty()) return; Fail(E); } template -static void FailIfEmpty(const std::unique_ptr &Ptr, - const std::string &Message) { +void FailIfEmpty(const std::unique_ptr &Ptr, const std::string &Message) { if (Ptr.get()) return; Fail(Message); @@ -154,7 +164,7 @@ // Produces std::map> grouping input // elements by FuncTy result. template -static inline auto group_by(const RangeTy &R, FuncTy F) +inline auto group_by(const RangeTy &R, FuncTy F) -> std::map::type, std::vector::type>> { std::map::type, @@ -167,8 +177,7 @@ } template -static void readInts(const char *Start, const char *End, - std::set *Ints) { +void readInts(const char *Start, const char *End, std::set *Ints) { const T *S = reinterpret_cast(Start); const T *E = reinterpret_cast(End); std::copy(S, E, std::inserter(*Ints, Ints->end())); @@ -211,7 +220,7 @@ return Path.substr(Pos + ClStripPathPrefix.size()); } -static std::unique_ptr createSymbolizer() { +std::unique_ptr createSymbolizer() { symbolize::LLVMSymbolizer::Options SymbolizerOptions; SymbolizerOptions.Demangle = ClDemangle; SymbolizerOptions.UseSymbolTable = true; @@ -276,9 +285,9 @@ }; // Collect all debug info for given addresses. -static std::vector getAddrInfo(std::string ObjectFile, - const std::set &Addrs, - bool InlinedCode) { +std::vector getAddrInfo(std::string ObjectFile, + const std::set &Addrs, + bool InlinedCode) { std::vector Result; auto Symbolizer(createSymbolizer()); Blacklists B; @@ -306,7 +315,7 @@ // Locate __sanitizer_cov* function addresses that are used for coverage // reporting. -static std::set +std::set findSanitizerCovFunctions(const object::ObjectFile &O) { std::set Result; @@ -331,8 +340,8 @@ // Locate addresses of all coverage points in a file. Coverage point // is defined as the 'address of instruction following __sanitizer_cov // call - 1'. -static void getObjectCoveragePoints(const object::ObjectFile &O, - std::set *Addrs) { +void getObjectCoveragePoints(const object::ObjectFile &O, + std::set *Addrs) { Triple TheTriple("unknown-unknown-unknown"); TheTriple.setArch(Triple::ArchType(O.getArch())); auto TripleName = TheTriple.getTriple(); @@ -404,7 +413,7 @@ } } -static void +void visitObjectFiles(const object::Archive &A, std::function Fn) { for (auto &ErrorOrChild : A.children()) { @@ -419,7 +428,7 @@ } } -static void +void visitObjectFiles(std::string FileName, std::function Fn) { ErrorOr> BinaryOrErr = @@ -455,7 +464,7 @@ return Result; } -static void printCovPoints(std::string ObjFile, raw_ostream &OS) { +void printCovPoints(std::string ObjFile, raw_ostream &OS) { for (uint64_t Addr : getCoveragePoints(ObjFile)) { OS << "0x"; OS.write_hex(Addr); @@ -463,7 +472,7 @@ } } -static std::string escapeHtml(const std::string &S) { +std::string escapeHtml(const std::string &S) { std::string Result; Result.reserve(S.size()); for (char Ch : S) { @@ -493,7 +502,7 @@ // Adds leading zeroes wrapped in 'lz' style. // Leading zeroes help locate 000% coverage. -static std::string formatHtmlPct(size_t Pct) { +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); @@ -504,7 +513,7 @@ return Zeroes + Num; } -static std::string anchorName(std::string Anchor) { +std::string anchorName(std::string Anchor) { llvm::MD5 Hasher; llvm::MD5::MD5Result Hash; Hasher.update(Anchor); @@ -515,7 +524,7 @@ return HexString.str().str(); } -static ErrorOr isCoverageFile(std::string FileName) { +ErrorOr isCoverageFile(std::string FileName) { ErrorOr> BufOrErr = MemoryBuffer::getFile(FileName); if (!BufOrErr) { @@ -542,7 +551,7 @@ size_t CovFns; }; -static raw_ostream &operator<<(raw_ostream &OS, const CoverageStats &Stats) { +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"; @@ -822,8 +831,8 @@ std::vector CovAddrInfo; }; -static void printFunctionLocs(const SourceCoverageData::FunctionLocs &FnLocs, - raw_ostream &OS) { +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 << " " @@ -1182,7 +1191,7 @@ const std::set CoverageFiles; }; -} // namespace +} // end anonymous namespace int main(int argc, char **argv) { // Print stack trace if we signal out. Index: llvm/trunk/tools/sanstats/sanstats.cpp =================================================================== --- llvm/trunk/tools/sanstats/sanstats.cpp +++ llvm/trunk/tools/sanstats/sanstats.cpp @@ -12,20 +12,26 @@ // //===----------------------------------------------------------------------===// +#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 +#include +#include +#include +#include using namespace llvm; -static cl::opt ClInputFile(cl::Positional, cl::Required, - cl::desc("")); +namespace { -static cl::opt ClDemangle("demangle", cl::init(false), - cl::desc("Print demangled function name.")); +cl::opt ClInputFile(cl::Positional, cl::Required, + cl::desc("")); + +cl::opt 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); @@ -63,7 +69,7 @@ SymbolizerOptions.UseSymbolTable = true; symbolize::LLVMSymbolizer Symbolizer(SymbolizerOptions); - while (1) { + while (true) { uint64_t Addr = ReadLE(SizeofPtr, Begin, End); Begin += SizeofPtr; uint64_t Data = ReadLE(SizeofPtr, Begin, End); @@ -109,6 +115,8 @@ } } +} // end anonymous namespace + int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "Sanitizer Statistics Processing Tool"); Index: llvm/trunk/unittests/ADT/SCCIteratorTest.cpp =================================================================== --- llvm/trunk/unittests/ADT/SCCIteratorTest.cpp +++ llvm/trunk/unittests/ADT/SCCIteratorTest.cpp @@ -10,7 +10,10 @@ #include "llvm/ADT/SCCIterator.h" #include "llvm/ADT/GraphTraits.h" #include "gtest/gtest.h" -#include +#include +#include +#include +#include using namespace llvm; @@ -27,13 +30,14 @@ static void ValidateIndex(unsigned Idx) { assert(Idx < N && "Invalid node index!"); } -public: +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) { @@ -98,8 +102,8 @@ private: /// Nodes - The list of nodes for this graph. NodeType Nodes[N]; -public: +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 @@ -166,6 +170,7 @@ NodeSubset Children; ChildIterator(); // Disable default constructor. + protected: ChildIterator(NodeType *F, NodeSubset C) : FirstNode(F), Children(C) {} @@ -341,4 +346,4 @@ } } -} +} // end namespace llvm Index: llvm/trunk/unittests/ADT/SmallStringTest.cpp =================================================================== --- llvm/trunk/unittests/ADT/SmallStringTest.cpp +++ llvm/trunk/unittests/ADT/SmallStringTest.cpp @@ -12,10 +12,9 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "gtest/gtest.h" -#include -#include -#include using namespace llvm; @@ -204,4 +203,4 @@ EXPECT_EQ( 1, SmallString<10>("V8_q0").compare_numeric("V1_q0")); } -} +} // end anonymous namespace Index: llvm/trunk/unittests/ADT/SmallVectorTest.cpp =================================================================== --- llvm/trunk/unittests/ADT/SmallVectorTest.cpp +++ llvm/trunk/unittests/ADT/SmallVectorTest.cpp @@ -15,8 +15,10 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Compiler.h" #include "gtest/gtest.h" +#include +#include #include -#include +#include using namespace llvm; @@ -141,9 +143,10 @@ int Constructable::numMoveAssignmentCalls; struct NonCopyable { - NonCopyable() {} - NonCopyable(NonCopyable &&) {} + NonCopyable() = default; + NonCopyable(NonCopyable &&) = default; NonCopyable &operator=(NonCopyable &&) { return *this; } + private: NonCopyable(const NonCopyable &) = delete; NonCopyable &operator=(const NonCopyable &) = delete; @@ -200,7 +203,6 @@ VectorT otherVector; }; - typedef ::testing::Types, SmallVector, SmallVector, @@ -522,7 +524,6 @@ this->assertValuesInOrder(this->theVector, 6u, 1, 16, 16, 2, 3, 4); } - TYPED_TEST(SmallVectorTest, InsertRepeatedAtEndTest) { SCOPED_TRACE("InsertRepeatedTest"); @@ -581,7 +582,6 @@ this->assertValuesInOrder(this->theVector, 6u, 1, 77, 77, 77, 2, 3); } - TYPED_TEST(SmallVectorTest, InsertRangeAtEndTest) { SCOPED_TRACE("InsertRangeTest"); @@ -748,11 +748,14 @@ 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; @@ -775,6 +778,7 @@ EAS_RValue, EAS_Failure }; + template struct EmplaceableArg { EmplaceableArgState State; EmplaceableArg() : State(EAS_Defaulted) {} @@ -924,4 +928,4 @@ EXPECT_TRUE(makeArrayRef(V2).equals({4, 5, 3, 2})); } -} // end namespace +} // end anonymous namespace Index: llvm/trunk/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp =================================================================== --- llvm/trunk/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp +++ llvm/trunk/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 -#include -#include +#include +#include namespace llvm { @@ -157,4 +157,4 @@ LLVMOrcDisposeInstance(JIT); } -} // namespace llvm +} // end namespace llvm Index: llvm/trunk/unittests/Support/CommandLineTest.cpp =================================================================== --- llvm/trunk/unittests/Support/CommandLineTest.cpp +++ llvm/trunk/unittests/Support/CommandLineTest.cpp @@ -7,12 +7,17 @@ // //===----------------------------------------------------------------------===// +#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 +#include #include using namespace llvm; @@ -20,7 +25,7 @@ namespace { class TempEnvVar { - public: +public: TempEnvVar(const char *name, const char *value) : name(name) { const char *old_value = getenv(name); @@ -41,13 +46,14 @@ #endif } - private: +private: const char *const name; }; template class StackOption : public cl::opt { typedef cl::opt Base; + public: // One option... template @@ -69,7 +75,6 @@ ~StackOption() override { this->removeArgument(); } }; - cl::OptionCategory TestCategory("Test Options", "Description"); TEST(CommandLineTest, ModifyExisitingOption) { StackOption TestOption("test-option", cl::desc("old description")); @@ -265,4 +270,4 @@ << "Hid default option that should be visable."; } -} // anonymous namespace +} // end anonymous namespace Index: llvm/trunk/unittests/Support/ProgramTest.cpp =================================================================== --- llvm/trunk/unittests/Support/ProgramTest.cpp +++ llvm/trunk/unittests/Support/ProgramTest.cpp @@ -7,13 +7,19 @@ // //===----------------------------------------------------------------------===// +#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 +#include +#include +#include +#include #if defined(__APPLE__) # include #elif !defined(_MSC_VER) @@ -45,6 +51,7 @@ GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ } else { \ } + // From TestMain.cpp. extern const char *TestMainArgv0; @@ -53,9 +60,9 @@ using namespace llvm; using namespace sys; -static cl::opt +cl::opt ProgramTestStringArg1("program-test-string-arg1"); -static cl::opt +cl::opt ProgramTestStringArg2("program-test-string-arg2"); class ProgramEnvTest : public testing::Test { @@ -309,7 +316,6 @@ ASSERT_TRUE(ExecutionFailed); ASSERT_FALSE(Error.empty()); } - } #ifdef LLVM_ON_WIN32 Index: llvm/trunk/unittests/Support/StreamingMemoryObjectTest.cpp =================================================================== --- llvm/trunk/unittests/Support/StreamingMemoryObjectTest.cpp +++ llvm/trunk/unittests/Support/StreamingMemoryObjectTest.cpp @@ -11,7 +11,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/StreamingMemoryObject.h" #include "gtest/gtest.h" -#include +#include using namespace llvm; @@ -65,4 +65,4 @@ EXPECT_TRUE(std::equal(InputBuffer, InputBuffer + 8, O.getPointer(0, 20))); } -} // end namespace +} // end anonymous namespace Index: llvm/trunk/unittests/Support/TimeValueTest.cpp =================================================================== --- llvm/trunk/unittests/Support/TimeValueTest.cpp +++ llvm/trunk/unittests/Support/TimeValueTest.cpp @@ -9,9 +9,12 @@ #include "gtest/gtest.h" #include "llvm/Support/TimeValue.h" -#include +#include +#include +#include using namespace llvm; + namespace { TEST(TimeValue, time_t) { @@ -37,4 +40,4 @@ EXPECT_EQ(ft1970, epoch.toWin32Time()); } -} +} // end anonymous namespace Index: llvm/trunk/unittests/Support/TimerTest.cpp =================================================================== --- llvm/trunk/unittests/Support/TimerTest.cpp +++ llvm/trunk/unittests/Support/TimerTest.cpp @@ -13,7 +13,7 @@ #if LLVM_ON_WIN32 #include #else -#include +#include #endif using namespace llvm; @@ -62,4 +62,4 @@ EXPECT_FALSE(T1.hasTriggered()); } -} // end anon namespace +} // end anonymous namespace