diff --git a/lld/include/lld/Core/LLVM.h b/lld/include/lld/Core/LLVM.h index 11ccf894c209..4f86a490d94b 100644 --- a/lld/include/lld/Core/LLVM.h +++ b/lld/include/lld/Core/LLVM.h @@ -28,7 +28,6 @@ namespace llvm { class Twine; class MemoryBuffer; template class ArrayRef; - template class OwningPtr; template class SmallString; template class SmallVector; template class SmallVectorImpl; @@ -63,7 +62,6 @@ namespace lld { using llvm::Twine; using llvm::MemoryBuffer; using llvm::ArrayRef; - using llvm::OwningPtr; using llvm::SmallString; using llvm::SmallVector; using llvm::SmallVectorImpl; diff --git a/lld/include/lld/Driver/CoreInputGraph.h b/lld/include/lld/Driver/CoreInputGraph.h index 9422505b7810..ee122978f8fc 100644 --- a/lld/include/lld/Driver/CoreInputGraph.h +++ b/lld/include/lld/Driver/CoreInputGraph.h @@ -20,9 +20,9 @@ #include "lld/Core/InputGraph.h" #include "lld/ReaderWriter/CoreLinkingContext.h" #include "lld/ReaderWriter/Reader.h" -#include "llvm/ADT/OwningPtr.h" #include +#include namespace lld { @@ -45,11 +45,10 @@ public: return make_error_code(llvm::errc::no_such_file_or_directory); // Create a memory buffer - OwningPtr opmb; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, opmb)) + std::unique_ptr mb; + if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, mb)) return ec; - std::unique_ptr mb(opmb.take()); _buffer = std::move(mb); return ctx.registry().parseFile(_buffer, _files); } diff --git a/lld/include/lld/ReaderWriter/LinkerScript.h b/lld/include/lld/ReaderWriter/LinkerScript.h index 7bc64af7015f..fc38f68c386c 100644 --- a/lld/include/lld/ReaderWriter/LinkerScript.h +++ b/lld/include/lld/ReaderWriter/LinkerScript.h @@ -18,7 +18,6 @@ #include "lld/Core/LLVM.h" #include "lld/Core/range.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/MemoryBuffer.h" @@ -26,6 +25,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" +#include #include namespace lld { diff --git a/lld/lib/Core/InputGraph.cpp b/lld/lib/Core/InputGraph.cpp index d6e619ac420e..b11e076ac5ec 100644 --- a/lld/lib/Core/InputGraph.cpp +++ b/lld/lib/Core/InputGraph.cpp @@ -10,7 +10,8 @@ #include "lld/Core/InputGraph.h" #include "lld/Core/Resolver.h" -#include "llvm/ADT/OwningPtr.h" + +#include using namespace lld; @@ -137,12 +138,11 @@ FileNode::FileNode(StringRef path, int64_t ordinal) /// \brief Read the file into _buffer. error_code FileNode::getBuffer(StringRef filePath) { // Create a memory buffer - OwningPtr opmb; + std::unique_ptr mb; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, opmb)) + if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, mb)) return ec; - std::unique_ptr mb(opmb.take()); _buffer = std::move(mb); return error_code::success(); diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 257a34890bb1..8f946a11557d 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -20,7 +20,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/Optional.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" @@ -34,6 +33,7 @@ #include #include #include +#include #include namespace lld { @@ -249,7 +249,7 @@ static bool parseSection(StringRef option, std::string §ion, static bool readFile(PECOFFLinkingContext &ctx, StringRef path, ArrayRef &result) { - OwningPtr buf; + std::unique_ptr buf; if (MemoryBuffer::getFile(path, buf)) return false; result = ctx.allocate(ArrayRef( @@ -351,10 +351,10 @@ static bool parseExport(StringRef option, // Read module-definition file. static llvm::Optional parseDef(StringRef option, llvm::BumpPtrAllocator &alloc) { - OwningPtr buf; + std::unique_ptr buf; if (MemoryBuffer::getFile(option, buf)) return llvm::None; - moduledef::Lexer lexer(std::unique_ptr(buf.take())); + moduledef::Lexer lexer(std::move(buf)); moduledef::Parser parser(lexer, alloc); return parser.parse(); } diff --git a/lld/lib/Passes/RoundTripNativePass.cpp b/lld/lib/Passes/RoundTripNativePass.cpp index 723f06a4320d..b58c9d6087fe 100644 --- a/lld/lib/Passes/RoundTripNativePass.cpp +++ b/lld/lib/Passes/RoundTripNativePass.cpp @@ -14,10 +14,11 @@ #include "lld/ReaderWriter/Simple.h" #include "lld/ReaderWriter/Writer.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Path.h" +#include + using namespace lld; /// Perform the actual pass @@ -36,11 +37,10 @@ void RoundTripNativePass::perform(std::unique_ptr &mergedFile) { // The file that is written would be kept around if there is a problem // writing to the file or when reading atoms back from the file. nativeWriter->writeFile(*mergedFile, tmpNativeFile.str()); - OwningPtr buff; - if (MemoryBuffer::getFile(tmpNativeFile.str(), buff)) + std::unique_ptr mb; + if (MemoryBuffer::getFile(tmpNativeFile.str(), mb)) return; - std::unique_ptr mb(buff.take()); error_code ec = _context.registry().parseFile(mb, _nativeFile); if (ec) { // Note: we need a way for Passes to report errors. diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp index 0212fa6eba3f..d5454fb1b616 100644 --- a/lld/lib/Passes/RoundTripYAMLPass.cpp +++ b/lld/lib/Passes/RoundTripYAMLPass.cpp @@ -13,10 +13,11 @@ #include "lld/ReaderWriter/Simple.h" #include "lld/ReaderWriter/Writer.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Path.h" +#include + // Skip YAML files larger than this to avoid OOM error. The YAML reader consumes // excessively large amount of memory when parsing a large file. // TODO: Fix the YAML reader to reduce memory footprint. @@ -40,12 +41,11 @@ void RoundTripYAMLPass::perform(std::unique_ptr &mergedFile) { // The file that is written would be kept around if there is a problem // writing to the file or when reading atoms back from the file. yamlWriter->writeFile(*mergedFile, tmpYAMLFile.str()); - OwningPtr buff; - if (MemoryBuffer::getFile(tmpYAMLFile.str(), buff)) + std::unique_ptr mb; + if (MemoryBuffer::getFile(tmpYAMLFile.str(), mb)) return; - if (buff->getBufferSize() < MAX_YAML_FILE_SIZE) { - std::unique_ptr mb(buff.take()); + if (mb->getBufferSize() < MAX_YAML_FILE_SIZE) { error_code ec = _context.registry().parseFile(mb, _yamlFile); if (ec) { // Note: we need a way for Passes to report errors. diff --git a/lld/lib/ReaderWriter/ELF/Chunk.h b/lld/lib/ReaderWriter/ELF/Chunk.h index f8d3ffbc9543..b306a3b291d9 100644 --- a/lld/lib/ReaderWriter/ELF/Chunk.h +++ b/lld/lib/ReaderWriter/ELF/Chunk.h @@ -12,7 +12,6 @@ #include "lld/Core/LLVM.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/ELF.h" #include "llvm/Support/Allocator.h" @@ -21,6 +20,8 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" +#include + namespace lld { class ELFLinkingContext; diff --git a/lld/lib/ReaderWriter/ELF/DefaultLayout.h b/lld/lib/ReaderWriter/ELF/DefaultLayout.h index f3dc886a6bc7..a6d959a0be9a 100644 --- a/lld/lib/ReaderWriter/ELF/DefaultLayout.h +++ b/lld/lib/ReaderWriter/ELF/DefaultLayout.h @@ -22,7 +22,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" @@ -31,6 +30,7 @@ #include "llvm/Support/Format.h" #include +#include #include #include diff --git a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h index f20321dcdd84..1d734808a306 100644 --- a/lld/lib/ReaderWriter/ELF/OutputELFWriter.h +++ b/lld/lib/ReaderWriter/ELF/OutputELFWriter.h @@ -429,7 +429,7 @@ template uint64_t OutputELFWriter::outputFileSize() const { template error_code OutputELFWriter::writeOutput(const File &file, StringRef path) { - OwningPtr buffer; + std::unique_ptr buffer; ScopedTask createOutputTask(getDefaultDomain(), "ELF Writer Create Output"); error_code ec = FileOutputBuffer::create(path, outputFileSize(), buffer, FileOutputBuffer::F_executable); diff --git a/lld/lib/ReaderWriter/ELF/SectionChunks.h b/lld/lib/ReaderWriter/ELF/SectionChunks.h index 267dbf4761ce..05b96ed5136b 100644 --- a/lld/lib/ReaderWriter/ELF/SectionChunks.h +++ b/lld/lib/ReaderWriter/ELF/SectionChunks.h @@ -21,7 +21,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Object/ELF.h" #include "llvm/Support/Allocator.h" @@ -31,6 +30,8 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" +#include + namespace lld { namespace elf { template class MergedSections; diff --git a/lld/lib/ReaderWriter/ELF/SegmentChunks.h b/lld/lib/ReaderWriter/ELF/SegmentChunks.h index 8e47499128b0..ee052551b19c 100644 --- a/lld/lib/ReaderWriter/ELF/SegmentChunks.h +++ b/lld/lib/ReaderWriter/ELF/SegmentChunks.h @@ -19,7 +19,6 @@ #include "lld/ReaderWriter/Writer.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/ELF.h" #include "llvm/Support/Allocator.h" @@ -27,6 +26,7 @@ #include "llvm/Support/ELF.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileOutputBuffer.h" +#include namespace lld { namespace elf { diff --git a/lld/lib/ReaderWriter/FileArchive.cpp b/lld/lib/ReaderWriter/FileArchive.cpp index a486ffb9c932..1749ed48d4e0 100644 --- a/lld/lib/ReaderWriter/FileArchive.cpp +++ b/lld/lib/ReaderWriter/FileArchive.cpp @@ -11,7 +11,6 @@ #include "lld/Core/LLVM.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" @@ -19,6 +18,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/MemoryBuffer.h" +#include #include #include @@ -51,10 +51,10 @@ public: return nullptr; if (dataSymbolOnly) { - OwningPtr buff; + std::unique_ptr buff; if (ci->getMemoryBuffer(buff, true)) return nullptr; - if (isDataSymbol(buff.take(), name)) + if (isDataSymbol(std::move(buff), name)) return nullptr; } @@ -101,20 +101,19 @@ protected: error_code instantiateMember(Archive::child_iterator member, std::vector> &result) const { - OwningPtr buff; - if (error_code ec = member->getMemoryBuffer(buff, true)) + std::unique_ptr mb; + if (error_code ec = member->getMemoryBuffer(mb, true)) return ec; if (_logLoading) - llvm::outs() << buff->getBufferIdentifier() << "\n"; - std::unique_ptr mb(buff.take()); + llvm::outs() << mb->getBufferIdentifier() << "\n"; _registry.parseFile(mb, result); const char *memberStart = member->getBuffer().data(); _membersInstantiated.insert(memberStart); return error_code::success(); } - error_code isDataSymbol(MemoryBuffer *mb, StringRef symbol) const { - auto objOrErr(ObjectFile::createObjectFile(mb)); + error_code isDataSymbol(std::unique_ptr mb, StringRef symbol) const { + auto objOrErr(ObjectFile::createObjectFile(mb.release())); if (auto ec = objOrErr.getError()) return ec; std::unique_ptr obj(objOrErr.get()); diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp index 7b0b501c3b0e..1ffb4294c926 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp @@ -933,7 +933,7 @@ error_code MachOFileLayout::writeBinary(StringRef path) { if (_ec) return _ec; // Create FileOutputBuffer with calculated size. - OwningPtr fob; + std::unique_ptr fob; unsigned flags = 0; if (_file.fileType != llvm::MachO::MH_OBJECT) flags = llvm::FileOutputBuffer::F_executable; diff --git a/lld/lib/ReaderWriter/Native/ReaderNative.cpp b/lld/lib/ReaderWriter/Native/ReaderNative.cpp index b6cd91ae0a7b..f338e81ea956 100644 --- a/lld/lib/ReaderWriter/Native/ReaderNative.cpp +++ b/lld/lib/ReaderWriter/Native/ReaderNative.cpp @@ -17,7 +17,6 @@ #include "lld/Core/File.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -369,7 +368,7 @@ public: } virtual ~File() { - // _buffer is automatically deleted because of OwningPtr<> + // _buffer is automatically deleted because of std::unique_ptr<> // All other ivar pointers are pointers into the MemoryBuffer, except // the _definedAtoms array which was allocated to contain an array diff --git a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp index d582e6dd2d59..8898746a78b6 100644 --- a/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp @@ -272,14 +272,14 @@ FileCOFF::FileCOFF(std::unique_ptr mb, error_code &ec) auto binaryOrErr = llvm::object::createBinary(mb.release()); if ((ec = binaryOrErr.getError())) return; - OwningPtr bin(binaryOrErr.get()); + std::unique_ptr bin(binaryOrErr.get()); _obj.reset(dyn_cast(bin.get())); if (!_obj) { ec = make_error_code(llvm::object::object_error::invalid_file_type); return; } - bin.take(); + bin.release(); // Read .drectve section if exists. ArrayRef directives; @@ -912,10 +912,9 @@ public: llvm::FileRemover coffFileRemover(*coffPath); // Read and parse the COFF - OwningPtr opmb; - if (error_code ec = MemoryBuffer::getFile(*coffPath, opmb)) + std::unique_ptr newmb; + if (error_code ec = MemoryBuffer::getFile(*coffPath, newmb)) return ec; - std::unique_ptr newmb(opmb.take()); error_code ec; std::unique_ptr file(new FileCOFF(std::move(newmb), ec)); if (ec) @@ -938,7 +937,7 @@ private: // Write the memory buffer contents to .res file, so that we can run // cvtres.exe on it. - OwningPtr buffer; + std::unique_ptr buffer; if (error_code ec = llvm::FileOutputBuffer::create( tempFilePath.str(), mb->getBufferSize(), buffer)) return ec; diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 54686c73cd09..6da91958bc39 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -1016,7 +1016,7 @@ error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) { } uint64_t totalSize = _chunks.back()->fileOffset() + _chunks.back()->size(); - OwningPtr buffer; + std::unique_ptr buffer; error_code ec = llvm::FileOutputBuffer::create( path, totalSize, buffer, llvm::FileOutputBuffer::F_executable); if (ec) diff --git a/lld/lib/ReaderWriter/Reader.cpp b/lld/lib/ReaderWriter/Reader.cpp index 16eb7a0fa4ed..54e3dae2c982 100644 --- a/lld/lib/ReaderWriter/Reader.cpp +++ b/lld/lib/ReaderWriter/Reader.cpp @@ -9,13 +9,14 @@ #include "lld/ReaderWriter/Reader.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/FileUtilities.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/system_error.h" +#include + namespace lld { Reader::~Reader() { diff --git a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp index 0a01d41aa95c..fe3cffdafe44 100644 --- a/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp +++ b/lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp @@ -20,7 +20,6 @@ #include "lld/Core/Reference.h" #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Debug.h" @@ -31,6 +30,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" +#include #include using llvm::yaml::MappingTraits; diff --git a/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp b/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp index 6c8b6d4013a7..36869c0ae563 100644 --- a/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp +++ b/lld/unittests/MachOTests/MachONormalizedFileBinaryWriterTests.cpp @@ -10,18 +10,17 @@ #include "gtest/gtest.h" #include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h" -#include #include #include #include #include #include +#include #include using llvm::StringRef; using llvm::MemoryBuffer; -using llvm::OwningPtr; using llvm::SmallString; using llvm::Twine; using llvm::ErrorOr; @@ -34,10 +33,8 @@ using namespace lld::mach_o::normalized; // Normalized file to nf parameter. static void fromBinary(StringRef path, std::unique_ptr &mb, std::unique_ptr &nf, StringRef archStr) { - OwningPtr opmb; - error_code ec = MemoryBuffer::getFile(path, opmb); + error_code ec = MemoryBuffer::getFile(path, mb); EXPECT_FALSE(ec); - mb.reset(opmb.take()); ErrorOr> r = lld::mach_o::normalized::readBinary( diff --git a/lld/utils/linker-script-test/linker-script-test.cpp b/lld/utils/linker-script-test/linker-script-test.cpp index 4df0ff95bc4f..8de19b6cb772 100644 --- a/lld/utils/linker-script-test/linker-script-test.cpp +++ b/lld/utils/linker-script-test/linker-script-test.cpp @@ -26,12 +26,12 @@ int main(int argc, const char **argv) { llvm::PrettyStackTraceProgram X(argc, argv); { - llvm::OwningPtr mb; + std::unique_ptr mb; if (error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) { llvm::errs() << ec.message() << "\n"; return 1; } - Lexer l(std::unique_ptr(mb.take())); + Lexer l(std::move(mb)); Token tok; while (true) { l.lex(tok); @@ -41,12 +41,12 @@ int main(int argc, const char **argv) { } } { - llvm::OwningPtr mb; + std::unique_ptr mb; if (error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) { llvm::errs() << ec.message() << "\n"; return 1; } - Lexer l(std::unique_ptr(mb.take())); + Lexer l(std::move(mb)); Parser p(l); LinkerScript *ls = p.parse(); if (ls)