diff --git a/llvm/lib/Support/Unix/COM.inc b/llvm/lib/Support/Unix/COM.inc --- a/llvm/lib/Support/Unix/COM.inc +++ b/llvm/lib/Support/Unix/COM.inc @@ -22,5 +22,5 @@ bool SpeedOverMemory) {} InitializeCOMRAII::~InitializeCOMRAII() = default; -} -} +} // namespace sys +} // namespace llvm diff --git a/llvm/lib/Support/Unix/DynamicLibrary.inc b/llvm/lib/Support/Unix/DynamicLibrary.inc --- a/llvm/lib/Support/Unix/DynamicLibrary.inc +++ b/llvm/lib/Support/Unix/DynamicLibrary.inc @@ -25,9 +25,10 @@ } void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) { - void *Handle = ::dlopen(File, RTLD_LAZY|RTLD_GLOBAL); + void *Handle = ::dlopen(File, RTLD_LAZY | RTLD_GLOBAL); if (!Handle) { - if (Err) *Err = ::dlerror(); + if (Err) + *Err = ::dlerror(); return &DynamicLibrary::Invalid; } @@ -41,9 +42,7 @@ return Handle; } -void DynamicLibrary::HandleSet::DLClose(void *Handle) { - ::dlclose(Handle); -} +void DynamicLibrary::HandleSet::DLClose(void *Handle) { ::dlclose(Handle); } void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) { return ::dlsym(Handle, Symbol); @@ -54,12 +53,12 @@ DynamicLibrary::HandleSet::~HandleSet() {} void *DynamicLibrary::HandleSet::DLOpen(const char *File, std::string *Err) { - if (Err) *Err = "dlopen() not supported on this platform"; + if (Err) + *Err = "dlopen() not supported on this platform"; return &Invalid; } -void DynamicLibrary::HandleSet::DLClose(void *Handle) { -} +void DynamicLibrary::HandleSet::DLClose(void *Handle) {} void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) { return nullptr; @@ -68,9 +67,11 @@ #endif // Must declare the symbols in the global namespace. -static void *DoSearch(const char* SymbolName) { -#define EXPLICIT_SYMBOL(SYM) \ - extern void *SYM; if (!strcmp(SymbolName, #SYM)) return (void*)&SYM +static void *DoSearch(const char *SymbolName) { +#define EXPLICIT_SYMBOL(SYM) \ + extern void *SYM; \ + if (!strcmp(SymbolName, #SYM)) \ + return (void *)&SYM // If this is darwin, it has some funky issues, try to solve them here. Some // important symbols are marked 'private external' which doesn't allow @@ -101,8 +102,9 @@ #undef EXPLICIT_SYMBOL // This macro returns the address of a well-known, explicit symbol -#define EXPLICIT_SYMBOL(SYM) \ - if (!strcmp(SymbolName, #SYM)) return &SYM +#define EXPLICIT_SYMBOL(SYM) \ + if (!strcmp(SymbolName, #SYM)) \ + return &SYM // Under glibc we have a weird situation. The stderr/out/in symbols are both // macros and global variables because of standards requirements. So, we diff --git a/llvm/lib/Support/Unix/Memory.inc b/llvm/lib/Support/Unix/Memory.inc --- a/llvm/lib/Support/Unix/Memory.inc +++ b/llvm/lib/Support/Unix/Memory.inc @@ -33,7 +33,7 @@ #if defined(__APPLE__) extern "C" void sys_icache_invalidate(const void *Addr, size_t len); #else -extern "C" void __clear_cache(void *, void*); +extern "C" void __clear_cache(void *, void *); #endif static int getPosixProtectionFlags(unsigned Flags) { @@ -42,9 +42,9 @@ return PROT_READ; case llvm::sys::Memory::MF_WRITE: return PROT_WRITE; - case llvm::sys::Memory::MF_READ|llvm::sys::Memory::MF_WRITE: + case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE: return PROT_READ | PROT_WRITE; - case llvm::sys::Memory::MF_READ|llvm::sys::Memory::MF_EXEC: + case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_EXEC: return PROT_READ | PROT_EXEC; case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE | llvm::sys::Memory::MF_EXEC: @@ -70,11 +70,9 @@ namespace llvm { namespace sys { -MemoryBlock -Memory::allocateMappedMemory(size_t NumBytes, - const MemoryBlock *const NearBlock, - unsigned PFlags, - std::error_code &EC) { +MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, + const MemoryBlock *const NearBlock, + unsigned PFlags, std::error_code &EC) { EC = std::error_code(); if (NumBytes == 0) return MemoryBlock(); @@ -105,18 +103,19 @@ // Use any near hint and the page size to set a page-aligned starting address uintptr_t Start = NearBlock ? reinterpret_cast(NearBlock->base()) + - NearBlock->allocatedSize() : 0; + NearBlock->allocatedSize() + : 0; static const size_t PageSize = Process::getPageSizeEstimate(); - const size_t NumPages = (NumBytes+PageSize-1)/PageSize; + const size_t NumPages = (NumBytes + PageSize - 1) / PageSize; if (Start && Start % PageSize) Start += PageSize - Start % PageSize; // FIXME: Handle huge page requests (MF_HUGE_HINT). - void *Addr = ::mmap(reinterpret_cast(Start), PageSize*NumPages, Protect, - MMFlags, fd, 0); + void *Addr = ::mmap(reinterpret_cast(Start), PageSize * NumPages, + Protect, MMFlags, fd, 0); if (Addr == MAP_FAILED) { - if (NearBlock) { //Try again without a near hint + if (NearBlock) { // Try again without a near hint #if !defined(MAP_ANON) close(fd); #endif @@ -136,12 +135,12 @@ MemoryBlock Result; Result.Address = Addr; - Result.AllocatedSize = PageSize*NumPages; + Result.AllocatedSize = PageSize * NumPages; Result.Flags = PFlags; // Rely on protectMappedMemory to invalidate instruction cache. if (PFlags & MF_EXEC) { - EC = Memory::protectMappedMemory (Result, PFlags); + EC = Memory::protectMappedMemory(Result, PFlags); if (EC != std::error_code()) return MemoryBlock(); } @@ -149,8 +148,7 @@ return Result; } -std::error_code -Memory::releaseMappedMemory(MemoryBlock &M) { +std::error_code Memory::releaseMappedMemory(MemoryBlock &M) { if (M.Address == nullptr || M.AllocatedSize == 0) return std::error_code(); @@ -163,8 +161,8 @@ return std::error_code(); } -std::error_code -Memory::protectMappedMemory(const MemoryBlock &M, unsigned Flags) { +std::error_code Memory::protectMappedMemory(const MemoryBlock &M, + unsigned Flags) { static const Align PageSize = Align(Process::getPageSizeEstimate()); if (M.Address == nullptr || M.AllocatedSize == 0) return std::error_code(); @@ -173,15 +171,18 @@ return std::error_code(EINVAL, std::generic_category()); int Protect = getPosixProtectionFlags(Flags); - uintptr_t Start = alignAddr((const uint8_t *)M.Address - PageSize.value() + 1, PageSize); - uintptr_t End = alignAddr((const uint8_t *)M.Address + M.AllocatedSize, PageSize); + uintptr_t Start = + alignAddr((const uint8_t *)M.Address - PageSize.value() + 1, PageSize); + uintptr_t End = + alignAddr((const uint8_t *)M.Address + M.AllocatedSize, PageSize); bool InvalidateCache = (Flags & MF_EXEC); #if defined(__arm__) || defined(__aarch64__) - // Certain ARM implementations treat icache clear instruction as a memory read, - // and CPU segfaults on trying to clear cache on !PROT_READ page. Therefore we need - // to temporarily add PROT_READ for the sake of flushing the instruction caches. + // Certain ARM implementations treat icache clear instruction as a memory + // read, and CPU segfaults on trying to clear cache on !PROT_READ page. + // Therefore we need to temporarily add PROT_READ for the sake of flushing the + // instruction caches. if (InvalidateCache && !(Protect & PROT_READ)) { int Result = ::mprotect((void *)Start, End - Start, Protect | PROT_READ); if (Result != 0) @@ -206,15 +207,14 @@ /// InvalidateInstructionCache - Before the JIT can run a block of code /// that has been emitted it must invalidate the instruction cache on some /// platforms. -void Memory::InvalidateInstructionCache(const void *Addr, - size_t Len) { +void Memory::InvalidateInstructionCache(const void *Addr, size_t Len) { // icache invalidation for PPC and ARM. #if defined(__APPLE__) -# if (defined(__powerpc__) || defined(__arm__) || defined(__arm64__)) +#if (defined(__powerpc__) || defined(__arm__) || defined(__arm64__)) sys_icache_invalidate(const_cast(Addr), Len); -# endif +#endif #elif defined(__Fuchsia__) @@ -223,12 +223,12 @@ #else -# if defined(__powerpc__) && defined(__GNUC__) +#if defined(__powerpc__) && defined(__GNUC__) const size_t LineSize = 32; const intptr_t Mask = ~(LineSize - 1); - const intptr_t StartLine = ((intptr_t) Addr) & Mask; - const intptr_t EndLine = ((intptr_t) Addr + Len + LineSize - 1) & Mask; + const intptr_t StartLine = ((intptr_t)Addr) & Mask; + const intptr_t EndLine = ((intptr_t)Addr + Len + LineSize - 1) & Mask; for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) asm volatile("dcbf 0, %0" : : "r"(Line)); @@ -237,15 +237,15 @@ for (intptr_t Line = StartLine; Line < EndLine; Line += LineSize) asm volatile("icbi 0, %0" : : "r"(Line)); asm volatile("isync"); -# elif (defined(__arm__) || defined(__aarch64__) || defined(__mips__)) && \ - defined(__GNUC__) +#elif (defined(__arm__) || defined(__aarch64__) || defined(__mips__)) && \ + defined(__GNUC__) // FIXME: Can we safely always call this for __GNUC__ everywhere? const char *Start = static_cast(Addr); const char *End = Start + Len; __clear_cache(const_cast(Start), const_cast(End)); -# endif +#endif -#endif // end apple +#endif // end apple ValgrindDiscardTranslations(Addr, Len); } diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -36,9 +36,9 @@ #include #ifdef __APPLE__ +#include #include #include -#include #if __has_include() #include #endif @@ -111,7 +111,7 @@ #define STATVFS_F_FRSIZE(vfs) static_cast(vfs.f_bsize) #endif -#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \ +#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \ defined(__MVS__) #define STATVFS_F_FLAG(vfs) (vfs).f_flag #else @@ -121,18 +121,16 @@ using namespace llvm; namespace llvm { -namespace sys { +namespace sys { namespace fs { const file_t kInvalidFile = -1; #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__minix) || defined(__FreeBSD_kernel__) || defined(__linux__) || \ - defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || defined(__GNU__) || \ - (defined(__sun__) && defined(__svr4__)) -static int -test_dir(char ret[PATH_MAX], const char *dir, const char *bin) -{ + defined(__CYGWIN__) || defined(__DragonFly__) || defined(_AIX) || \ + defined(__GNU__) || (defined(__sun__) && defined(__svr4__)) +static int test_dir(char ret[PATH_MAX], const char *dir, const char *bin) { struct stat sb; char fullpath[PATH_MAX]; @@ -149,9 +147,7 @@ return 0; } -static char * -getprogpath(char ret[PATH_MAX], const char *bin) -{ +static char *getprogpath(char ret[PATH_MAX], const char *bin) { if (bin == nullptr) return nullptr; @@ -319,7 +315,7 @@ char real_path[PATH_MAX]; if (realpath(exe_path, real_path)) return std::string(real_path); - break; // Found entry, but realpath failed. + break; // Found entry, but realpath failed. } #elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR) // Use dladdr to get executable path if available. @@ -351,9 +347,7 @@ return UniqueID(fs_st_dev, fs_st_ino); } -uint32_t file_status::getLinkCount() const { - return fs_st_nlinks; -} +uint32_t file_status::getLinkCount() const { return fs_st_nlinks; } ErrorOr disk_space(const Twine &Path) { struct STATVFS Vfs; @@ -513,7 +507,8 @@ // Haiku doesn't expose this information. return false; #elif defined(__sun) - // statvfs::f_basetype contains a null-terminated FSType name of the mounted target + // statvfs::f_basetype contains a null-terminated FSType name of the mounted + // target StringRef fstype(Vfs.f_basetype); // NFS is the only non-local fstype?? return !fstype.equals("nfs"); @@ -637,8 +632,7 @@ bool equivalent(file_status A, file_status B) { assert(status_known(A) && status_known(B)); - return A.fs_st_dev == B.fs_st_dev && - A.fs_st_ino == B.fs_st_ino; + return A.fs_st_dev == B.fs_st_dev && A.fs_st_ino == B.fs_st_ino; } std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { @@ -697,7 +691,6 @@ llvm::sys::path::append(Path, Storage); } - void expand_tilde(const Twine &path, SmallVectorImpl &dest) { dest.clear(); if (path.isTriviallyEmpty()) @@ -749,9 +742,9 @@ perms Perms = static_cast(Status.st_mode) & all_perms; Result = file_status(typeForMode(Status.st_mode), Perms, Status.st_dev, - Status.st_nlink, Status.st_ino, - Status.st_atime, atime_nsec, Status.st_mtime, mtime_nsec, - Status.st_uid, Status.st_gid, Status.st_size); + Status.st_nlink, Status.st_ino, Status.st_atime, + atime_nsec, Status.st_mtime, mtime_nsec, Status.st_uid, + Status.st_gid, Status.st_size); return std::error_code(); } @@ -775,7 +768,7 @@ // Chose arbitary new mask and reset the umask to the old mask. // umask(2) never fails so ignore the return of the second call. unsigned Mask = ::umask(0); - (void) ::umask(Mask); + (void)::umask(Mask); return Mask; } @@ -881,9 +874,9 @@ void mapped_file_region::dontNeedImpl() { assert(Mode == mapped_file_region::readonly); if (!Mapping) - return; + return; #if defined(__MVS__) || defined(_AIX) - // If we don't have madvise, or it isn't beneficial, treat this as a no-op. + // If we don't have madvise, or it isn't beneficial, treat this as a no-op. #elif defined(POSIX_MADV_DONTNEED) ::posix_madvise(Mapping, Size, POSIX_MADV_DONTNEED); #else @@ -891,9 +884,7 @@ #endif } -int mapped_file_region::alignment() { - return Process::getPageSizeEstimate(); -} +int mapped_file_region::alignment() { return Process::getPageSizeEstimate(); } std::error_code detail::directory_iterator_construct(detail::DirIterState &it, StringRef path, @@ -918,7 +909,7 @@ return std::error_code(); } -static file_type direntType(dirent* Entry) { +static file_type direntType(dirent *Entry) { // Most platforms provide the file type in the dirent: Linux/BSD/Mac. // The DTTOIF macro lets us reuse our status -> type conversion. // Note that while glibc provides a macro to see if this is supported, @@ -1140,7 +1131,7 @@ return EC; // Attempt to get the real name of the file, if the user asked - if(!RealPath) + if (!RealPath) return std::error_code(); RealPath->clear(); #if defined(F_GETPATH) @@ -1192,8 +1183,7 @@ #else size_t Size = Buf.size(); #endif - ssize_t NumRead = - sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size); + ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size); if (ssize_t(NumRead) == -1) return errorCodeToError(std::error_code(errno, std::generic_category())); return NumRead; @@ -1212,8 +1202,7 @@ #else if (lseek(FD, Offset, SEEK_SET) == -1) return errorCodeToError(std::error_code(errno, std::generic_category())); - ssize_t NumRead = - sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size); + ssize_t NumRead = sys::RetryAfterSignal(-1, ::read, FD, Buf.data(), Size); #endif if (NumRead == -1) return errorCodeToError(std::error_code(errno, std::generic_category())); @@ -1367,11 +1356,10 @@ } static bool getDarwinConfDir(bool TempDir, SmallVectorImpl &Result) { - #if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR) +#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 - int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR - : _CS_DARWIN_USER_CACHE_DIR; + int ConfName = TempDir ? _CS_DARWIN_USER_TEMP_DIR : _CS_DARWIN_USER_CACHE_DIR; size_t ConfLen = confstr(ConfName, nullptr, 0); if (ConfLen > 0) { do { @@ -1387,7 +1375,7 @@ Result.clear(); } - #endif +#endif return false; } @@ -1417,7 +1405,7 @@ bool cache_directory(SmallVectorImpl &result) { #ifdef __APPLE__ - if (getDarwinConfDir(false/*tempDir*/, result)) { + if (getDarwinConfDir(false /*tempDir*/, result)) { return true; } #else @@ -1503,13 +1491,13 @@ auto Errno = errno; switch (Errno) { - case EEXIST: // To already exists. - case ENOTSUP: // Device does not support cloning. - case EXDEV: // From and To are on different devices. - break; - default: - // Anything else will also break copyfile(). - return std::error_code(Errno, std::generic_category()); + case EEXIST: // To already exists. + case ENOTSUP: // Device does not support cloning. + case EXDEV: // From and To are on different devices. + break; + default: + // Anything else will also break copyfile(). + return std::error_code(Errno, std::generic_category()); } // TODO: For EEXIST, profile calling fs::generateUniqueName() and diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc --- a/llvm/lib/Support/Unix/Process.inc +++ b/llvm/lib/Support/Unix/Process.inc @@ -40,10 +40,10 @@ #include #endif #ifdef HAVE_SYS_IOCTL_H -# include +#include #endif #ifdef HAVE_TERMIOS_H -# include +#include #endif //===----------------------------------------------------------------------===// @@ -54,14 +54,15 @@ using namespace llvm; using namespace sys; -static std::pair getRUsageTimes() { +static std::pair +getRUsageTimes() { #if defined(HAVE_GETRUSAGE) struct rusage RU; ::getrusage(RUSAGE_SELF, &RU); - return { toDuration(RU.ru_utime), toDuration(RU.ru_stime) }; + return {toDuration(RU.ru_utime), toDuration(RU.ru_stime)}; #else #warning Cannot get usage times on this platform - return { std::chrono::microseconds::zero(), std::chrono::microseconds::zero() }; + return {std::chrono::microseconds::zero(), std::chrono::microseconds::zero()}; #endif } @@ -99,7 +100,7 @@ #elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H) malloc_statistics_t Stats; malloc_zone_statistics(malloc_default_zone(), &Stats); - return Stats.size_in_use; // darwin + return Stats.size_in_use; // darwin #elif defined(HAVE_MALLCTL) size_t alloc, sz; sz = sizeof(size_t); @@ -109,9 +110,9 @@ #elif defined(HAVE_SBRK) // Note this is only an approximation and more closely resembles // the value returned by mallinfo in the arena field. - static char *StartOfMemory = reinterpret_cast(::sbrk(0)); - char *EndOfMemory = (char*)sbrk(0); - if (EndOfMemory != ((char*)-1) && StartOfMemory != ((char*)-1)) + static char *StartOfMemory = reinterpret_cast(::sbrk(0)); + char *EndOfMemory = (char *)sbrk(0); + if (EndOfMemory != ((char *)-1) && StartOfMemory != ((char *)-1)) return EndOfMemory - StartOfMemory; return 0; #else @@ -120,7 +121,8 @@ #endif } -void Process::GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, +void Process::GetTimeUsage(TimePoint<> &elapsed, + std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time) { elapsed = std::chrono::system_clock::now(); std::tie(user_time, sys_time) = getRUsageTimes(); @@ -149,10 +151,9 @@ exception_port_t OriginalPorts[EXC_TYPES_COUNT]; exception_behavior_t OriginalBehaviors[EXC_TYPES_COUNT]; thread_state_flavor_t OriginalFlavors[EXC_TYPES_COUNT]; - kern_return_t err = - task_get_exception_ports(mach_task_self(), EXC_MASK_ALL, OriginalMasks, - &Count, OriginalPorts, OriginalBehaviors, - OriginalFlavors); + kern_return_t err = task_get_exception_ports( + mach_task_self(), EXC_MASK_ALL, OriginalMasks, &Count, OriginalPorts, + OriginalBehaviors, OriginalFlavors); if (err == KERN_SUCCESS) { // replace each with MACH_PORT_NULL. for (unsigned i = 0; i != Count; ++i) @@ -163,10 +164,10 @@ // Disable crash reporting on Mac OS X 10.5 signal(SIGABRT, _exit); - signal(SIGILL, _exit); - signal(SIGFPE, _exit); + signal(SIGILL, _exit); + signal(SIGFPE, _exit); signal(SIGSEGV, _exit); - signal(SIGBUS, _exit); + signal(SIGBUS, _exit); #endif coreFilesPrevented = true; @@ -197,7 +198,7 @@ int &FD; bool KeepOpen; }; -} +} // namespace std::error_code Process::FixupStandardFileDescriptors() { int NullFD = -1; @@ -239,7 +240,7 @@ if (sigfillset(&FullSet) < 0 || sigfillset(&SavedSet) < 0) return std::error_code(errno, std::generic_category()); - // Atomically swap our current signal mask with a full mask. + // Atomically swap our current signal mask with a full mask. #if LLVM_ENABLE_THREADS if (int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet)) return std::error_code(EC, std::generic_category()); @@ -329,15 +330,15 @@ bool checkTerminalEnvironmentForColors() { if (const char *TermStr = std::getenv("TERM")) { return StringSwitch(TermStr) - .Case("ansi", true) - .Case("cygwin", true) - .Case("linux", true) - .StartsWith("screen", true) - .StartsWith("xterm", true) - .StartsWith("vt100", true) - .StartsWith("rxvt", true) - .EndsWith("color", true) - .Default(false); + .Case("ansi", true) + .Case("cygwin", true) + .Case("linux", true) + .StartsWith("screen", true) + .StartsWith("xterm", true) + .StartsWith("vt100", true) + .StartsWith("rxvt", true) + .EndsWith("color", true) + .Default(false); } return false; @@ -370,7 +371,8 @@ // The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if // the terminfo says that no colors are supported. int colors_ti = tigetnum(const_cast("colors")); - bool HasColors = colors_ti >= 0 ? colors_ti : checkTerminalEnvironmentForColors(); + bool HasColors = + colors_ti >= 0 ? colors_ti : checkTerminalEnvironmentForColors(); // Now extract the structure allocated by setupterm and free its memory // through a really silly dance. @@ -410,20 +412,14 @@ } const char *Process::OutputColor(char code, bool bold, bool bg) { - return colorcodes[bg?1:0][bold?1:0][code&7]; + return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7]; } -const char *Process::OutputBold(bool bg) { - return "\033[1m"; -} +const char *Process::OutputBold(bool bg) { return "\033[1m"; } -const char *Process::OutputReverse() { - return "\033[7m"; -} +const char *Process::OutputReverse() { return "\033[7m"; } -const char *Process::ResetColor() { - return "\033[0m"; -} +const char *Process::ResetColor() { return "\033[0m"; } #if !HAVE_DECL_ARC4RANDOM static unsigned GetRandomNumberSeed() { diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -1,4 +1,5 @@ -//===- llvm/Support/Unix/Program.cpp -----------------------------*- C++ -*-===// +//===- llvm/Support/Unix/Program.cpp -----------------------------*- C++ +//-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -55,7 +56,7 @@ #endif #if !USE_NSGETENVIRON - extern char **environ; +extern char **environ; #else #include // _NSGetEnviron #endif @@ -89,12 +90,12 @@ SmallString<128> FilePath(Path); sys::path::append(FilePath, Name); if (sys::fs::can_execute(FilePath.c_str())) - return std::string(FilePath.str()); // Found the executable! + return std::string(FilePath.str()); // Found the executable! } return errc::no_such_file_or_directory; } -static bool RedirectIO(Optional Path, int FD, std::string* ErrMsg) { +static bool RedirectIO(Optional Path, int FD, std::string *ErrMsg) { if (!Path) // Noop return false; std::string File; @@ -105,10 +106,10 @@ File = std::string(*Path); // Open the file - int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666); + int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666); if (InFD == -1) { - MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for " - + (FD == 0 ? "input" : "output")); + MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for " + + (FD == 0 ? "input" : "output")); return true; } @@ -118,7 +119,7 @@ close(InFD); return true; } - close(InFD); // Close the original FD + close(InFD); // Close the original FD return false; } @@ -135,30 +136,28 @@ File = Path->c_str(); if (int Err = posix_spawn_file_actions_addopen( - FileActions, FD, File, - FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666)) + FileActions, FD, File, FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666)) return MakeErrMsg(ErrMsg, "Cannot posix_spawn_file_actions_addopen", Err); return false; } #endif -static void TimeOutHandler(int Sig) { -} +static void TimeOutHandler(int Sig) {} static void SetMemoryLimits(unsigned size) { #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT struct rlimit r; - __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur)) (size) * 1048576; + __typeof__(r.rlim_cur) limit = (__typeof__(r.rlim_cur))(size)*1048576; // Heap size - getrlimit (RLIMIT_DATA, &r); + getrlimit(RLIMIT_DATA, &r); r.rlim_cur = limit; - setrlimit (RLIMIT_DATA, &r); + setrlimit(RLIMIT_DATA, &r); #ifdef RLIMIT_RSS // Resident set size. - getrlimit (RLIMIT_RSS, &r); + getrlimit(RLIMIT_RSS, &r); r.rlim_cur = limit; - setrlimit (RLIMIT_RSS, &r); + setrlimit(RLIMIT_RSS, &r); #endif #endif } @@ -263,7 +262,7 @@ posix_spawn_file_actions_destroy(FileActions); if (Err) - return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err); + return !MakeErrMsg(ErrMsg, "posix_spawn failed", Err); PI.Pid = PID; PI.Process = PID; @@ -275,56 +274,62 @@ // Create a child process. int child = fork(); switch (child) { - // An error occurred: Return to the caller. - case -1: - MakeErrMsg(ErrMsg, "Couldn't fork"); - return false; + // An error occurred: Return to the caller. + case -1: + MakeErrMsg(ErrMsg, "Couldn't fork"); + return false; - // Child process: Execute the program. - case 0: { - // Redirect file descriptors... - if (!Redirects.empty()) { - // Redirect stdin - if (RedirectIO(Redirects[0], 0, ErrMsg)) { return false; } - // Redirect stdout - if (RedirectIO(Redirects[1], 1, ErrMsg)) { return false; } - if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) { - // If stdout and stderr should go to the same place, redirect stderr - // to the FD already open for stdout. - if (-1 == dup2(1,2)) { - MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout"); - return false; - } - } else { - // Just redirect stderr - if (RedirectIO(Redirects[2], 2, ErrMsg)) { return false; } - } + // Child process: Execute the program. + case 0: { + // Redirect file descriptors... + if (!Redirects.empty()) { + // Redirect stdin + if (RedirectIO(Redirects[0], 0, ErrMsg)) { + return false; } - - // Set memory limits - if (MemoryLimit!=0) { - SetMemoryLimits(MemoryLimit); + // Redirect stdout + if (RedirectIO(Redirects[1], 1, ErrMsg)) { + return false; + } + if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) { + // If stdout and stderr should go to the same place, redirect stderr + // to the FD already open for stdout. + if (-1 == dup2(1, 2)) { + MakeErrMsg(ErrMsg, "Can't redirect stderr to stdout"); + return false; + } + } else { + // Just redirect stderr + if (RedirectIO(Redirects[2], 2, ErrMsg)) { + return false; + } } + } - // Execute! - std::string PathStr = std::string(Program); - if (Envp != nullptr) - execve(PathStr.c_str(), const_cast(Argv), - const_cast(Envp)); - else - execv(PathStr.c_str(), const_cast(Argv)); - // If the execve() failed, we should exit. Follow Unix protocol and - // return 127 if the executable was not found, and 126 otherwise. - // Use _exit rather than exit so that atexit functions and static - // object destructors cloned from the parent process aren't - // redundantly run, and so that any data buffered in stdio buffers - // cloned from the parent aren't redundantly written out. - _exit(errno == ENOENT ? 127 : 126); + // Set memory limits + if (MemoryLimit != 0) { + SetMemoryLimits(MemoryLimit); } - // Parent process: Break out of the switch to do our processing. - default: - break; + // Execute! + std::string PathStr = std::string(Program); + if (Envp != nullptr) + execve(PathStr.c_str(), const_cast(Argv), + const_cast(Envp)); + else + execv(PathStr.c_str(), const_cast(Argv)); + // If the execve() failed, we should exit. Follow Unix protocol and + // return 127 if the executable was not found, and 126 otherwise. + // Use _exit rather than exit so that atexit functions and static + // object destructors cloned from the parent process aren't + // redundantly run, and so that any data buffered in stdio buffers + // cloned from the parent aren't redundantly written out. + _exit(errno == ENOENT ? 127 : 126); + } + + // Parent process: Break out of the switch to do our processing. + default: + break; } PI.Pid = child; @@ -339,7 +344,7 @@ #ifndef _AIX using ::wait4; #else -static pid_t (wait4)(pid_t pid, int *status, int options, struct rusage *usage); +static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage); #endif } // namespace sys @@ -347,11 +352,11 @@ #ifdef _AIX #ifndef _ALL_SOURCE -extern "C" pid_t (wait4)(pid_t pid, int *status, int options, - struct rusage *usage); +extern "C" pid_t(wait4)(pid_t pid, int *status, int options, + struct rusage *usage); #endif -pid_t (llvm::sys::wait4)(pid_t pid, int *status, int options, - struct rusage *usage) { +pid_t(llvm::sys::wait4)(pid_t pid, int *status, int options, + struct rusage *usage) { assert(pid > 0 && "Only expecting to handle actual PID values!"); assert((options & ~WNOHANG) == 0 && "Expecting WNOHANG at most!"); assert(usage && "Expecting usage collection!"); @@ -494,13 +499,13 @@ return WaitResult; } -std::error_code llvm::sys::ChangeStdinMode(fs::OpenFlags Flags){ +std::error_code llvm::sys::ChangeStdinMode(fs::OpenFlags Flags) { if (!(Flags & fs::OF_Text)) return ChangeStdinToBinary(); return std::error_code(); } -std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags){ +std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags) { if (!(Flags & fs::OF_Text)) return ChangeStdoutToBinary(); return std::error_code(); @@ -520,7 +525,8 @@ llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents, WindowsEncodingMethod Encoding /*unused*/) { std::error_code EC; - llvm::raw_fd_ostream OS(FileName, EC, llvm::sys::fs::OpenFlags::OF_TextWithCRLF); + llvm::raw_fd_ostream OS(FileName, EC, + llvm::sys::fs::OpenFlags::OF_TextWithCRLF); if (EC) return EC; diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -48,7 +48,7 @@ #include #include #ifdef HAVE_BACKTRACE -# include BACKTRACE_HEADER // For backtrace(). +#include BACKTRACE_HEADER // For backtrace(). #endif #if HAVE_SIGNAL_H #include @@ -79,8 +79,8 @@ using namespace llvm; -static void SignalHandler(int Sig); // defined below. -static void InfoSignalHandler(int Sig); // defined below. +static void SignalHandler(int Sig); // defined below. +static void InfoSignalHandler(int Sig); // defined below. using SignalHandlerFunctionType = void (*)(); /// The function to call if ctrl-c is pressed. @@ -208,40 +208,45 @@ /// 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[] = { - SIGHUP, SIGINT, SIGTERM, SIGUSR2 -}; +static const int IntSigs[] = {SIGHUP, SIGINT, SIGTERM, SIGUSR2}; /// Signals that represent that we have a bug, and our prompt termination has /// been ordered. -static const int KillSigs[] = { - SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT +static const int KillSigs[] = {SIGILL, + SIGTRAP, + SIGABRT, + SIGFPE, + SIGBUS, + SIGSEGV, + SIGQUIT #ifdef SIGSYS - , SIGSYS + , + SIGSYS #endif #ifdef SIGXCPU - , SIGXCPU + , + SIGXCPU #endif #ifdef SIGXFSZ - , SIGXFSZ + , + SIGXFSZ #endif #ifdef SIGEMT - , SIGEMT + , + SIGEMT #endif }; /// Signals that represent requests for status. -static const int InfoSigs[] = { - SIGUSR1 +static const int InfoSigs[] = {SIGUSR1 #ifdef SIGINFO - , SIGINFO + , + SIGINFO #endif }; -static const size_t NumSigs = - std::size(IntSigs) + std::size(KillSigs) + - std::size(InfoSigs) + 1 /* SIGPIPE */; - +static const size_t NumSigs = std::size(IntSigs) + std::size(KillSigs) + + std::size(InfoSigs) + 1 /* SIGPIPE */; static std::atomic NumRegisteredSignals = ATOMIC_VAR_INIT(0); static struct { @@ -334,8 +339,8 @@ void sys::unregisterHandlers() { // Restore all of the signal handlers to how they were before we showed up. for (unsigned i = 0, e = NumRegisteredSignals.load(); i != e; ++i) { - sigaction(RegisteredSignalInfo[i].SigNo, - &RegisteredSignalInfo[i].SA, nullptr); + sigaction(RegisteredSignalInfo[i].SigNo, &RegisteredSignalInfo[i].SA, + nullptr); --NumRegisteredSignals; } } @@ -412,9 +417,7 @@ CurrentInfoFunction(); } -void llvm::sys::RunInterruptHandlers() { - RemoveFilesToRemove(); -} +void llvm::sys::RunInterruptHandlers() { RemoveFilesToRemove(); } void llvm::sys::SetInterruptFunction(void (*IF)()) { InterruptFunction.exchange(IF); @@ -437,8 +440,7 @@ } // The public API -bool llvm::sys::RemoveFileOnSignal(StringRef Filename, - std::string* ErrMsg) { +bool llvm::sys::RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg) { // Ensure that cleanup will occur as soon as one file is added. static ManagedStatic FilesToRemoveCleanup; *FilesToRemoveCleanup; @@ -461,7 +463,7 @@ RegisterHandlers(); } -#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && HAVE_LINK_H && \ +#if defined(HAVE_BACKTRACE) && ENABLE_BACKTRACES && HAVE_LINK_H && \ (defined(__linux__) || defined(__FreeBSD__) || \ defined(__FreeBSD_kernel__) || defined(__NetBSD__)) struct DlIteratePhdrData { @@ -474,7 +476,7 @@ }; static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { - DlIteratePhdrData *data = (DlIteratePhdrData*)arg; + DlIteratePhdrData *data = (DlIteratePhdrData *)arg; const char *name = data->first ? data->main_exec_name : info->dlpi_name; data->first = false; for (int i = 0; i < info->dlpi_phnum; i++) { @@ -567,8 +569,8 @@ #if defined(HAVE__UNWIND_BACKTRACE) // Try _Unwind_Backtrace() if backtrace() failed. if (!depth) - depth = unwindBacktrace(StackTrace, - static_cast(std::size(StackTrace))); + depth = + unwindBacktrace(StackTrace, static_cast(std::size(StackTrace))); #endif if (!depth) return; @@ -586,13 +588,16 @@ for (int i = 0; i < depth; ++i) { Dl_info dlinfo; dladdr(StackTrace[i], &dlinfo); - const char* name = strrchr(dlinfo.dli_fname, '/'); + const char *name = strrchr(dlinfo.dli_fname, '/'); int nwidth; - if (!name) nwidth = strlen(dlinfo.dli_fname); - else nwidth = strlen(name) - 1; + if (!name) + nwidth = strlen(dlinfo.dli_fname); + else + nwidth = strlen(name) - 1; - if (nwidth > width) width = nwidth; + if (nwidth > width) + width = nwidth; } for (int i = 0; i < depth; ++i) { @@ -601,23 +606,27 @@ OS << format("%-2d", i); - const char* name = strrchr(dlinfo.dli_fname, '/'); - if (!name) OS << format(" %-*s", width, dlinfo.dli_fname); - else OS << format(" %-*s", width, name+1); + const char *name = strrchr(dlinfo.dli_fname, '/'); + if (!name) + OS << format(" %-*s", width, dlinfo.dli_fname); + else + OS << format(" %-*s", width, name + 1); - OS << format(" %#0*lx", (int)(sizeof(void*) * 2) + 2, + OS << format(" %#0*lx", (int)(sizeof(void *) * 2) + 2, (unsigned long)StackTrace[i]); if (dlinfo.dli_sname != nullptr) { OS << ' '; int res; - char* d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res); - if (!d) OS << dlinfo.dli_sname; - else OS << d; + char *d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res); + if (!d) + OS << dlinfo.dli_sname; + else + OS << d; free(d); - OS << format(" + %tu", (static_cast(StackTrace[i])- - static_cast(dlinfo.dli_saddr))); + OS << format(" + %tu", (static_cast(StackTrace[i]) - + static_cast(dlinfo.dli_saddr))); } OS << '\n'; } @@ -648,11 +657,9 @@ exception_mask_t mask = EXC_MASK_CRASH; - kern_return_t ret = task_set_exception_ports(self, - mask, - MACH_PORT_NULL, - EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, - THREAD_STATE_NONE); + kern_return_t ret = task_set_exception_ports( + self, mask, MACH_PORT_NULL, + EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, THREAD_STATE_NONE); (void)ret; } #endif diff --git a/llvm/lib/Support/Unix/ThreadLocal.inc b/llvm/lib/Support/Unix/ThreadLocal.inc --- a/llvm/lib/Support/Unix/ThreadLocal.inc +++ b/llvm/lib/Support/Unix/ThreadLocal.inc @@ -1,4 +1,5 @@ -//=== llvm/Support/Unix/ThreadLocal.inc - Unix Thread Local Data -*- C++ -*-===// +//=== llvm/Support/Unix/ThreadLocal.inc - Unix Thread Local Data -*- C++ +//-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -26,33 +27,31 @@ ThreadLocalImpl::ThreadLocalImpl() : data() { static_assert(sizeof(pthread_key_t) <= sizeof(data), "size too big"); - pthread_key_t* key = reinterpret_cast(&data); + pthread_key_t *key = reinterpret_cast(&data); int errorcode = pthread_key_create(key, nullptr); assert(errorcode == 0); - (void) errorcode; + (void)errorcode; } ThreadLocalImpl::~ThreadLocalImpl() { - pthread_key_t* key = reinterpret_cast(&data); + pthread_key_t *key = reinterpret_cast(&data); int errorcode = pthread_key_delete(*key); assert(errorcode == 0); - (void) errorcode; + (void)errorcode; } -void ThreadLocalImpl::setInstance(const void* d) { - pthread_key_t* key = reinterpret_cast(&data); +void ThreadLocalImpl::setInstance(const void *d) { + pthread_key_t *key = reinterpret_cast(&data); int errorcode = pthread_setspecific(*key, d); assert(errorcode == 0); - (void) errorcode; + (void)errorcode; } void *ThreadLocalImpl::getInstance() { - pthread_key_t* key = reinterpret_cast(&data); + pthread_key_t *key = reinterpret_cast(&data); return pthread_getspecific(*key); } -void ThreadLocalImpl::removeInstance() { - setInstance(nullptr); -} +void ThreadLocalImpl::removeInstance() { setInstance(nullptr); } -} +} // namespace llvm diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc --- a/llvm/lib/Support/Unix/Threading.inc +++ b/llvm/lib/Support/Unix/Threading.inc @@ -98,13 +98,9 @@ } } -pthread_t llvm_thread_get_id_impl(pthread_t Thread) { - return Thread; -} +pthread_t llvm_thread_get_id_impl(pthread_t Thread) { return Thread; } -pthread_t llvm_thread_get_current_id_impl() { - return ::pthread_self(); -} +pthread_t llvm_thread_get_current_id_impl() { return ::pthread_self(); } } // namespace llvm @@ -131,7 +127,6 @@ #endif } - static constexpr uint32_t get_max_thread_name_length_impl() { #if defined(__NetBSD__) return PTHREAD_MAX_NAMELEN_NP; @@ -180,7 +175,7 @@ ::pthread_set_name_np(::pthread_self(), NameStr.data()); #elif defined(__NetBSD__) ::pthread_setname_np(::pthread_self(), "%s", - const_cast(NameStr.data())); + const_cast(NameStr.data())); #elif defined(__APPLE__) ::pthread_setname_np(NameStr.data()); #endif @@ -196,8 +191,8 @@ struct kinfo_proc *kp = nullptr, *nkp; size_t len = 0; int error; - int ctl[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, - (int)pid }; + int ctl[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, + (int)pid}; while (1) { error = sysctl(ctl, 4, kp, &len, nullptr, 0); @@ -240,7 +235,7 @@ #elif defined(__linux__) #if HAVE_PTHREAD_GETNAME_NP constexpr uint32_t len = get_max_thread_name_length_impl(); - char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive. + char Buffer[len] = {'\0'}; // FIXME: working around MSan false positive. if (0 == ::pthread_getname_np(::pthread_self(), Buffer, len)) Name.append(Buffer, Buffer + strlen(Buffer)); #endif @@ -267,18 +262,22 @@ #elif defined(__APPLE__) // https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon // - // Background - Applies to work that isn’t visible to the user and may take significant - // time to complete. Examples include indexing, backing up, or synchronizing data. This - // class emphasizes energy efficiency. + // Background - Applies to work that isn’t visible to the user and may take + // significant time to complete. Examples include indexing, backing up, or + // synchronizing data. This class emphasizes energy efficiency. // - // Utility - Applies to work that takes anywhere from a few seconds to a few minutes to - // complete. Examples include downloading a document or importing data. This class - // offers a balance between responsiveness, performance, and energy efficiency. - const auto qosClass = [&](){ + // Utility - Applies to work that takes anywhere from a few seconds to a few + // minutes to complete. Examples include downloading a document or importing + // data. This class offers a balance between responsiveness, performance, and + // energy efficiency. + const auto qosClass = [&]() { switch (Priority) { - case ThreadPriority::Background: return QOS_CLASS_BACKGROUND; - case ThreadPriority::Low: return QOS_CLASS_UTILITY; - case ThreadPriority::Default: return QOS_CLASS_DEFAULT; + case ThreadPriority::Background: + return QOS_CLASS_BACKGROUND; + case ThreadPriority::Low: + return QOS_CLASS_UTILITY; + case ThreadPriority::Default: + return QOS_CLASS_DEFAULT; } }(); return !pthread_set_qos_class_self_np(qosClass, 0) diff --git a/llvm/lib/Support/Unix/Watchdog.inc b/llvm/lib/Support/Unix/Watchdog.inc --- a/llvm/lib/Support/Unix/Watchdog.inc +++ b/llvm/lib/Support/Unix/Watchdog.inc @@ -17,17 +17,17 @@ #endif namespace llvm { - namespace sys { - Watchdog::Watchdog(unsigned int seconds) { +namespace sys { +Watchdog::Watchdog(unsigned int seconds) { #ifdef HAVE_UNISTD_H - alarm(seconds); + alarm(seconds); #endif - } +} - Watchdog::~Watchdog() { +Watchdog::~Watchdog() { #ifdef HAVE_UNISTD_H - alarm(0); + alarm(0); #endif - } - } } +} // namespace sys +} // namespace llvm diff --git a/llvm/lib/Support/Windows/COM.inc b/llvm/lib/Support/Windows/COM.inc --- a/llvm/lib/Support/Windows/COM.inc +++ b/llvm/lib/Support/Windows/COM.inc @@ -32,5 +32,5 @@ } InitializeCOMRAII::~InitializeCOMRAII() { ::CoUninitialize(); } -} -} +} // namespace sys +} // namespace llvm diff --git a/llvm/lib/Support/Windows/DynamicLibrary.inc b/llvm/lib/Support/Windows/DynamicLibrary.inc --- a/llvm/lib/Support/Windows/DynamicLibrary.inc +++ b/llvm/lib/Support/Windows/DynamicLibrary.inc @@ -10,8 +10,8 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Windows/WindowsSupport.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Windows/WindowsSupport.h" #include "llvm/Support/raw_ostream.h" #include @@ -21,13 +21,12 @@ //=== and must not be UNIX code. //===----------------------------------------------------------------------===// - DynamicLibrary::HandleSet::~HandleSet() { for (void *Handle : llvm::reverse(Handles)) FreeLibrary(HMODULE(Handle)); // 'Process' should not be released on Windows. - assert((!Process || Process==this) && "Bad Handle"); + assert((!Process || Process == this) && "Bad Handle"); // llvm_shutdown called, Return to default DynamicLibrary::SearchOrder = DynamicLibrary::SO_Linker; } @@ -51,7 +50,7 @@ return &DynamicLibrary::Invalid; } - return reinterpret_cast(Handle); + return reinterpret_cast(Handle); } static DynamicLibrary::HandleSet *IsOpenedHandlesInstance(void *Handle) { @@ -60,7 +59,7 @@ } void DynamicLibrary::HandleSet::DLClose(void *Handle) { - if (HandleSet* HS = IsOpenedHandlesInstance(Handle)) + if (HandleSet *HS = IsOpenedHandlesInstance(Handle)) HS->Process = nullptr; // Just drop the *Process* handle. else FreeLibrary((HMODULE)Handle); @@ -75,7 +74,7 @@ #else !EnumProcessModules(H, Data, Bytes, &Bytes) #endif - ) { + ) { std::string Err; if (MakeErrMsg(&Err, "EnumProcessModules failure")) llvm::errs() << Err << "\n"; @@ -85,7 +84,7 @@ } void *DynamicLibrary::HandleSet::DLSym(void *Handle, const char *Symbol) { - HandleSet* HS = IsOpenedHandlesInstance(Handle); + HandleSet *HS = IsOpenedHandlesInstance(Handle); if (!HS) return (void *)uintptr_t(GetProcAddress((HMODULE)Handle, Symbol)); @@ -128,7 +127,7 @@ // Try EXE first, mirroring what dlsym(dlopen(NULL)) does. if (FARPROC Ptr = GetProcAddress(HMODULE(Handles.front()), Symbol)) - return (void *) uintptr_t(Ptr); + return (void *)uintptr_t(Ptr); if (Handles.size() > 1) { // This is different behaviour than what Posix dlsym(dlopen(NULL)) does. @@ -137,19 +136,20 @@ // symbols from ucrt.dll first, but iterating NOT in reverse here would // mean that the msvc.dll versions would be returned. - for (auto I = Handles.rbegin(), E = Handles.rend()-1; I != E; ++I) { + for (auto I = Handles.rbegin(), E = Handles.rend() - 1; I != E; ++I) { if (FARPROC Ptr = GetProcAddress(HMODULE(*I), Symbol)) - return (void *) uintptr_t(Ptr); + return (void *)uintptr_t(Ptr); } } return nullptr; } - // Stack probing routines are in the support library (e.g. libgcc), but we don't // have dynamic linking on windows. Provide a hook. -#define EXPLICIT_SYMBOL(SYM) \ - extern "C" { extern void *SYM; } +#define EXPLICIT_SYMBOL(SYM) \ + extern "C" { \ + extern void *SYM; \ + } #define EXPLICIT_SYMBOL2(SYMFROM, SYMTO) EXPLICIT_SYMBOL(SYMTO) #ifdef _M_IX86 diff --git a/llvm/lib/Support/Windows/Host.inc b/llvm/lib/Support/Windows/Host.inc --- a/llvm/lib/Support/Windows/Host.inc +++ b/llvm/lib/Support/Windows/Host.inc @@ -19,14 +19,13 @@ using namespace llvm; -static std::string updateTripleOSVersion(std::string Triple) { - return Triple; -} +static std::string updateTripleOSVersion(std::string Triple) { return Triple; } std::string sys::getDefaultTargetTriple() { const char *Triple = LLVM_DEFAULT_TARGET_TRIPLE; - // Override the default target with an environment variable named by LLVM_TARGET_TRIPLE_ENV. + // Override the default target with an environment variable named by + // LLVM_TARGET_TRIPLE_ENV. #if defined(LLVM_TARGET_TRIPLE_ENV) if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV)) Triple = EnvTriple; diff --git a/llvm/lib/Support/Windows/Memory.inc b/llvm/lib/Support/Windows/Memory.inc --- a/llvm/lib/Support/Windows/Memory.inc +++ b/llvm/lib/Support/Windows/Memory.inc @@ -28,13 +28,12 @@ case llvm::sys::Memory::MF_WRITE: // Note: PAGE_WRITE is not supported by VirtualProtect return PAGE_READWRITE; - case llvm::sys::Memory::MF_READ|llvm::sys::Memory::MF_WRITE: + case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE: return PAGE_READWRITE; - case llvm::sys::Memory::MF_READ|llvm::sys::Memory::MF_EXEC: + case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_EXEC: return PAGE_EXECUTE_READ; - case llvm::sys::Memory::MF_READ | - llvm::sys::Memory::MF_WRITE | - llvm::sys::Memory::MF_EXEC: + case llvm::sys::Memory::MF_READ | llvm::sys::Memory::MF_WRITE | + llvm::sys::Memory::MF_EXEC: return PAGE_EXECUTE_READWRITE; case llvm::sys::Memory::MF_EXEC: return PAGE_EXECUTE; @@ -49,7 +48,7 @@ // granularity may be larger than a single page (in practice, it is 64K) // so mapping less than that will create an unreachable fragment of memory. static size_t getAllocationGranularity() { - SYSTEM_INFO Info; + SYSTEM_INFO Info; ::GetSystemInfo(&Info); if (Info.dwPageSize > Info.dwAllocationGranularity) return Info.dwPageSize; @@ -99,8 +98,7 @@ MemoryBlock Memory::allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, - unsigned Flags, - std::error_code &EC) { + unsigned Flags, std::error_code &EC) { EC = std::error_code(); if (NumBytes == 0) return MemoryBlock(); @@ -121,8 +119,8 @@ size_t NumBlocks = (NumBytes + Granularity - 1) / Granularity; uintptr_t Start = NearBlock ? reinterpret_cast(NearBlock->base()) + - NearBlock->allocatedSize() - : 0; + NearBlock->allocatedSize() + : 0; // If the requested address is not aligned to the allocation granularity, // round up to get beyond NearBlock. VirtualAlloc would have rounded down. @@ -132,8 +130,8 @@ DWORD Protect = getWindowsProtectionFlags(Flags); size_t AllocSize = NumBlocks * Granularity; - void *PA = ::VirtualAlloc(reinterpret_cast(Start), - AllocSize, AllocType, Protect); + void *PA = ::VirtualAlloc(reinterpret_cast(Start), AllocSize, + AllocType, Protect); if (PA == NULL) { if (NearBlock || HugePages) { // Try again without the NearBlock hint and without large memory pages @@ -154,7 +152,7 @@ return Result; } - std::error_code Memory::releaseMappedMemory(MemoryBlock &M) { +std::error_code Memory::releaseMappedMemory(MemoryBlock &M) { if (M.Address == 0 || M.AllocatedSize == 0) return std::error_code(); @@ -167,8 +165,8 @@ return std::error_code(); } - std::error_code Memory::protectMappedMemory(const MemoryBlock &M, - unsigned Flags) { +std::error_code Memory::protectMappedMemory(const MemoryBlock &M, + unsigned Flags) { if (M.Address == 0 || M.AllocatedSize == 0) return std::error_code(); @@ -187,8 +185,7 @@ /// InvalidateInstructionCache - Before the JIT can run a block of code /// that has been emitted it must invalidate the instruction cache on some /// platforms. -void Memory::InvalidateInstructionCache( - const void *Addr, size_t Len) { +void Memory::InvalidateInstructionCache(const void *Addr, size_t Len) { FlushInstructionCache(GetCurrentProcess(), Addr, Len); } diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -37,15 +37,15 @@ #endif #ifdef _MSC_VER -# pragma comment(lib, "advapi32.lib") // This provides CryptAcquireContextW. -# pragma comment(lib, "ole32.lib") // This provides CoTaskMemFree +#pragma comment(lib, "advapi32.lib") // This provides CryptAcquireContextW. +#pragma comment(lib, "ole32.lib") // This provides CoTaskMemFree #endif using namespace llvm; -using llvm::sys::windows::UTF8ToUTF16; using llvm::sys::windows::CurCPToUTF16; using llvm::sys::windows::UTF16ToUTF8; +using llvm::sys::windows::UTF8ToUTF16; using llvm::sys::windows::widenPath; static bool is_separator(const wchar_t value) { @@ -59,7 +59,7 @@ } namespace llvm { -namespace sys { +namespace sys { namespace windows { // Convert a UTF-8 path to UTF-16. Also, if the absolute equivalent of the path @@ -193,9 +193,7 @@ return toTimePoint(Time); } -uint32_t file_status::getLinkCount() const { - return NumLinks; -} +uint32_t file_status::getLinkCount() const { return NumLinks; } std::error_code current_path(SmallVectorImpl &result) { SmallVector cur_path; @@ -372,8 +370,8 @@ // The buffer wasn't big enough, try again. In this case the return value // *does* indicate the size of the null terminator. Buffer.resize_for_overwrite(CountChars); - CountChars = ::GetFinalPathNameByHandleW( - H, Buffer.begin(), Buffer.size(), FILE_NAME_NORMALIZED); + CountChars = ::GetFinalPathNameByHandleW(H, Buffer.begin(), Buffer.size(), + FILE_NAME_NORMALIZED); } Buffer.truncate(CountChars); if (CountChars == 0) @@ -628,8 +626,7 @@ if (Attributes == INVALID_FILE_ATTRIBUTES) { // See if the file didn't actually exist. DWORD LastError = ::GetLastError(); - if (LastError != ERROR_FILE_NOT_FOUND && - LastError != ERROR_PATH_NOT_FOUND) + if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND) return mapWindowsError(LastError); return errc::no_such_file_or_directory; } @@ -650,15 +647,14 @@ bool equivalent(file_status A, file_status B) { assert(status_known(A) && status_known(B)); - return A.FileIndexHigh == B.FileIndexHigh && - A.FileIndexLow == B.FileIndexLow && - A.FileSizeHigh == B.FileSizeHigh && - A.FileSizeLow == B.FileSizeLow && - A.LastAccessedTimeHigh == B.LastAccessedTimeHigh && - A.LastAccessedTimeLow == B.LastAccessedTimeLow && - A.LastWriteTimeHigh == B.LastWriteTimeHigh && - A.LastWriteTimeLow == B.LastWriteTimeLow && - A.VolumeSerialNumber == B.VolumeSerialNumber; + return A.FileIndexHigh == B.FileIndexHigh && + A.FileIndexLow == B.FileIndexLow && A.FileSizeHigh == B.FileSizeHigh && + A.FileSizeLow == B.FileSizeLow && + A.LastAccessedTimeHigh == B.LastAccessedTimeHigh && + A.LastAccessedTimeLow == B.LastAccessedTimeLow && + A.LastWriteTimeHigh == B.LastWriteTimeHigh && + A.LastWriteTimeLow == B.LastWriteTimeLow && + A.VolumeSerialNumber == B.VolumeSerialNumber; } std::error_code equivalent(const Twine &A, const Twine &B, bool &result) { @@ -674,12 +670,10 @@ static bool isReservedName(StringRef path) { // This list of reserved names comes from MSDN, at: // http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx - static const char *const sReservedNames[] = { "nul", "con", "prn", "aux", - "com1", "com2", "com3", "com4", - "com5", "com6", "com7", "com8", - "com9", "lpt1", "lpt2", "lpt3", - "lpt4", "lpt5", "lpt6", "lpt7", - "lpt8", "lpt9" }; + static const char *const sReservedNames[] = { + "nul", "con", "prn", "aux", "com1", "com2", "com3", "com4", + "com5", "com6", "com7", "com8", "com9", "lpt1", "lpt2", "lpt3", + "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9"}; // First, check to see if this is a device namespace, which always // starts with \\.\, since device namespaces are not legal file paths. @@ -744,8 +738,7 @@ handle_status_error: DWORD LastError = ::GetLastError(); - if (LastError == ERROR_FILE_NOT_FOUND || - LastError == ERROR_PATH_NOT_FOUND) + if (LastError == ERROR_FILE_NOT_FOUND || LastError == ERROR_PATH_NOT_FOUND) Result = file_status(file_type::file_not_found); else if (LastError == ERROR_SHARING_VIOLATION) Result = file_status(file_type::type_unknown); @@ -795,9 +788,7 @@ return getStatus(FileHandle, Result); } -unsigned getUmask() { - return 0; -} +unsigned getUmask() { return 0; } std::error_code setPermissions(const Twine &Path, perms Permissions) { SmallVector PathUTF16; @@ -816,8 +807,7 @@ if (Attributes == 0) // FILE_ATTRIBUTE_NORMAL indicates no other attributes are set. Attributes |= FILE_ATTRIBUTE_NORMAL; - } - else { + } else { Attributes |= FILE_ATTRIBUTE_READONLY; // FILE_ATTRIBUTE_NORMAL is not compatible with any other attributes, so // remove it, if it is present. @@ -853,16 +843,19 @@ DWORD flprotect; switch (Mode) { - case readonly: flprotect = PAGE_READONLY; break; - case readwrite: flprotect = PAGE_READWRITE; break; - case priv: flprotect = PAGE_WRITECOPY; break; + case readonly: + flprotect = PAGE_READONLY; + break; + case readwrite: + flprotect = PAGE_READWRITE; + break; + case priv: + flprotect = PAGE_WRITECOPY; + break; } - HANDLE FileMappingHandle = - ::CreateFileMappingW(OrigFileHandle, 0, flprotect, - Hi_32(Size), - Lo_32(Size), - 0); + HANDLE FileMappingHandle = ::CreateFileMappingW(OrigFileHandle, 0, flprotect, + Hi_32(Size), Lo_32(Size), 0); if (FileMappingHandle == NULL) { std::error_code ec = mapWindowsError(GetLastError()); return ec; @@ -870,15 +863,18 @@ DWORD dwDesiredAccess; switch (Mode) { - case readonly: dwDesiredAccess = FILE_MAP_READ; break; - case readwrite: dwDesiredAccess = FILE_MAP_WRITE; break; - case priv: dwDesiredAccess = FILE_MAP_COPY; break; + case readonly: + dwDesiredAccess = FILE_MAP_READ; + break; + case readwrite: + dwDesiredAccess = FILE_MAP_WRITE; + break; + case priv: + dwDesiredAccess = FILE_MAP_COPY; + break; } - Mapping = ::MapViewOfFile(FileMappingHandle, - dwDesiredAccess, - Offset >> 32, - Offset & 0xffffffff, - Size); + Mapping = ::MapViewOfFile(FileMappingHandle, dwDesiredAccess, Offset >> 32, + Offset & 0xffffffff, Size); if (Mapping == NULL) { std::error_code ec = mapWindowsError(GetLastError()); ::CloseHandle(FileMappingHandle); @@ -1008,7 +1004,7 @@ size_t FilenameLen = ::wcslen(FirstFind.cFileName); while ((FilenameLen == 1 && FirstFind.cFileName[0] == L'.') || (FilenameLen == 2 && FirstFind.cFileName[0] == L'.' && - FirstFind.cFileName[1] == L'.')) + FirstFind.cFileName[1] == L'.')) if (!::FindNextFileW(FindHandle, &FirstFind)) { DWORD LastError = ::GetLastError(); // Check for end. @@ -1058,7 +1054,7 @@ size_t FilenameLen = ::wcslen(FindData.cFileName); if ((FilenameLen == 1 && FindData.cFileName[0] == L'.') || (FilenameLen == 2 && FindData.cFileName[0] == L'.' && - FindData.cFileName[1] == L'.')) + FindData.cFileName[1] == L'.')) return directory_iterator_increment(IT); SmallString<128> DirectoryEntryPathUTF8; @@ -1074,9 +1070,7 @@ return std::error_code(); } -ErrorOr directory_entry::status() const { - return Status; -} +ErrorOr directory_entry::status() const { return Status; } static std::error_code nativeFileToFd(Expected H, int &ResultFD, OpenFlags Flags) { @@ -1365,7 +1359,8 @@ StringRef PathStr(Path.begin(), Path.size()); PathStr = PathStr.drop_front(); - StringRef Expr = PathStr.take_until([](char c) { return path::is_separator(c); }); + StringRef Expr = + PathStr.take_until([](char c) { return path::is_separator(c); }); if (!Expr.empty()) { // This is probably a ~username/ expression. Don't support this on Windows. @@ -1496,12 +1491,12 @@ } // end namespace path namespace windows { -std::error_code CodePageToUTF16(unsigned codepage, - llvm::StringRef original, +std::error_code CodePageToUTF16(unsigned codepage, llvm::StringRef original, llvm::SmallVectorImpl &utf16) { if (!original.empty()) { - int len = ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.begin(), - original.size(), utf16.begin(), 0); + int len = + ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.begin(), + original.size(), utf16.begin(), 0); if (len == 0) { return mapWindowsError(::GetLastError()); @@ -1510,8 +1505,9 @@ utf16.reserve(len + 1); utf16.resize_for_overwrite(len); - len = ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.begin(), - original.size(), utf16.begin(), utf16.size()); + len = + ::MultiByteToWideChar(codepage, MB_ERR_INVALID_CHARS, original.begin(), + original.size(), utf16.begin(), utf16.size()); if (len == 0) { return mapWindowsError(::GetLastError()); @@ -1531,18 +1527,17 @@ } std::error_code CurCPToUTF16(llvm::StringRef curcp, - llvm::SmallVectorImpl &utf16) { + llvm::SmallVectorImpl &utf16) { return CodePageToUTF16(CP_ACP, curcp, utf16); } -static -std::error_code UTF16ToCodePage(unsigned codepage, const wchar_t *utf16, - size_t utf16_len, - llvm::SmallVectorImpl &converted) { +static std::error_code UTF16ToCodePage(unsigned codepage, const wchar_t *utf16, + size_t utf16_len, + llvm::SmallVectorImpl &converted) { if (utf16_len) { // Get length. - int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, converted.begin(), - 0, NULL, NULL); + int len = ::WideCharToMultiByte(codepage, 0, utf16, utf16_len, + converted.begin(), 0, NULL, NULL); if (len == 0) { return mapWindowsError(::GetLastError()); diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc --- a/llvm/lib/Support/Windows/Process.inc +++ b/llvm/lib/Support/Windows/Process.inc @@ -27,8 +27,8 @@ #include #if !defined(__MINGW32__) - #pragma comment(lib, "psapi.lib") - #pragma comment(lib, "shell32.lib") +#pragma comment(lib, "psapi.lib") +#pragma comment(lib, "shell32.lib") #endif //===----------------------------------------------------------------------===// @@ -38,7 +38,7 @@ #ifdef __MINGW32__ // This ban should be lifted when MinGW 1.0+ has defined this value. -# define _HEAPOK (-2) +#define _HEAPOK (-2) #endif using namespace llvm; @@ -67,9 +67,7 @@ return Ret; } -size_t -Process::GetMallocUsage() -{ +size_t Process::GetMallocUsage() { _HEAPINFO hinfo; hinfo._pentry = NULL; @@ -81,9 +79,11 @@ return size; } -void Process::GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, +void Process::GetTimeUsage(TimePoint<> &elapsed, + std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time) { - elapsed = std::chrono::system_clock::now();; + elapsed = std::chrono::system_clock::now(); + ; FILETIME ProcCreate, ProcExit, KernelTime, UserTime; if (GetProcessTimes(GetCurrentProcess(), &ProcCreate, &ProcExit, &KernelTime, @@ -108,8 +108,7 @@ // // Windows also has modal pop-up message boxes. As this method is used by // bugpoint, preventing these pop-ups is additionally important. - SetErrorMode(SEM_FAILCRITICALERRORS | - SEM_NOGPFAULTERRORBOX | + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); coreFilesPrevented = true; @@ -131,8 +130,7 @@ do { Buf.resize_for_overwrite(Size); SetLastError(NO_ERROR); - Size = - GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.size()); + Size = GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.size()); if (Size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND) return None; @@ -281,20 +279,14 @@ return std::error_code(); } -bool Process::StandardInIsUserInput() { - return FileDescriptorIsDisplayed(0); -} +bool Process::StandardInIsUserInput() { return FileDescriptorIsDisplayed(0); } -bool Process::StandardOutIsDisplayed() { - return FileDescriptorIsDisplayed(1); -} +bool Process::StandardOutIsDisplayed() { return FileDescriptorIsDisplayed(1); } -bool Process::StandardErrIsDisplayed() { - return FileDescriptorIsDisplayed(2); -} +bool Process::StandardErrIsDisplayed() { return FileDescriptorIsDisplayed(2); } bool Process::FileDescriptorIsDisplayed(int fd) { - DWORD Mode; // Unused + DWORD Mode; // Unused return (GetConsoleMode((HANDLE)_get_osfhandle(fd), &Mode) != 0); } @@ -319,13 +311,9 @@ return FileDescriptorIsDisplayed(fd); } -bool Process::StandardOutHasColors() { - return FileDescriptorHasColors(1); -} +bool Process::StandardOutHasColors() { return FileDescriptorHasColors(1); } -bool Process::StandardErrHasColors() { - return FileDescriptorHasColors(2); -} +bool Process::StandardErrHasColors() { return FileDescriptorHasColors(2); } static bool UseANSI = false; void Process::UseANSIEscapeCodes(bool enable) { @@ -342,41 +330,39 @@ } namespace { -class DefaultColors -{ - private: - WORD defaultColor; - public: - DefaultColors() - :defaultColor(GetCurrentColor()) {} - static unsigned GetCurrentColor() { - CONSOLE_SCREEN_BUFFER_INFO csbi; - if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) - return csbi.wAttributes; - return 0; - } - WORD operator()() const { return defaultColor; } +class DefaultColors { +private: + WORD defaultColor; + +public: + DefaultColors() : defaultColor(GetCurrentColor()) {} + static unsigned GetCurrentColor() { + CONSOLE_SCREEN_BUFFER_INFO csbi; + if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) + return csbi.wAttributes; + return 0; + } + WORD operator()() const { return defaultColor; } }; DefaultColors defaultColors; WORD fg_color(WORD color) { - return color & (FOREGROUND_BLUE | FOREGROUND_GREEN | - FOREGROUND_INTENSITY | FOREGROUND_RED); + return color & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | + FOREGROUND_RED); } WORD bg_color(WORD color) { - return color & (BACKGROUND_BLUE | BACKGROUND_GREEN | - BACKGROUND_INTENSITY | BACKGROUND_RED); -} + return color & (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY | + BACKGROUND_RED); } +} // namespace -bool Process::ColorNeedsFlush() { - return !UseANSI; -} +bool Process::ColorNeedsFlush() { return !UseANSI; } const char *Process::OutputBold(bool bg) { - if (UseANSI) return "\033[1m"; + if (UseANSI) + return "\033[1m"; WORD colors = DefaultColors::GetCurrentColor(); if (bg) @@ -388,21 +374,22 @@ } const char *Process::OutputColor(char code, bool bold, bool bg) { - if (UseANSI) return colorcodes[bg?1:0][bold?1:0][code&7]; + if (UseANSI) + return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7]; WORD current = DefaultColors::GetCurrentColor(); WORD colors; if (bg) { - colors = ((code&1) ? BACKGROUND_RED : 0) | - ((code&2) ? BACKGROUND_GREEN : 0 ) | - ((code&4) ? BACKGROUND_BLUE : 0); + colors = ((code & 1) ? BACKGROUND_RED : 0) | + ((code & 2) ? BACKGROUND_GREEN : 0) | + ((code & 4) ? BACKGROUND_BLUE : 0); if (bold) colors |= BACKGROUND_INTENSITY; colors |= fg_color(current); } else { - colors = ((code&1) ? FOREGROUND_RED : 0) | - ((code&2) ? FOREGROUND_GREEN : 0 ) | - ((code&4) ? FOREGROUND_BLUE : 0); + colors = ((code & 1) ? FOREGROUND_RED : 0) | + ((code & 2) ? FOREGROUND_GREEN : 0) | + ((code & 4) ? FOREGROUND_BLUE : 0); if (bold) colors |= FOREGROUND_INTENSITY; colors |= bg_color(current); @@ -418,27 +405,27 @@ } const char *Process::OutputReverse() { - if (UseANSI) return "\033[7m"; + if (UseANSI) + return "\033[7m"; - const WORD attributes - = GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)); + const WORD attributes = + GetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)); const WORD foreground_mask = FOREGROUND_BLUE | FOREGROUND_GREEN | - FOREGROUND_RED | FOREGROUND_INTENSITY; + FOREGROUND_RED | FOREGROUND_INTENSITY; const WORD background_mask = BACKGROUND_BLUE | BACKGROUND_GREEN | - BACKGROUND_RED | BACKGROUND_INTENSITY; + BACKGROUND_RED | BACKGROUND_INTENSITY; const WORD color_mask = foreground_mask | background_mask; WORD new_attributes = - ((attributes & FOREGROUND_BLUE )?BACKGROUND_BLUE :0) | - ((attributes & FOREGROUND_GREEN )?BACKGROUND_GREEN :0) | - ((attributes & FOREGROUND_RED )?BACKGROUND_RED :0) | - ((attributes & FOREGROUND_INTENSITY)?BACKGROUND_INTENSITY:0) | - ((attributes & BACKGROUND_BLUE )?FOREGROUND_BLUE :0) | - ((attributes & BACKGROUND_GREEN )?FOREGROUND_GREEN :0) | - ((attributes & BACKGROUND_RED )?FOREGROUND_RED :0) | - ((attributes & BACKGROUND_INTENSITY)?FOREGROUND_INTENSITY:0) | - 0; + ((attributes & FOREGROUND_BLUE) ? BACKGROUND_BLUE : 0) | + ((attributes & FOREGROUND_GREEN) ? BACKGROUND_GREEN : 0) | + ((attributes & FOREGROUND_RED) ? BACKGROUND_RED : 0) | + ((attributes & FOREGROUND_INTENSITY) ? BACKGROUND_INTENSITY : 0) | + ((attributes & BACKGROUND_BLUE) ? FOREGROUND_BLUE : 0) | + ((attributes & BACKGROUND_GREEN) ? FOREGROUND_GREEN : 0) | + ((attributes & BACKGROUND_RED) ? FOREGROUND_RED : 0) | + ((attributes & BACKGROUND_INTENSITY) ? FOREGROUND_INTENSITY : 0) | 0; new_attributes = (attributes & ~color_mask) | (new_attributes & color_mask); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), new_attributes); @@ -446,7 +433,8 @@ } const char *Process::ResetColor() { - if (UseANSI) return "\033[0m"; + if (UseANSI) + return "\033[0m"; SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors()); return 0; } @@ -485,7 +473,7 @@ return GetPseudoRandomNumber(); } -typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) llvm::VersionTuple llvm::GetWindowsOSVersion() { diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc --- a/llvm/lib/Support/Windows/Program.inc +++ b/llvm/lib/Support/Windows/Program.inc @@ -82,8 +82,8 @@ windows::UTF8ToUTF16(Twine(Name + Ext).str(), U16NameExt)) return EC; - Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr, - U16Result.size(), U16Result.data(), nullptr); + Len = ::SearchPathW(Path, c_str(U16NameExt), nullptr, U16Result.size(), + U16Result.data(), nullptr); } while (Len > U16Result.size()); if (Len == 0) @@ -92,7 +92,7 @@ U16Result.truncate(Len); if (std::error_code EC = - windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result)) + windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result)) return EC; if (sys::fs::can_execute(U8Result)) @@ -132,8 +132,8 @@ HANDLE h; if (!Path) { if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd), - GetCurrentProcess(), &h, - 0, TRUE, DUPLICATE_SAME_ACCESS)) + GetCurrentProcess(), &h, 0, TRUE, + DUPLICATE_SAME_ACCESS)) return INVALID_HANDLE_VALUE; return h; } @@ -162,14 +162,14 @@ FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (h == INVALID_HANDLE_VALUE) { - MakeErrMsg(ErrMsg, fname + ": Can't open file for " + - (fd ? "input" : "output")); + MakeErrMsg(ErrMsg, + fname + ": Can't open file for " + (fd ? "input" : "output")); } return h; } -} +} // namespace llvm static bool Execute(ProcessInfo &PI, StringRef Program, ArrayRef Args, Optional> Env, @@ -248,8 +248,8 @@ // If stdout and stderr should go to the same place, redirect stderr // to the handle already open for stdout. if (!DuplicateHandle(GetCurrentProcess(), si.hStdOutput, - GetCurrentProcess(), &si.hStdError, - 0, TRUE, DUPLICATE_SAME_ACCESS)) { + GetCurrentProcess(), &si.hStdError, 0, TRUE, + DUPLICATE_SAME_ACCESS)) { CloseHandle(si.hStdInput); CloseHandle(si.hStdOutput); MakeErrMsg(ErrMsg, "can't dup stderr to stdout"); @@ -301,8 +301,8 @@ // Now return an error if the process didn't get created. if (!rc) { SetLastError(err); - MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") + - Program.str() + "'"); + MakeErrMsg(ErrMsg, + std::string("Couldn't execute program '") + Program.str() + "'"); return false; } @@ -490,13 +490,13 @@ return WaitResult; } -std::error_code llvm::sys::ChangeStdinMode(sys::fs::OpenFlags Flags){ +std::error_code llvm::sys::ChangeStdinMode(sys::fs::OpenFlags Flags) { if (!(Flags & fs::OF_CRLF)) return ChangeStdinToBinary(); return std::error_code(); } -std::error_code llvm::sys::ChangeStdoutMode(sys::fs::OpenFlags Flags){ +std::error_code llvm::sys::ChangeStdoutMode(sys::fs::OpenFlags Flags) { if (!(Flags & fs::OF_CRLF)) return ChangeStdoutToBinary(); return std::error_code(); @@ -533,8 +533,8 @@ if ((EC = windows::UTF8ToUTF16(Contents, ArgsUTF16))) return EC; - if ((EC = windows::UTF16ToCurCP( - ArgsUTF16.data(), ArgsUTF16.size(), ArgsCurCP))) + if ((EC = windows::UTF16ToCurCP(ArgsUTF16.data(), ArgsUTF16.size(), + ArgsCurCP))) return EC; OS.write(ArgsCurCP.data(), ArgsCurCP.size()); @@ -574,4 +574,4 @@ assert(!Result.getError()); return (Result->size() + 1) <= MaxCommandStringLength; } -} +} // namespace llvm diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc --- a/llvm/lib/Support/Windows/Signals.inc +++ b/llvm/lib/Support/Windows/Signals.inc @@ -26,98 +26,99 @@ #include "llvm/Support/Windows/WindowsSupport.h" #ifdef __MINGW32__ - #include +#include #else - #include - #include +#include +#include #endif #include #ifdef _MSC_VER - #pragma comment(lib, "psapi.lib") +#pragma comment(lib, "psapi.lib") #elif __MINGW32__ - // The version of g++ that comes with MinGW does *not* properly understand - // the ll format specifier for printf. However, MinGW passes the format - // specifiers on to the MSVCRT entirely, and the CRT understands the ll - // specifier. So these warnings are spurious in this case. Since we compile - // with -Wall, this will generate these warnings which should be ignored. So - // we will turn off the warnings for this just file. However, MinGW also does - // not support push and pop for diagnostics, so we have to manually turn it - // back on at the end of the file. - #pragma GCC diagnostic ignored "-Wformat" - #pragma GCC diagnostic ignored "-Wformat-extra-args" - - #if !defined(__MINGW64_VERSION_MAJOR) - // MinGW.org does not have updated support for the 64-bit versions of the - // DebugHlp APIs. So we will have to load them manually. The structures and - // method signatures were pulled from DbgHelp.h in the Windows Platform SDK, - // and adjusted for brevity. - typedef struct _IMAGEHLP_LINE64 { - DWORD SizeOfStruct; - PVOID Key; - DWORD LineNumber; - PCHAR FileName; - DWORD64 Address; - } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; - - typedef struct _IMAGEHLP_SYMBOL64 { - DWORD SizeOfStruct; - DWORD64 Address; - DWORD Size; - DWORD Flags; - DWORD MaxNameLength; - CHAR Name[1]; - } IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; - - typedef struct _tagADDRESS64 { - DWORD64 Offset; - WORD Segment; - ADDRESS_MODE Mode; - } ADDRESS64, *LPADDRESS64; - - typedef struct _KDHELP64 { - DWORD64 Thread; - DWORD ThCallbackStack; - DWORD ThCallbackBStore; - DWORD NextCallback; - DWORD FramePointer; - DWORD64 KiCallUserMode; - DWORD64 KeUserCallbackDispatcher; - DWORD64 SystemRangeStart; - DWORD64 KiUserExceptionDispatcher; - DWORD64 StackBase; - DWORD64 StackLimit; - DWORD64 Reserved[5]; - } KDHELP64, *PKDHELP64; - - typedef struct _tagSTACKFRAME64 { - ADDRESS64 AddrPC; - ADDRESS64 AddrReturn; - ADDRESS64 AddrFrame; - ADDRESS64 AddrStack; - ADDRESS64 AddrBStore; - PVOID FuncTableEntry; - DWORD64 Params[4]; - BOOL Far; - BOOL Virtual; - DWORD64 Reserved[3]; - KDHELP64 KdHelp; - } STACKFRAME64, *LPSTACKFRAME64; - #endif // !defined(__MINGW64_VERSION_MAJOR) +// The version of g++ that comes with MinGW does *not* properly understand +// the ll format specifier for printf. However, MinGW passes the format +// specifiers on to the MSVCRT entirely, and the CRT understands the ll +// specifier. So these warnings are spurious in this case. Since we compile +// with -Wall, this will generate these warnings which should be ignored. So +// we will turn off the warnings for this just file. However, MinGW also does +// not support push and pop for diagnostics, so we have to manually turn it +// back on at the end of the file. +#pragma GCC diagnostic ignored "-Wformat" +#pragma GCC diagnostic ignored "-Wformat-extra-args" + +#if !defined(__MINGW64_VERSION_MAJOR) +// MinGW.org does not have updated support for the 64-bit versions of the +// DebugHlp APIs. So we will have to load them manually. The structures and +// method signatures were pulled from DbgHelp.h in the Windows Platform SDK, +// and adjusted for brevity. +typedef struct _IMAGEHLP_LINE64 { + DWORD SizeOfStruct; + PVOID Key; + DWORD LineNumber; + PCHAR FileName; + DWORD64 Address; +} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; + +typedef struct _IMAGEHLP_SYMBOL64 { + DWORD SizeOfStruct; + DWORD64 Address; + DWORD Size; + DWORD Flags; + DWORD MaxNameLength; + CHAR Name[1]; +} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; + +typedef struct _tagADDRESS64 { + DWORD64 Offset; + WORD Segment; + ADDRESS_MODE Mode; +} ADDRESS64, *LPADDRESS64; + +typedef struct _KDHELP64 { + DWORD64 Thread; + DWORD ThCallbackStack; + DWORD ThCallbackBStore; + DWORD NextCallback; + DWORD FramePointer; + DWORD64 KiCallUserMode; + DWORD64 KeUserCallbackDispatcher; + DWORD64 SystemRangeStart; + DWORD64 KiUserExceptionDispatcher; + DWORD64 StackBase; + DWORD64 StackLimit; + DWORD64 Reserved[5]; +} KDHELP64, *PKDHELP64; + +typedef struct _tagSTACKFRAME64 { + ADDRESS64 AddrPC; + ADDRESS64 AddrReturn; + ADDRESS64 AddrFrame; + ADDRESS64 AddrStack; + ADDRESS64 AddrBStore; + PVOID FuncTableEntry; + DWORD64 Params[4]; + BOOL Far; + BOOL Virtual; + DWORD64 Reserved[3]; + KDHELP64 KdHelp; +} STACKFRAME64, *LPSTACKFRAME64; +#endif // !defined(__MINGW64_VERSION_MAJOR) #endif // __MINGW32__ -typedef BOOL (__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess, - DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, - LPDWORD lpNumberOfBytesRead); +typedef BOOL(__stdcall *PREAD_PROCESS_MEMORY_ROUTINE64)( + HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, + LPDWORD lpNumberOfBytesRead); -typedef PVOID (__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)( HANDLE ahProcess, - DWORD64 AddrBase); +typedef PVOID(__stdcall *PFUNCTION_TABLE_ACCESS_ROUTINE64)(HANDLE ahProcess, + DWORD64 AddrBase); -typedef DWORD64 (__stdcall *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess, - DWORD64 Address); +typedef DWORD64(__stdcall *PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess, + DWORD64 Address); -typedef DWORD64 (__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess, - HANDLE hThread, LPADDRESS64 lpaddr); +typedef DWORD64(__stdcall *PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess, + HANDLE hThread, + LPADDRESS64 lpaddr); typedef BOOL(WINAPI *fpMiniDumpWriteDump)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, @@ -125,38 +126,40 @@ PMINIDUMP_CALLBACK_INFORMATION); static fpMiniDumpWriteDump fMiniDumpWriteDump; -typedef BOOL (WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, - PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, - PFUNCTION_TABLE_ACCESS_ROUTINE64, - PGET_MODULE_BASE_ROUTINE64, - PTRANSLATE_ADDRESS_ROUTINE64); +typedef BOOL(WINAPI *fpStackWalk64)(DWORD, HANDLE, HANDLE, LPSTACKFRAME64, + PVOID, PREAD_PROCESS_MEMORY_ROUTINE64, + PFUNCTION_TABLE_ACCESS_ROUTINE64, + PGET_MODULE_BASE_ROUTINE64, + PTRANSLATE_ADDRESS_ROUTINE64); static fpStackWalk64 fStackWalk64; -typedef DWORD64 (WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64); +typedef DWORD64(WINAPI *fpSymGetModuleBase64)(HANDLE, DWORD64); static fpSymGetModuleBase64 fSymGetModuleBase64; -typedef BOOL (WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, - PDWORD64, PIMAGEHLP_SYMBOL64); +typedef BOOL(WINAPI *fpSymGetSymFromAddr64)(HANDLE, DWORD64, PDWORD64, + PIMAGEHLP_SYMBOL64); static fpSymGetSymFromAddr64 fSymGetSymFromAddr64; -typedef BOOL (WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, - PDWORD, PIMAGEHLP_LINE64); +typedef BOOL(WINAPI *fpSymGetLineFromAddr64)(HANDLE, DWORD64, PDWORD, + PIMAGEHLP_LINE64); static fpSymGetLineFromAddr64 fSymGetLineFromAddr64; typedef BOOL(WINAPI *fpSymGetModuleInfo64)(HANDLE hProcess, DWORD64 dwAddr, PIMAGEHLP_MODULE64 ModuleInfo); static fpSymGetModuleInfo64 fSymGetModuleInfo64; -typedef PVOID (WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64); +typedef PVOID(WINAPI *fpSymFunctionTableAccess64)(HANDLE, DWORD64); static fpSymFunctionTableAccess64 fSymFunctionTableAccess64; -typedef DWORD (WINAPI *fpSymSetOptions)(DWORD); +typedef DWORD(WINAPI *fpSymSetOptions)(DWORD); static fpSymSetOptions fSymSetOptions; -typedef BOOL (WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL); +typedef BOOL(WINAPI *fpSymInitialize)(HANDLE, PCSTR, BOOL); static fpSymInitialize fSymInitialize; -typedef BOOL (WINAPI *fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALLBACK64,PVOID); +typedef BOOL(WINAPI *fpEnumerateLoadedModules)(HANDLE, + PENUMLOADED_MODULES_CALLBACK64, + PVOID); static fpEnumerateLoadedModules fEnumerateLoadedModules; static bool isDebugHelpInitialized() { @@ -166,24 +169,23 @@ static bool load64BitDebugHelp(void) { HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll"); if (hLib) { - fMiniDumpWriteDump = (fpMiniDumpWriteDump) - ::GetProcAddress(hLib, "MiniDumpWriteDump"); - fStackWalk64 = (fpStackWalk64) - ::GetProcAddress(hLib, "StackWalk64"); - fSymGetModuleBase64 = (fpSymGetModuleBase64) - ::GetProcAddress(hLib, "SymGetModuleBase64"); - fSymGetSymFromAddr64 = (fpSymGetSymFromAddr64) - ::GetProcAddress(hLib, "SymGetSymFromAddr64"); - fSymGetLineFromAddr64 = (fpSymGetLineFromAddr64) - ::GetProcAddress(hLib, "SymGetLineFromAddr64"); - fSymGetModuleInfo64 = (fpSymGetModuleInfo64) - ::GetProcAddress(hLib, "SymGetModuleInfo64"); - fSymFunctionTableAccess64 = (fpSymFunctionTableAccess64) - ::GetProcAddress(hLib, "SymFunctionTableAccess64"); + fMiniDumpWriteDump = + (fpMiniDumpWriteDump)::GetProcAddress(hLib, "MiniDumpWriteDump"); + fStackWalk64 = (fpStackWalk64)::GetProcAddress(hLib, "StackWalk64"); + fSymGetModuleBase64 = + (fpSymGetModuleBase64)::GetProcAddress(hLib, "SymGetModuleBase64"); + fSymGetSymFromAddr64 = + (fpSymGetSymFromAddr64)::GetProcAddress(hLib, "SymGetSymFromAddr64"); + fSymGetLineFromAddr64 = + (fpSymGetLineFromAddr64)::GetProcAddress(hLib, "SymGetLineFromAddr64"); + fSymGetModuleInfo64 = + (fpSymGetModuleInfo64)::GetProcAddress(hLib, "SymGetModuleInfo64"); + fSymFunctionTableAccess64 = (fpSymFunctionTableAccess64)::GetProcAddress( + hLib, "SymFunctionTableAccess64"); fSymSetOptions = (fpSymSetOptions)::GetProcAddress(hLib, "SymSetOptions"); fSymInitialize = (fpSymInitialize)::GetProcAddress(hLib, "SymInitialize"); - fEnumerateLoadedModules = (fpEnumerateLoadedModules) - ::GetProcAddress(hLib, "EnumerateLoadedModules64"); + fEnumerateLoadedModules = (fpEnumerateLoadedModules)::GetProcAddress( + hLib, "EnumerateLoadedModules64"); } return isDebugHelpInitialized(); } @@ -261,12 +263,11 @@ intptr_t *Offsets; StringSaver *StrPool; }; -} +} // namespace -static BOOL CALLBACK findModuleCallback(PCSTR ModuleName, - DWORD64 ModuleBase, ULONG ModuleSize, - void *VoidData) { - FindModuleData *Data = (FindModuleData*)VoidData; +static BOOL CALLBACK findModuleCallback(PCSTR ModuleName, DWORD64 ModuleBase, + ULONG ModuleSize, void *VoidData) { + FindModuleData *Data = (FindModuleData *)VoidData; intptr_t Beg = ModuleBase; intptr_t End = Beg + ModuleSize; for (int I = 0; I < Data->Depth; I++) { @@ -454,7 +455,7 @@ } // The public API -bool sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { +bool sys::RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg) { RegisterHandler(); if (CleanupExecuted) { @@ -482,7 +483,7 @@ std::vector::reverse_iterator I = find(reverse(*FilesToRemove), Filename); if (I != FilesToRemove->rend()) - FilesToRemove->erase(I.base()-1); + FilesToRemove->erase(I.base() - 1); LeaveCriticalSection(&CriticalSection); } @@ -519,7 +520,7 @@ RegisterHandler(); LeaveCriticalSection(&CriticalSection); } -} +} // namespace llvm #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) // Provide a prototype for RtlCaptureContext, mingw32 from mingw.org is @@ -697,8 +698,7 @@ DWORD DumpType; DWORD TypeSize = sizeof(DumpType); if (ERROR_SUCCESS != ::RegGetValueW(Key, NULL, L"DumpType", RRF_RT_REG_DWORD, - NULL, &DumpType, - &TypeSize)) + NULL, &DumpType, &TypeSize)) return false; switch (DumpType) { @@ -865,14 +865,14 @@ // If an interrupt function has been set, go and run one it; otherwise, // the process dies. void (*IF)() = InterruptFunction; - InterruptFunction = 0; // Don't run it on another CTRL-C. + InterruptFunction = 0; // Don't run it on another CTRL-C. if (IF) { // Note: if the interrupt function throws an exception, there is nothing // to catch it in this thread so it will kill the process. - IF(); // Run it now. + IF(); // Run it now. LeaveCriticalSection(&CriticalSection); - return TRUE; // Don't kill the process. + return TRUE; // Don't kill the process. } // Allow normal processing to take place; i.e., the process dies. @@ -881,12 +881,12 @@ } #if __MINGW32__ - // We turned these warnings off for this file so that MinGW-g++ doesn't - // complain about the ll format specifiers used. Now we are turning the - // warnings back on. If MinGW starts to support diagnostic stacks, we can - // replace this with a pop. - #pragma GCC diagnostic warning "-Wformat" - #pragma GCC diagnostic warning "-Wformat-extra-args" +// We turned these warnings off for this file so that MinGW-g++ doesn't +// complain about the ll format specifiers used. Now we are turning the +// warnings back on. If MinGW starts to support diagnostic stacks, we can +// replace this with a pop. +#pragma GCC diagnostic warning "-Wformat" +#pragma GCC diagnostic warning "-Wformat-extra-args" #endif void sys::unregisterHandlers() {} diff --git a/llvm/lib/Support/Windows/ThreadLocal.inc b/llvm/lib/Support/Windows/ThreadLocal.inc --- a/llvm/lib/Support/Windows/ThreadLocal.inc +++ b/llvm/lib/Support/Windows/ThreadLocal.inc @@ -1,4 +1,5 @@ -//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++ -*-===// +//= llvm/Support/Win32/ThreadLocal.inc - Win32 Thread Local Data -*- C++ +//-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -15,37 +16,35 @@ //=== is guaranteed to work on *all* Win32 variants. //===----------------------------------------------------------------------===// -#include "llvm/Support/Windows/WindowsSupport.h" #include "llvm/Support/ThreadLocal.h" +#include "llvm/Support/Windows/WindowsSupport.h" namespace llvm { sys::ThreadLocalImpl::ThreadLocalImpl() : data() { static_assert(sizeof(DWORD) <= sizeof(data), "size too big"); - DWORD* tls = reinterpret_cast(&data); + DWORD *tls = reinterpret_cast(&data); *tls = TlsAlloc(); assert(*tls != TLS_OUT_OF_INDEXES); } sys::ThreadLocalImpl::~ThreadLocalImpl() { - DWORD* tls = reinterpret_cast(&data); + DWORD *tls = reinterpret_cast(&data); TlsFree(*tls); } void *sys::ThreadLocalImpl::getInstance() { - DWORD* tls = reinterpret_cast(&data); + DWORD *tls = reinterpret_cast(&data); return TlsGetValue(*tls); } -void sys::ThreadLocalImpl::setInstance(const void* d){ - DWORD* tls = reinterpret_cast(&data); - int errorcode = TlsSetValue(*tls, const_cast(d)); +void sys::ThreadLocalImpl::setInstance(const void *d) { + DWORD *tls = reinterpret_cast(&data); + int errorcode = TlsSetValue(*tls, const_cast(d)); assert(errorcode != 0); (void)errorcode; } -void sys::ThreadLocalImpl::removeInstance() { - setInstance(0); -} +void sys::ThreadLocalImpl::removeInstance() { setInstance(0); } -} +} // namespace llvm diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc --- a/llvm/lib/Support/Windows/Threading.inc +++ b/llvm/lib/Support/Windows/Threading.inc @@ -49,19 +49,13 @@ } } -DWORD llvm_thread_get_id_impl(HANDLE hThread) { - return ::GetThreadId(hThread); -} +DWORD llvm_thread_get_id_impl(HANDLE hThread) { return ::GetThreadId(hThread); } -DWORD llvm_thread_get_current_id_impl() { - return ::GetCurrentThreadId(); -} +DWORD llvm_thread_get_current_id_impl() { return ::GetCurrentThreadId(); } } // namespace llvm -uint64_t llvm::get_threadid() { - return uint64_t(::GetCurrentThreadId()); -} +uint64_t llvm::get_threadid() { return uint64_t(::GetCurrentThreadId()); } uint32_t llvm::get_max_thread_name_length() { return 0; } @@ -86,9 +80,8 @@ __try { ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), - (ULONG_PTR *)&info); - } - __except (EXCEPTION_EXECUTE_HANDLER) { + (ULONG_PTR *)&info); + } __except (EXCEPTION_EXECUTE_HANDLER) { } } #endif diff --git a/llvm/lib/Support/Windows/Watchdog.inc b/llvm/lib/Support/Windows/Watchdog.inc --- a/llvm/lib/Support/Windows/Watchdog.inc +++ b/llvm/lib/Support/Windows/Watchdog.inc @@ -16,8 +16,8 @@ // and a second thread to run the TimerAPCProc. namespace llvm { - namespace sys { - Watchdog::Watchdog(unsigned int seconds) {} - Watchdog::~Watchdog() {} - } -} +namespace sys { +Watchdog::Watchdog(unsigned int seconds) {} +Watchdog::~Watchdog() {} +} // namespace sys +} // namespace llvm diff --git a/llvm/lib/Support/Windows/explicit_symbols.inc b/llvm/lib/Support/Windows/explicit_symbols.inc --- a/llvm/lib/Support/Windows/explicit_symbols.inc +++ b/llvm/lib/Support/Windows/explicit_symbols.inc @@ -1,94 +1,94 @@ /* in libgcc.a */ #ifdef HAVE__ALLOCA - EXPLICIT_SYMBOL(_alloca) - EXPLICIT_SYMBOL2(alloca, _alloca) +EXPLICIT_SYMBOL(_alloca) +EXPLICIT_SYMBOL2(alloca, _alloca) #endif #ifdef HAVE___ALLOCA - EXPLICIT_SYMBOL(__alloca) +EXPLICIT_SYMBOL(__alloca) #endif #ifdef HAVE___CHKSTK - EXPLICIT_SYMBOL(__chkstk) +EXPLICIT_SYMBOL(__chkstk) #endif #ifdef HAVE___CHKSTK_MS - EXPLICIT_SYMBOL(__chkstk_ms) +EXPLICIT_SYMBOL(__chkstk_ms) #endif #ifdef HAVE____CHKSTK - EXPLICIT_SYMBOL(___chkstk) +EXPLICIT_SYMBOL(___chkstk) #endif #ifdef HAVE____CHKSTK_MS - EXPLICIT_SYMBOL(___chkstk_ms) +EXPLICIT_SYMBOL(___chkstk_ms) #endif #ifdef HAVE___MAIN - EXPLICIT_SYMBOL(__main) // FIXME: Don't call it. +EXPLICIT_SYMBOL(__main) // FIXME: Don't call it. #endif #ifdef HAVE___ASHLDI3 - EXPLICIT_SYMBOL(__ashldi3) +EXPLICIT_SYMBOL(__ashldi3) #endif #ifdef HAVE___ASHRDI3 - EXPLICIT_SYMBOL(__ashrdi3) +EXPLICIT_SYMBOL(__ashrdi3) #endif #ifdef HAVE___CMPDI2 // FIXME: unused - EXPLICIT_SYMBOL(__cmpdi2) +EXPLICIT_SYMBOL(__cmpdi2) #endif #ifdef HAVE___DIVDI3 - EXPLICIT_SYMBOL(__divdi3) +EXPLICIT_SYMBOL(__divdi3) #endif #ifdef HAVE___FIXDFDI - EXPLICIT_SYMBOL(__fixdfdi) +EXPLICIT_SYMBOL(__fixdfdi) #endif #ifdef HAVE___FIXSFDI - EXPLICIT_SYMBOL(__fixsfdi) +EXPLICIT_SYMBOL(__fixsfdi) #endif #ifdef HAVE___FIXUNSDFDI - EXPLICIT_SYMBOL(__fixunsdfdi) +EXPLICIT_SYMBOL(__fixunsdfdi) #endif #ifdef HAVE___FIXUNSSFDI - EXPLICIT_SYMBOL(__fixunssfdi) +EXPLICIT_SYMBOL(__fixunssfdi) #endif #ifdef HAVE___FLOATDIDF - EXPLICIT_SYMBOL(__floatdidf) +EXPLICIT_SYMBOL(__floatdidf) #endif #ifdef HAVE___FLOATDISF - EXPLICIT_SYMBOL(__floatdisf) +EXPLICIT_SYMBOL(__floatdisf) #endif #ifdef HAVE___LSHRDI3 - EXPLICIT_SYMBOL(__lshrdi3) +EXPLICIT_SYMBOL(__lshrdi3) #endif #ifdef HAVE___MODDI3 - EXPLICIT_SYMBOL(__moddi3) +EXPLICIT_SYMBOL(__moddi3) #endif #ifdef HAVE___UDIVDI3 - EXPLICIT_SYMBOL(__udivdi3) +EXPLICIT_SYMBOL(__udivdi3) #endif #ifdef HAVE___UMODDI3 - EXPLICIT_SYMBOL(__umoddi3) +EXPLICIT_SYMBOL(__umoddi3) #endif /* msvcrt */ #if defined(_MSC_VER) - EXPLICIT_SYMBOL2(alloca, _alloca_probe) +EXPLICIT_SYMBOL2(alloca, _alloca_probe) #ifdef _M_IX86 #define INLINE_DEF_FLOAT_SYMBOL(SYM, ARGC) INLINE_DEF_SYMBOL##ARGC(float, SYM) - INLINE_DEF_FLOAT_SYMBOL(acosf, 1) - INLINE_DEF_FLOAT_SYMBOL(asinf, 1) - INLINE_DEF_FLOAT_SYMBOL(atanf, 1) - INLINE_DEF_FLOAT_SYMBOL(atan2f, 2) - INLINE_DEF_FLOAT_SYMBOL(ceilf, 1) - INLINE_DEF_FLOAT_SYMBOL(cosf, 1) - INLINE_DEF_FLOAT_SYMBOL(coshf, 1) - INLINE_DEF_FLOAT_SYMBOL(expf, 1) - INLINE_DEF_FLOAT_SYMBOL(floorf, 1) - INLINE_DEF_FLOAT_SYMBOL(fmodf, 2) - INLINE_DEF_FLOAT_SYMBOL(logf, 1) - INLINE_DEF_FLOAT_SYMBOL(powf, 2) - INLINE_DEF_FLOAT_SYMBOL(sinf, 1) - INLINE_DEF_FLOAT_SYMBOL(sinhf, 1) - INLINE_DEF_FLOAT_SYMBOL(sqrtf, 1) - INLINE_DEF_FLOAT_SYMBOL(tanf, 1) - INLINE_DEF_FLOAT_SYMBOL(tanhf, 1) +INLINE_DEF_FLOAT_SYMBOL(acosf, 1) +INLINE_DEF_FLOAT_SYMBOL(asinf, 1) +INLINE_DEF_FLOAT_SYMBOL(atanf, 1) +INLINE_DEF_FLOAT_SYMBOL(atan2f, 2) +INLINE_DEF_FLOAT_SYMBOL(ceilf, 1) +INLINE_DEF_FLOAT_SYMBOL(cosf, 1) +INLINE_DEF_FLOAT_SYMBOL(coshf, 1) +INLINE_DEF_FLOAT_SYMBOL(expf, 1) +INLINE_DEF_FLOAT_SYMBOL(floorf, 1) +INLINE_DEF_FLOAT_SYMBOL(fmodf, 2) +INLINE_DEF_FLOAT_SYMBOL(logf, 1) +INLINE_DEF_FLOAT_SYMBOL(powf, 2) +INLINE_DEF_FLOAT_SYMBOL(sinf, 1) +INLINE_DEF_FLOAT_SYMBOL(sinhf, 1) +INLINE_DEF_FLOAT_SYMBOL(sqrtf, 1) +INLINE_DEF_FLOAT_SYMBOL(tanf, 1) +INLINE_DEF_FLOAT_SYMBOL(tanhf, 1) #undef INLINE_DEF_FLOAT_SYMBOL #endif