Index: lib/Support/raw_ostream.cpp =================================================================== --- lib/Support/raw_ostream.cpp +++ lib/Support/raw_ostream.cpp @@ -567,20 +567,34 @@ assert(FD >= 0 && "File already closed."); pos += Size; +#ifndef LLVM_ON_WIN32 + bool ShouldWriteInChunks = false; +#else + // PR25717: writing a large size of output to Windows console returns ENOMEM. + // Seems that WriteFile() is redirecting to WriteConsole() prior to Windows 8, + // and WriteConsole() has a size limit (66000 bytes or less, depending on + // heap usage). + bool ShouldWriteInChunks = !!::_isatty(FD); +#endif + do { ssize_t ret; + size_t ChunkSize = Size; + if (ChunkSize > 32767 && ShouldWriteInChunks) + ChunkSize = 32767; + // Check whether we should attempt to use atomic writes. if (LLVM_LIKELY(!UseAtomicWrites)) { - ret = ::write(FD, Ptr, Size); + ret = ::write(FD, Ptr, ChunkSize); } else { // Use ::writev() where available. #if defined(HAVE_WRITEV) const void *Addr = static_cast(Ptr); - struct iovec IOV = {const_cast(Addr), Size }; + struct iovec IOV = {const_cast(Addr), ChunkSize }; ret = ::writev(FD, &IOV, 1); #else - ret = ::write(FD, Ptr, Size); + ret = ::write(FD, Ptr, ChunkSize); #endif }