[llvm] r212299 - Use std::unique_ptr to manage memory. No functionality change.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jul 3 15:43:03 PDT 2014
Author: rafael
Date: Thu Jul 3 17:43:03 2014
New Revision: 212299
URL: http://llvm.org/viewvc/llvm-project?rev=212299&view=rev
Log:
Use std::unique_ptr to manage memory. No functionality change.
Modified:
llvm/trunk/include/llvm/LTO/LTOModule.h
llvm/trunk/lib/LTO/LTOModule.cpp
Modified: llvm/trunk/include/llvm/LTO/LTOModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LTO/LTOModule.h?rev=212299&r1=212298&r2=212299&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LTO/LTOModule.h (original)
+++ llvm/trunk/include/llvm/LTO/LTOModule.h Thu Jul 3 17:43:03 2014
@@ -63,7 +63,7 @@ private:
// Use mangler to add GlobalPrefix to names to match linker names.
Mangler _mangler;
- LTOModule(Module *m, TargetMachine *t);
+ LTOModule(std::unique_ptr<Module> M, TargetMachine *TM);
public:
/// Returns 'true' if the file or memory contents is LLVM bitcode.
@@ -205,8 +205,8 @@ private:
/// Create an LTOModule (private version). N.B. This method takes ownership of
/// the buffer.
- static LTOModule *makeLTOModule(MemoryBuffer *buffer, TargetOptions options,
- std::string &errMsg);
+ static LTOModule *makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
+ TargetOptions options, std::string &errMsg);
/// Create a MemoryBuffer from a memory range with an optional name.
static MemoryBuffer *makeBuffer(const void *mem, size_t length,
Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=212299&r1=212298&r2=212299&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Thu Jul 3 17:43:03 2014
@@ -44,12 +44,13 @@
#include <system_error>
using namespace llvm;
-LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
- : _module(m), _target(t),
- _context(_target->getMCAsmInfo(), _target->getRegisterInfo(), &ObjFileInfo),
- _mangler(t->getDataLayout()) {
- ObjFileInfo.InitMCObjectFileInfo(t->getTargetTriple(),
- t->getRelocationModel(), t->getCodeModel(),
+LTOModule::LTOModule(std::unique_ptr<Module> M, TargetMachine *TM)
+ : _module(std::move(M)), _target(TM),
+ _context(_target->getMCAsmInfo(), _target->getRegisterInfo(),
+ &ObjFileInfo),
+ _mangler(TM->getDataLayout()) {
+ ObjFileInfo.InitMCObjectFileInfo(TM->getTargetTriple(),
+ TM->getRelocationModel(), TM->getCodeModel(),
_context);
}
@@ -102,7 +103,7 @@ LTOModule *LTOModule::makeLTOModule(cons
errMsg = ec.message();
return nullptr;
}
- return makeLTOModule(buffer.release(), options, errMsg);
+ return makeLTOModule(std::move(buffer), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
@@ -122,7 +123,7 @@ LTOModule *LTOModule::makeLTOModule(int
errMsg = ec.message();
return nullptr;
}
- return makeLTOModule(buffer.release(), options, errMsg);
+ return makeLTOModule(std::move(buffer), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
@@ -131,20 +132,20 @@ LTOModule *LTOModule::makeLTOModule(cons
std::unique_ptr<MemoryBuffer> buffer(makeBuffer(mem, length, path));
if (!buffer)
return nullptr;
- return makeLTOModule(buffer.release(), options, errMsg);
+ return makeLTOModule(std::move(buffer), options, errMsg);
}
-LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
+LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
TargetOptions options,
std::string &errMsg) {
// parse bitcode buffer
ErrorOr<Module *> ModuleOrErr =
- getLazyBitcodeModule(buffer, getGlobalContext());
+ getLazyBitcodeModule(Buffer.get(), getGlobalContext());
if (std::error_code EC = ModuleOrErr.getError()) {
errMsg = EC.message();
- delete buffer;
return nullptr;
}
+ Buffer.release();
std::unique_ptr<Module> m(ModuleOrErr.get());
std::string TripleStr = m->getTargetTriple();
@@ -177,7 +178,7 @@ LTOModule *LTOModule::makeLTOModule(Memo
options);
m->materializeAllPermanently();
- LTOModule *Ret = new LTOModule(m.release(), target);
+ LTOModule *Ret = new LTOModule(std::move(m), target);
// We need a MCContext set up in order to get mangled names of private
// symbols. It is a bit odd that we need to report uses and definitions
More information about the llvm-commits
mailing list