diff options
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Support/FileCollector.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/FileOutputBuffer.cpp | 30 | ||||
-rw-r--r-- | llvm/lib/Support/KnownBits.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 48 | ||||
-rw-r--r-- | llvm/lib/Support/Path.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Support/Signals.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Support/Signposts.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/Support/TimeProfiler.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/Timer.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/ToolOutputFile.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Support/Triple.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/TypeSize.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 24 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 2 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 52 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Program.inc | 33 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/Signals.inc | 12 | ||||
-rw-r--r-- | llvm/lib/Support/X86TargetParser.cpp | 8 |
19 files changed, 193 insertions, 139 deletions
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 33caf5833728..ddacb4feaa0f 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -185,6 +185,7 @@ add_llvm_component_library(LLVMSupport TrigramIndex.cpp Triple.cpp Twine.cpp + TypeSize.cpp Unicode.cpp UnicodeCaseFold.cpp VersionTuple.cpp diff --git a/llvm/lib/Support/FileCollector.cpp b/llvm/lib/Support/FileCollector.cpp index 7d23d036fac2..5854baeebbb9 100644 --- a/llvm/lib/Support/FileCollector.cpp +++ b/llvm/lib/Support/FileCollector.cpp @@ -241,7 +241,7 @@ std::error_code FileCollector::writeMapping(StringRef MappingFile) { VFSWriter.setUseExternalNames(false); std::error_code EC; - raw_fd_ostream os(MappingFile, EC, sys::fs::OF_Text); + raw_fd_ostream os(MappingFile, EC, sys::fs::OF_TextWithCRLF); if (EC) return EC; diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp index 3342682270dc..4b4406c4c9f4 100644 --- a/llvm/lib/Support/FileOutputBuffer.cpp +++ b/llvm/lib/Support/FileOutputBuffer.cpp @@ -33,21 +33,20 @@ namespace { // with the temporary file on commit(). class OnDiskBuffer : public FileOutputBuffer { public: - OnDiskBuffer(StringRef Path, fs::TempFile Temp, - std::unique_ptr<fs::mapped_file_region> Buf) + OnDiskBuffer(StringRef Path, fs::TempFile Temp, fs::mapped_file_region Buf) : FileOutputBuffer(Path), Buffer(std::move(Buf)), Temp(std::move(Temp)) {} - uint8_t *getBufferStart() const override { return (uint8_t *)Buffer->data(); } + uint8_t *getBufferStart() const override { return (uint8_t *)Buffer.data(); } uint8_t *getBufferEnd() const override { - return (uint8_t *)Buffer->data() + Buffer->size(); + return (uint8_t *)Buffer.data() + Buffer.size(); } - size_t getBufferSize() const override { return Buffer->size(); } + size_t getBufferSize() const override { return Buffer.size(); } Error commit() override { // Unmap buffer, letting OS flush dirty pages to file on disk. - Buffer.reset(); + Buffer.unmap(); // Atomically replace the existing file with the new one. return Temp.keep(FinalPath); @@ -56,7 +55,7 @@ public: ~OnDiskBuffer() override { // Close the mapping before deleting the temp file, so that the removal // succeeds. - Buffer.reset(); + Buffer.unmap(); consumeError(Temp.discard()); } @@ -67,7 +66,7 @@ public: } private: - std::unique_ptr<fs::mapped_file_region> Buffer; + fs::mapped_file_region Buffer; fs::TempFile Temp; }; @@ -132,23 +131,16 @@ createOnDiskBuffer(StringRef Path, size_t Size, unsigned Mode) { return FileOrErr.takeError(); fs::TempFile File = std::move(*FileOrErr); -#ifndef _WIN32 - // On Windows, CreateFileMapping (the mmap function on Windows) - // automatically extends the underlying file. We don't need to - // extend the file beforehand. _chsize (ftruncate on Windows) is - // pretty slow just like it writes specified amount of bytes, - // so we should avoid calling that function. - if (auto EC = fs::resize_file(File.FD, Size)) { + if (auto EC = fs::resize_file_before_mapping_readwrite(File.FD, Size)) { consumeError(File.discard()); return errorCodeToError(EC); } -#endif // Mmap it. std::error_code EC; - auto MappedFile = std::make_unique<fs::mapped_file_region>( - fs::convertFDToNativeFile(File.FD), fs::mapped_file_region::readwrite, - Size, 0, EC); + fs::mapped_file_region MappedFile = + fs::mapped_file_region(fs::convertFDToNativeFile(File.FD), + fs::mapped_file_region::readwrite, Size, 0, EC); // mmap(2) can fail if the underlying filesystem does not support it. // If that happens, we fall back to in-memory buffer as the last resort. diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp index 423a908eed57..d997bd85f1e0 100644 --- a/llvm/lib/Support/KnownBits.cpp +++ b/llvm/lib/Support/KnownBits.cpp @@ -12,6 +12,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/KnownBits.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" #include <cassert> using namespace llvm; @@ -410,10 +412,11 @@ KnownBits KnownBits::abs(bool IntMinIsPoison) const { return KnownAbs; } -KnownBits KnownBits::computeForMul(const KnownBits &LHS, const KnownBits &RHS) { +KnownBits KnownBits::mul(const KnownBits &LHS, const KnownBits &RHS) { unsigned BitWidth = LHS.getBitWidth(); + assert(BitWidth == RHS.getBitWidth() && !LHS.hasConflict() && + !RHS.hasConflict() && "Operand mismatch"); - assert(!LHS.hasConflict() && !RHS.hasConflict()); // Compute a conservative estimate for high known-0 bits. unsigned LeadZ = std::max(LHS.countMinLeadingZeros() + RHS.countMinLeadingZeros(), @@ -495,7 +498,7 @@ KnownBits KnownBits::mulhs(const KnownBits &LHS, const KnownBits &RHS) { !RHS.hasConflict() && "Operand mismatch"); KnownBits WideLHS = LHS.sext(2 * BitWidth); KnownBits WideRHS = RHS.sext(2 * BitWidth); - return computeForMul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth); + return mul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth); } KnownBits KnownBits::mulhu(const KnownBits &LHS, const KnownBits &RHS) { @@ -504,7 +507,7 @@ KnownBits KnownBits::mulhu(const KnownBits &LHS, const KnownBits &RHS) { !RHS.hasConflict() && "Operand mismatch"); KnownBits WideLHS = LHS.zext(2 * BitWidth); KnownBits WideRHS = RHS.zext(2 * BitWidth); - return computeForMul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth); + return mul(WideLHS, WideRHS).extractBits(BitWidth, BitWidth); } KnownBits KnownBits::udiv(const KnownBits &LHS, const KnownBits &RHS) { @@ -601,3 +604,11 @@ KnownBits &KnownBits::operator^=(const KnownBits &RHS) { Zero = std::move(Z); return *this; } + +void KnownBits::print(raw_ostream &OS) const { + OS << "{Zero=" << Zero << ", One=" << One << "}"; +} +void KnownBits::dump() const { + print(dbgs()); + dbgs() << "\n"; +} diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index 955bf113fd79..dbdf41f255eb 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -105,9 +105,8 @@ public: template <typename MB> static ErrorOr<std::unique_ptr<MB>> -getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText); +getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, + bool IsText, bool RequiresNullTerminator, bool IsVolatile); std::unique_ptr<MemoryBuffer> MemoryBuffer::getMemBuffer(StringRef InputData, StringRef BufferName, @@ -141,21 +140,22 @@ MemoryBuffer::getMemBufferCopy(StringRef InputData, const Twine &BufferName) { } ErrorOr<std::unique_ptr<MemoryBuffer>> -MemoryBuffer::getFileOrSTDIN(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsText) { +MemoryBuffer::getFileOrSTDIN(const Twine &Filename, bool IsText, + bool RequiresNullTerminator) { SmallString<256> NameBuf; StringRef NameRef = Filename.toStringRef(NameBuf); if (NameRef == "-") return getSTDIN(); - return getFile(Filename, FileSize, RequiresNullTerminator, false, IsText); + return getFile(Filename, IsText, RequiresNullTerminator, + /*IsVolatile=*/false); } ErrorOr<std::unique_ptr<MemoryBuffer>> MemoryBuffer::getFileSlice(const Twine &FilePath, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { - return getFileAux<MemoryBuffer>(FilePath, -1, MapSize, Offset, false, - IsVolatile, false); + return getFileAux<MemoryBuffer>(FilePath, MapSize, Offset, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } //===----------------------------------------------------------------------===// @@ -242,11 +242,10 @@ getMemoryBufferForStream(sys::fs::file_t FD, const Twine &BufferName) { } ErrorOr<std::unique_ptr<MemoryBuffer>> -MemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, - bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { - return getFileAux<MemoryBuffer>(Filename, FileSize, FileSize, 0, - RequiresNullTerminator, IsVolatile, IsText); +MemoryBuffer::getFile(const Twine &Filename, bool IsText, + bool RequiresNullTerminator, bool IsVolatile) { + return getFileAux<MemoryBuffer>(Filename, /*MapSize=*/-1, /*Offset=*/0, + IsText, RequiresNullTerminator, IsVolatile); } template <typename MB> @@ -257,33 +256,32 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, template <typename MB> static ErrorOr<std::unique_ptr<MB>> -getFileAux(const Twine &Filename, int64_t FileSize, uint64_t MapSize, - uint64_t Offset, bool RequiresNullTerminator, bool IsVolatile, - bool IsText) { +getFileAux(const Twine &Filename, uint64_t MapSize, uint64_t Offset, + bool IsText, bool RequiresNullTerminator, bool IsVolatile) { Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForRead( - Filename, IsText ? sys::fs::OF_Text : sys::fs::OF_None); + Filename, IsText ? sys::fs::OF_TextWithCRLF : sys::fs::OF_None); if (!FDOrErr) return errorToErrorCode(FDOrErr.takeError()); sys::fs::file_t FD = *FDOrErr; - auto Ret = getOpenFileImpl<MB>(FD, Filename, FileSize, MapSize, Offset, + auto Ret = getOpenFileImpl<MB>(FD, Filename, /*FileSize=*/-1, MapSize, Offset, RequiresNullTerminator, IsVolatile); sys::fs::closeFile(FD); return Ret; } ErrorOr<std::unique_ptr<WritableMemoryBuffer>> -WritableMemoryBuffer::getFile(const Twine &Filename, int64_t FileSize, - bool IsVolatile) { - return getFileAux<WritableMemoryBuffer>(Filename, FileSize, FileSize, 0, - /*RequiresNullTerminator*/ false, - IsVolatile, false); +WritableMemoryBuffer::getFile(const Twine &Filename, bool IsVolatile) { + return getFileAux<WritableMemoryBuffer>( + Filename, /*MapSize=*/-1, /*Offset=*/0, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } ErrorOr<std::unique_ptr<WritableMemoryBuffer>> WritableMemoryBuffer::getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset, bool IsVolatile) { - return getFileAux<WritableMemoryBuffer>(Filename, -1, MapSize, Offset, false, - IsVolatile, false); + return getFileAux<WritableMemoryBuffer>( + Filename, MapSize, Offset, /*IsText=*/false, + /*RequiresNullTerminator=*/false, IsVolatile); } std::unique_ptr<WritableMemoryBuffer> diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index f49affb3fa99..005c27c3a42a 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -1152,6 +1152,21 @@ ErrorOr<perms> getPermissions(const Twine &Path) { return Status.permissions(); } +size_t mapped_file_region::size() const { + assert(Mapping && "Mapping failed but used anyway!"); + return Size; +} + +char *mapped_file_region::data() const { + assert(Mapping && "Mapping failed but used anyway!"); + return reinterpret_cast<char *>(Mapping); +} + +const char *mapped_file_region::const_data() const { + assert(Mapping && "Mapping failed but used anyway!"); + return reinterpret_cast<const char *>(Mapping); +} + } // end namespace fs } // end namespace sys } // end namespace llvm diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp index 29be4df95954..5aa1a9efcf59 100644 --- a/llvm/lib/Support/Signals.cpp +++ b/llvm/lib/Support/Signals.cpp @@ -43,6 +43,11 @@ static cl::opt<bool, true> DisableSymbolication("disable-symbolication", cl::desc("Disable symbolizing crash backtraces."), cl::location(DisableSymbolicationFlag), cl::Hidden); +static std::string CrashDiagnosticsDirectory; +static cl::opt<std::string, true> + CrashDiagnosticsDir("crash-diagnostics-dir", cl::value_desc("directory"), + cl::desc("Directory for crash diagnostic files."), + cl::location(CrashDiagnosticsDirectory), cl::Hidden); constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION"; constexpr char LLVMSymbolizerPathEnv[] = "LLVM_SYMBOLIZER_PATH"; diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp index eefd61f43b44..37e16a99f46b 100644 --- a/llvm/lib/Support/Signposts.cpp +++ b/llvm/lib/Support/Signposts.cpp @@ -29,15 +29,17 @@ os_log_t *LogCreator() { *X = os_log_create("org.llvm.signposts", OS_LOG_CATEGORY_POINTS_OF_INTEREST); return X; } -void LogDeleter(os_log_t *X) { - os_release(*X); - delete X; -} +struct LogDeleter { + void operator()(os_log_t *X) const { + os_release(*X); + delete X; + } +}; } // end anonymous namespace namespace llvm { class SignpostEmitterImpl { - using LogPtrTy = std::unique_ptr<os_log_t, std::function<void(os_log_t *)>>; + using LogPtrTy = std::unique_ptr<os_log_t, LogDeleter>; using LogTy = LogPtrTy::element_type; LogPtrTy SignpostLog; @@ -59,7 +61,7 @@ class SignpostEmitterImpl { } public: - SignpostEmitterImpl() : SignpostLog(LogCreator(), LogDeleter), Signposts() {} + SignpostEmitterImpl() : SignpostLog(LogCreator()) {} bool isEnabled() const { if (SIGNPOSTS_AVAILABLE()) @@ -88,6 +90,9 @@ public: } }; } // end namespace llvm +#else +/// Definition necessary for use of std::unique_ptr in SignpostEmitter::Impl. +class llvm::SignpostEmitterImpl {}; #endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS #if LLVM_SUPPORT_XCODE_SIGNPOSTS @@ -98,17 +103,11 @@ public: SignpostEmitter::SignpostEmitter() { #if HAVE_ANY_SIGNPOST_IMPL - Impl = new SignpostEmitterImpl(); -#else // if HAVE_ANY_SIGNPOST_IMPL - Impl = nullptr; + Impl = std::make_unique<SignpostEmitterImpl>(); #endif // if !HAVE_ANY_SIGNPOST_IMPL } -SignpostEmitter::~SignpostEmitter() { -#if HAVE_ANY_SIGNPOST_IMPL - delete Impl; -#endif // if HAVE_ANY_SIGNPOST_IMPL -} +SignpostEmitter::~SignpostEmitter() = default; bool SignpostEmitter::isEnabled() const { #if HAVE_ANY_SIGNPOST_IMPL diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index 93bf6f57e348..c37c74c61f3c 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -304,7 +304,7 @@ Error llvm::timeTraceProfilerWrite(StringRef PreferredFileName, } std::error_code EC; - raw_fd_ostream OS(Path, EC, sys::fs::OF_Text); + raw_fd_ostream OS(Path, EC, sys::fs::OF_TextWithCRLF); if (EC) return createStringError(EC, "Could not open " + Path); diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index a959cf35ec21..6e592dbc0ba1 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -82,7 +82,7 @@ std::unique_ptr<raw_fd_ostream> llvm::CreateInfoOutputFile() { // info output file before running commands which write to it. std::error_code EC; auto Result = std::make_unique<raw_fd_ostream>( - OutputFilename, EC, sys::fs::OF_Append | sys::fs::OF_Text); + OutputFilename, EC, sys::fs::OF_Append | sys::fs::OF_TextWithCRLF); if (!EC) return Result; diff --git a/llvm/lib/Support/ToolOutputFile.cpp b/llvm/lib/Support/ToolOutputFile.cpp index 3735aac79e2f..c192ce60f31c 100644 --- a/llvm/lib/Support/ToolOutputFile.cpp +++ b/llvm/lib/Support/ToolOutputFile.cpp @@ -46,12 +46,7 @@ ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC, EC = std::error_code(); return; } - - // On Windows, we set the OF_None flag even for text files to avoid - // CRLF translation. - OSHolder.emplace( - Filename, EC, - llvm::Triple(LLVM_HOST_TRIPLE).isOSWindows() ? sys::fs::OF_None : Flags); + OSHolder.emplace(Filename, EC, Flags); OS = OSHolder.getPointer(); // If open fails, no cleanup is needed. if (EC) diff --git a/llvm/lib/Support/Triple.cpp b/llvm/lib/Support/Triple.cpp index e5dd32fb5827..3c2182ecb09a 100644 --- a/llvm/lib/Support/Triple.cpp +++ b/llvm/lib/Support/Triple.cpp @@ -250,6 +250,7 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) { case Musl: return "musl"; case MuslEABI: return "musleabi"; case MuslEABIHF: return "musleabihf"; + case MuslX32: return "muslx32"; case Simulator: return "simulator"; } @@ -555,6 +556,7 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) { .StartsWith("android", Triple::Android) .StartsWith("musleabihf", Triple::MuslEABIHF) .StartsWith("musleabi", Triple::MuslEABI) + .StartsWith("muslx32", Triple::MuslX32) .StartsWith("musl", Triple::Musl) .StartsWith("msvc", Triple::MSVC) .StartsWith("itanium", Triple::Itanium) diff --git a/llvm/lib/Support/TypeSize.cpp b/llvm/lib/Support/TypeSize.cpp new file mode 100644 index 000000000000..83d40d9cb0ed --- /dev/null +++ b/llvm/lib/Support/TypeSize.cpp @@ -0,0 +1,41 @@ +//===- TypeSize.cpp - Wrapper around type sizes------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/TypeSize.h" +#include "llvm/Support/CommandLine.h" + +using namespace llvm; + +/// The ScalableErrorAsWarning is a temporary measure to suppress errors from +/// using the wrong interface on a scalable vector. +cl::opt<bool> ScalableErrorAsWarning( + "treat-scalable-fixed-error-as-warning", cl::Hidden, cl::init(false), + cl::desc("Treat issues where a fixed-width property is requested from a " + "scalable type as a warning, instead of an error."), + cl::ZeroOrMore); + +void llvm::reportInvalidSizeRequest(const char *Msg) { +#ifndef STRICT_FIXED_SIZE_VECTORS + if (ScalableErrorAsWarning) { + WithColor::warning() << "Invalid size request on a scalable vector; " << Msg + << "\n"; + return; + } +#endif + report_fatal_error("Invalid size request on a scalable vector."); +} + +TypeSize::operator TypeSize::ScalarTy() const { + if (isScalable()) { + reportInvalidSizeRequest( + "Cannot implicitly convert a scalable size to a fixed-width size in " + "`TypeSize::operator ScalarTy()`"); + return getKnownMinValue(); + } + return getFixedValue(); +} diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index bbac8a5b3733..56ed17e364e8 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -815,6 +815,9 @@ std::error_code mapped_file_region::init(int FD, uint64_t Offset, int flags = (Mode == readwrite) ? MAP_SHARED : MAP_PRIVATE; int prot = (Mode == readonly) ? PROT_READ : (PROT_READ | PROT_WRITE); +#if defined(MAP_NORESERVE) + flags |= MAP_NORESERVE; +#endif #if defined(__APPLE__) //---------------------------------------------------------------------- // Newer versions of MacOSX have a flag that will allow us to read from @@ -843,33 +846,18 @@ std::error_code mapped_file_region::init(int FD, uint64_t Offset, mapped_file_region::mapped_file_region(int fd, mapmode mode, size_t length, uint64_t offset, std::error_code &ec) - : Size(length), Mapping(), Mode(mode) { + : Size(length), Mode(mode) { (void)Mode; ec = init(fd, offset, mode); if (ec) - Mapping = nullptr; + copyFrom(mapped_file_region()); } -mapped_file_region::~mapped_file_region() { +void mapped_file_region::unmapImpl() { if (Mapping) ::munmap(Mapping, Size); } -size_t mapped_file_region::size() const { - assert(Mapping && "Mapping failed but used anyway!"); - return Size; -} - -char *mapped_file_region::data() const { - assert(Mapping && "Mapping failed but used anyway!"); - return reinterpret_cast<char*>(Mapping); -} - -const char *mapped_file_region::const_data() const { - assert(Mapping && "Mapping failed but used anyway!"); - return reinterpret_cast<const char*>(Mapping); -} - int mapped_file_region::alignment() { return Process::getPageSizeEstimate(); } diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 679ba536c99e..3f18d89fbdef 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -507,7 +507,7 @@ std::error_code 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_Text); + llvm::raw_fd_ostream OS(FileName, EC, llvm::sys::fs::OpenFlags::OF_TextWithCRLF); if (EC) return EC; diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index dc9bcf868381..19b9f9ef7cbc 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -402,8 +402,22 @@ std::error_code is_local(int FD, bool &Result) { } static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) { - // First, check if the file is on a network (non-local) drive. If so, don't - // set DeleteFile to true, since it prevents opening the file for writes. + // Clear the FILE_DISPOSITION_INFO flag first, before checking if it's a + // network file. On Windows 7 the function realPathFromHandle() below fails + // if the FILE_DISPOSITION_INFO flag was already set to 'DeleteFile = true' by + // a prior call. + FILE_DISPOSITION_INFO Disposition; + Disposition.DeleteFile = false; + if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition, + sizeof(Disposition))) + return mapWindowsError(::GetLastError()); + if (!Delete) + return std::error_code(); + + // Check if the file is on a network (non-local) drive. If so, don't + // continue when DeleteFile is true, since it prevents opening the file for + // writes. Note -- this will leak temporary files on disk, but only when the + // target file is on a network drive. SmallVector<wchar_t, 128> FinalPath; if (std::error_code EC = realPathFromHandle(Handle, FinalPath)) return EC; @@ -415,9 +429,9 @@ static std::error_code setDeleteDisposition(HANDLE Handle, bool Delete) { if (!IsLocal) return std::error_code(); - // The file is on a local drive, set the DeleteFile to true. - FILE_DISPOSITION_INFO Disposition; - Disposition.DeleteFile = Delete; + // The file is on a local drive, we can safely set FILE_DISPOSITION_INFO's + // flag. + Disposition.DeleteFile = true; if (!SetFileInformationByHandle(Handle, FileDispositionInfo, &Disposition, sizeof(Disposition))) return mapWindowsError(::GetLastError()); @@ -609,6 +623,9 @@ std::error_code access(const Twine &Path, AccessMode Mode) { if (Mode == AccessMode::Write && (Attributes & FILE_ATTRIBUTE_READONLY)) return errc::permission_denied; + if (Mode == AccessMode::Execute && (Attributes & FILE_ATTRIBUTE_DIRECTORY)) + return errc::permission_denied; + return std::error_code(); } @@ -886,10 +903,10 @@ std::error_code mapped_file_region::init(sys::fs::file_t OrigFileHandle, mapped_file_region::mapped_file_region(sys::fs::file_t fd, mapmode mode, size_t length, uint64_t offset, std::error_code &ec) - : Size(length), Mapping() { + : Size(length) { ec = init(fd, offset, mode); if (ec) - Mapping = 0; + copyFrom(mapped_file_region()); } static bool hasFlushBufferKernelBug() { @@ -908,7 +925,7 @@ static bool isEXE(StringRef Magic) { return false; } -mapped_file_region::~mapped_file_region() { +void mapped_file_region::unmapImpl() { if (Mapping) { bool Exe = isEXE(StringRef((char *)Mapping, Size)); @@ -930,21 +947,6 @@ mapped_file_region::~mapped_file_region() { } } -size_t mapped_file_region::size() const { - assert(Mapping && "Mapping failed but used anyway!"); - return Size; -} - -char *mapped_file_region::data() const { - assert(Mapping && "Mapping failed but used anyway!"); - return reinterpret_cast<char*>(Mapping); -} - -const char *mapped_file_region::const_data() const { - assert(Mapping && "Mapping failed but used anyway!"); - return reinterpret_cast<const char*>(Mapping); -} - int mapped_file_region::alignment() { SYSTEM_INFO SysInfo; ::GetSystemInfo(&SysInfo); @@ -1066,8 +1068,10 @@ static std::error_code nativeFileToFd(Expected<HANDLE> H, int &ResultFD, if (Flags & OF_Append) CrtOpenFlags |= _O_APPEND; - if (Flags & OF_Text) + if (Flags & OF_CRLF) { + assert(Flags & OF_Text && "Flags set OF_CRLF without OF_Text"); CrtOpenFlags |= _O_TEXT; + } ResultFD = -1; if (!H) diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc index f1d612cf3c98..92a607180c35 100644 --- a/llvm/lib/Support/Windows/Program.inc +++ b/llvm/lib/Support/Windows/Program.inc @@ -67,13 +67,10 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, if (const char *PathExtEnv = std::getenv("PATHEXT")) SplitString(PathExtEnv, PathExts, ";"); - SmallVector<wchar_t, MAX_PATH> U16Result; - DWORD Len = MAX_PATH; + SmallVector<char, MAX_PATH> U8Result; for (StringRef Ext : PathExts) { - SmallVector<wchar_t, MAX_PATH> U16Ext; - if (std::error_code EC = windows::UTF8ToUTF16(Ext, U16Ext)) - return EC; - + SmallVector<wchar_t, MAX_PATH> U16Result; + DWORD Len = MAX_PATH; do { U16Result.reserve(Len); // Lets attach the extension manually. That is needed for files @@ -88,20 +85,24 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, U16Result.capacity(), U16Result.data(), nullptr); } while (Len > U16Result.capacity()); - if (Len != 0) + if (Len == 0) + continue; + + U16Result.set_size(Len); + + if (std::error_code EC = + windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result)) + return EC; + + if (sys::fs::can_execute(U8Result)) break; // Found it. + + U8Result.clear(); } - if (Len == 0) + if (U8Result.empty()) return mapWindowsError(::GetLastError()); - U16Result.set_size(Len); - - SmallVector<char, MAX_PATH> U8Result; - if (std::error_code EC = - windows::UTF16ToUTF8(U16Result.data(), U16Result.size(), U8Result)) - return EC; - return std::string(U8Result.begin(), U8Result.end()); } @@ -505,7 +506,7 @@ std::error_code llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents, WindowsEncodingMethod Encoding) { std::error_code EC; - llvm::raw_fd_ostream OS(FileName, EC, llvm::sys::fs::OF_Text); + llvm::raw_fd_ostream OS(FileName, EC, llvm::sys::fs::OF_TextWithCRLF); if (EC) return EC; diff --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc index 3758582b35f7..df5fcb1b151b 100644 --- a/llvm/lib/Support/Windows/Signals.inc +++ b/llvm/lib/Support/Windows/Signals.inc @@ -766,16 +766,18 @@ WriteWindowsDumpFile(PMINIDUMP_EXCEPTION_INFORMATION ExceptionInfo) { if (!GetDumpType(DefaultLocalDumpsKey, DumpType)) DumpType = MiniDumpNormal; - // Look to see if a dump location is specified in the registry; first with the + // Look to see if a dump location is specified on the command line. If not, + // look to see if a dump location is specified in the registry; first with the // app-specific key and failing that with the global key. If none are found // we'll just create the dump file in the default temporary file location // (GetDumpFolder will return false either if the key is NULL or if there is // no valid DumpFolder value at its location). bool ExplicitDumpDirectorySet = true; - SmallString<MAX_PATH> DumpDirectory; - if (!GetDumpFolder(AppSpecificKey, DumpDirectory)) - if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory)) - ExplicitDumpDirectorySet = false; + SmallString<MAX_PATH> DumpDirectory(CrashDiagnosticsDirectory); + if (DumpDirectory.empty()) + if (!GetDumpFolder(AppSpecificKey, DumpDirectory)) + if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory)) + ExplicitDumpDirectorySet = false; int FD; SmallString<MAX_PATH> DumpPath; diff --git a/llvm/lib/Support/X86TargetParser.cpp b/llvm/lib/Support/X86TargetParser.cpp index 6355fd12c067..34e4798a0040 100644 --- a/llvm/lib/Support/X86TargetParser.cpp +++ b/llvm/lib/Support/X86TargetParser.cpp @@ -192,13 +192,13 @@ constexpr FeatureBitset FeaturesCannonlake = FeaturePKU | FeatureSHA; constexpr FeatureBitset FeaturesICLClient = FeaturesCannonlake | FeatureAVX512BITALG | FeatureAVX512VBMI2 | - FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureCLWB | FeatureGFNI | - FeatureRDPID | FeatureVAES | FeatureVPCLMULQDQ; + FeatureAVX512VNNI | FeatureAVX512VPOPCNTDQ | FeatureGFNI | FeatureRDPID | + FeatureVAES | FeatureVPCLMULQDQ; constexpr FeatureBitset FeaturesICLServer = - FeaturesICLClient | FeaturePCONFIG | FeatureWBNOINVD; + FeaturesICLClient | FeatureCLWB | FeaturePCONFIG | FeatureWBNOINVD; constexpr FeatureBitset FeaturesTigerlake = FeaturesICLClient | FeatureAVX512VP2INTERSECT | FeatureMOVDIR64B | - FeatureMOVDIRI | FeatureSHSTK | FeatureKL | FeatureWIDEKL; + FeatureCLWB | FeatureMOVDIRI | FeatureSHSTK | FeatureKL | FeatureWIDEKL; constexpr FeatureBitset FeaturesSapphireRapids = FeaturesICLServer | FeatureAMX_TILE | FeatureAMX_INT8 | FeatureAMX_BF16 | FeatureAVX512BF16 | FeatureAVX512VP2INTERSECT | FeatureCLDEMOTE | |