forked from OSchip/llvm-project
Replace OwningPtr with std::unique_ptr.
This results in some simplifications to the code where an OwningPtr had to be used with the previous api and then ownership moved to a unique_ptr for the rest of lld. llvm-svn: 203809
This commit is contained in:
parent
445a939db8
commit
13c70b6d4b
|
@ -28,7 +28,6 @@ namespace llvm {
|
|||
class Twine;
|
||||
class MemoryBuffer;
|
||||
template<typename T> class ArrayRef;
|
||||
template<class T> class OwningPtr;
|
||||
template<unsigned InternalLen> class SmallString;
|
||||
template<typename T, unsigned N> class SmallVector;
|
||||
template<typename T> 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;
|
||||
|
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
|
||||
namespace lld {
|
||||
|
||||
|
@ -45,11 +45,10 @@ public:
|
|||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
||||
|
||||
// Create a memory buffer
|
||||
OwningPtr<MemoryBuffer> opmb;
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, opmb))
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(*filePath, mb))
|
||||
return ec;
|
||||
|
||||
std::unique_ptr<MemoryBuffer> mb(opmb.take());
|
||||
_buffer = std::move(mb);
|
||||
return ctx.registry().parseFile(_buffer, _files);
|
||||
}
|
||||
|
|
|
@ -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 <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace lld {
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include "lld/Core/InputGraph.h"
|
||||
|
||||
#include "lld/Core/Resolver.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<MemoryBuffer> opmb;
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, opmb))
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(filePath, mb))
|
||||
return ec;
|
||||
|
||||
std::unique_ptr<MemoryBuffer> mb(opmb.take());
|
||||
_buffer = std::move(mb);
|
||||
|
||||
return error_code::success();
|
||||
|
|
|
@ -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 <algorithm>
|
||||
#include <cctype>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
namespace lld {
|
||||
|
@ -249,7 +249,7 @@ static bool parseSection(StringRef option, std::string §ion,
|
|||
|
||||
static bool readFile(PECOFFLinkingContext &ctx, StringRef path,
|
||||
ArrayRef<uint8_t> &result) {
|
||||
OwningPtr<MemoryBuffer> buf;
|
||||
std::unique_ptr<MemoryBuffer> buf;
|
||||
if (MemoryBuffer::getFile(path, buf))
|
||||
return false;
|
||||
result = ctx.allocate(ArrayRef<uint8_t>(
|
||||
|
@ -351,10 +351,10 @@ static bool parseExport(StringRef option,
|
|||
// Read module-definition file.
|
||||
static llvm::Optional<moduledef::Directive *>
|
||||
parseDef(StringRef option, llvm::BumpPtrAllocator &alloc) {
|
||||
OwningPtr<MemoryBuffer> buf;
|
||||
std::unique_ptr<MemoryBuffer> buf;
|
||||
if (MemoryBuffer::getFile(option, buf))
|
||||
return llvm::None;
|
||||
moduledef::Lexer lexer(std::unique_ptr<MemoryBuffer>(buf.take()));
|
||||
moduledef::Lexer lexer(std::move(buf));
|
||||
moduledef::Parser parser(lexer, alloc);
|
||||
return parser.parse();
|
||||
}
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
using namespace lld;
|
||||
|
||||
/// Perform the actual pass
|
||||
|
@ -36,11 +37,10 @@ void RoundTripNativePass::perform(std::unique_ptr<MutableFile> &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<MemoryBuffer> buff;
|
||||
if (MemoryBuffer::getFile(tmpNativeFile.str(), buff))
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (MemoryBuffer::getFile(tmpNativeFile.str(), mb))
|
||||
return;
|
||||
|
||||
std::unique_ptr<MemoryBuffer> mb(buff.take());
|
||||
error_code ec = _context.registry().parseFile(mb, _nativeFile);
|
||||
if (ec) {
|
||||
// Note: we need a way for Passes to report errors.
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
// 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<MutableFile> &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<MemoryBuffer> buff;
|
||||
if (MemoryBuffer::getFile(tmpYAMLFile.str(), buff))
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (MemoryBuffer::getFile(tmpYAMLFile.str(), mb))
|
||||
return;
|
||||
|
||||
if (buff->getBufferSize() < MAX_YAML_FILE_SIZE) {
|
||||
std::unique_ptr<MemoryBuffer> 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.
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
namespace lld {
|
||||
class ELFLinkingContext;
|
||||
|
||||
|
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
|
||||
|
|
|
@ -429,7 +429,7 @@ template <class ELFT> uint64_t OutputELFWriter<ELFT>::outputFileSize() const {
|
|||
template <class ELFT>
|
||||
error_code OutputELFWriter<ELFT>::writeOutput(const File &file,
|
||||
StringRef path) {
|
||||
OwningPtr<FileOutputBuffer> buffer;
|
||||
std::unique_ptr<FileOutputBuffer> buffer;
|
||||
ScopedTask createOutputTask(getDefaultDomain(), "ELF Writer Create Output");
|
||||
error_code ec = FileOutputBuffer::create(path, outputFileSize(), buffer,
|
||||
FileOutputBuffer::F_executable);
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
template <class> class MergedSections;
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
|
|
@ -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 <memory>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -51,10 +51,10 @@ public:
|
|||
return nullptr;
|
||||
|
||||
if (dataSymbolOnly) {
|
||||
OwningPtr<MemoryBuffer> buff;
|
||||
std::unique_ptr<MemoryBuffer> 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<std::unique_ptr<File>> &result) const {
|
||||
OwningPtr<MemoryBuffer> buff;
|
||||
if (error_code ec = member->getMemoryBuffer(buff, true))
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (error_code ec = member->getMemoryBuffer(mb, true))
|
||||
return ec;
|
||||
if (_logLoading)
|
||||
llvm::outs() << buff->getBufferIdentifier() << "\n";
|
||||
std::unique_ptr<MemoryBuffer> 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<MemoryBuffer> mb, StringRef symbol) const {
|
||||
auto objOrErr(ObjectFile::createObjectFile(mb.release()));
|
||||
if (auto ec = objOrErr.getError())
|
||||
return ec;
|
||||
std::unique_ptr<ObjectFile> obj(objOrErr.get());
|
||||
|
|
|
@ -933,7 +933,7 @@ error_code MachOFileLayout::writeBinary(StringRef path) {
|
|||
if (_ec)
|
||||
return _ec;
|
||||
// Create FileOutputBuffer with calculated size.
|
||||
OwningPtr<llvm::FileOutputBuffer> fob;
|
||||
std::unique_ptr<llvm::FileOutputBuffer> fob;
|
||||
unsigned flags = 0;
|
||||
if (_file.fileType != llvm::MachO::MH_OBJECT)
|
||||
flags = llvm::FileOutputBuffer::F_executable;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -272,14 +272,14 @@ FileCOFF::FileCOFF(std::unique_ptr<MemoryBuffer> mb, error_code &ec)
|
|||
auto binaryOrErr = llvm::object::createBinary(mb.release());
|
||||
if ((ec = binaryOrErr.getError()))
|
||||
return;
|
||||
OwningPtr<llvm::object::Binary> bin(binaryOrErr.get());
|
||||
std::unique_ptr<llvm::object::Binary> bin(binaryOrErr.get());
|
||||
|
||||
_obj.reset(dyn_cast<const llvm::object::COFFObjectFile>(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<uint8_t> directives;
|
||||
|
@ -912,10 +912,9 @@ public:
|
|||
llvm::FileRemover coffFileRemover(*coffPath);
|
||||
|
||||
// Read and parse the COFF
|
||||
OwningPtr<MemoryBuffer> opmb;
|
||||
if (error_code ec = MemoryBuffer::getFile(*coffPath, opmb))
|
||||
std::unique_ptr<MemoryBuffer> newmb;
|
||||
if (error_code ec = MemoryBuffer::getFile(*coffPath, newmb))
|
||||
return ec;
|
||||
std::unique_ptr<MemoryBuffer> newmb(opmb.take());
|
||||
error_code ec;
|
||||
std::unique_ptr<FileCOFF> 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<llvm::FileOutputBuffer> buffer;
|
||||
std::unique_ptr<llvm::FileOutputBuffer> buffer;
|
||||
if (error_code ec = llvm::FileOutputBuffer::create(
|
||||
tempFilePath.str(), mb->getBufferSize(), buffer))
|
||||
return ec;
|
||||
|
|
|
@ -1016,7 +1016,7 @@ error_code PECOFFWriter::writeFile(const File &linkedFile, StringRef path) {
|
|||
}
|
||||
|
||||
uint64_t totalSize = _chunks.back()->fileOffset() + _chunks.back()->size();
|
||||
OwningPtr<llvm::FileOutputBuffer> buffer;
|
||||
std::unique_ptr<llvm::FileOutputBuffer> buffer;
|
||||
error_code ec = llvm::FileOutputBuffer::create(
|
||||
path, totalSize, buffer, llvm::FileOutputBuffer::F_executable);
|
||||
if (ec)
|
||||
|
|
|
@ -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 <memory>
|
||||
|
||||
namespace lld {
|
||||
|
||||
Reader::~Reader() {
|
||||
|
|
|
@ -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 <memory>
|
||||
#include <string>
|
||||
|
||||
using llvm::yaml::MappingTraits;
|
||||
|
|
|
@ -10,18 +10,17 @@
|
|||
#include "gtest/gtest.h"
|
||||
|
||||
#include "../../lib/ReaderWriter/MachO/MachONormalizedFile.h"
|
||||
#include <llvm/ADT/OwningPtr.h>
|
||||
#include <llvm/ADT/Twine.h>
|
||||
#include <llvm/Support/FileSystem.h>
|
||||
#include <llvm/Support/MachO.h>
|
||||
#include <llvm/Support/system_error.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
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<MemoryBuffer> &mb,
|
||||
std::unique_ptr<NormalizedFile> &nf, StringRef archStr) {
|
||||
OwningPtr<MemoryBuffer> opmb;
|
||||
error_code ec = MemoryBuffer::getFile(path, opmb);
|
||||
error_code ec = MemoryBuffer::getFile(path, mb);
|
||||
EXPECT_FALSE(ec);
|
||||
mb.reset(opmb.take());
|
||||
|
||||
ErrorOr<std::unique_ptr<NormalizedFile>> r =
|
||||
lld::mach_o::normalized::readBinary(
|
||||
|
|
|
@ -26,12 +26,12 @@ int main(int argc, const char **argv) {
|
|||
llvm::PrettyStackTraceProgram X(argc, argv);
|
||||
|
||||
{
|
||||
llvm::OwningPtr<MemoryBuffer> mb;
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) {
|
||||
llvm::errs() << ec.message() << "\n";
|
||||
return 1;
|
||||
}
|
||||
Lexer l(std::unique_ptr<MemoryBuffer>(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<MemoryBuffer> mb;
|
||||
std::unique_ptr<MemoryBuffer> mb;
|
||||
if (error_code ec = MemoryBuffer::getFileOrSTDIN(argv[1], mb)) {
|
||||
llvm::errs() << ec.message() << "\n";
|
||||
return 1;
|
||||
}
|
||||
Lexer l(std::unique_ptr<MemoryBuffer>(mb.take()));
|
||||
Lexer l(std::move(mb));
|
||||
Parser p(l);
|
||||
LinkerScript *ls = p.parse();
|
||||
if (ls)
|
||||
|
|
Loading…
Reference in New Issue