From 6312816b42efc879f0b567b35d3fa532b2353de5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 1 Aug 2014 18:09:32 +0000 Subject: [PATCH] Replace comment about ownership with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214533 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ExecutionEngine/ExecutionEngine.h | 4 +--- lib/ExecutionEngine/MCJIT/MCJIT.cpp | 10 +++------- lib/ExecutionEngine/MCJIT/MCJIT.h | 4 ++-- tools/lli/lli.cpp | 8 +++++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h index b95a2341103..c367040cd71 100644 --- a/include/llvm/ExecutionEngine/ExecutionEngine.h +++ b/include/llvm/ExecutionEngine/ExecutionEngine.h @@ -196,9 +196,7 @@ public: /// resolve external symbols in objects it is loading. If a symbol is found /// in the Archive the contained object file will be extracted (in memory) /// and loaded for possible execution. - /// - /// MCJIT will take ownership of the Archive. - virtual void addArchive(object::Archive *A) { + virtual void addArchive(std::unique_ptr A) { llvm_unreachable("ExecutionEngine subclass doesn't implement addArchive."); } diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp index 2ed267b3161..435ffd7cdfa 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp +++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp @@ -87,10 +87,6 @@ MCJIT::~MCJIT() { } LoadedObjects.clear(); - - for (object::Archive *A : Archives) - delete A; - Archives.clear(); delete TM; @@ -118,8 +114,8 @@ void MCJIT::addObjectFile(std::unique_ptr Obj) { NotifyObjectEmitted(*LoadedObject); } -void MCJIT::addArchive(object::Archive *A) { - Archives.push_back(A); +void MCJIT::addArchive(std::unique_ptr A) { + Archives.push_back(std::move(A)); } @@ -294,7 +290,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name, if (Addr) return Addr; - for (object::Archive *A : Archives) { + for (std::unique_ptr &A : Archives) { // Look for our symbols in each Archive object::Archive::child_iterator ChildIt = A->findSym(Name); if (ChildIt != A->child_end()) { diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.h b/lib/ExecutionEngine/MCJIT/MCJIT.h index f28aab31197..83e3321db92 100644 --- a/lib/ExecutionEngine/MCJIT/MCJIT.h +++ b/lib/ExecutionEngine/MCJIT/MCJIT.h @@ -215,7 +215,7 @@ class MCJIT : public ExecutionEngine { OwningModuleContainer OwnedModules; - SmallVector Archives; + SmallVector, 2> Archives; typedef SmallVector LoadedObjectList; LoadedObjectList LoadedObjects; @@ -239,7 +239,7 @@ public: /// @{ void addModule(Module *M) override; void addObjectFile(std::unique_ptr O) override; - void addArchive(object::Archive *O) override; + void addArchive(std::unique_ptr O) override; bool removeModule(Module *M) override; /// FindFunctionNamed - Search all of the active modules to find the one that diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 43aedd1526a..f566bf7457d 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -545,12 +545,14 @@ int main(int argc, char **argv, char * const *envp) { return 1; } std::error_code EC; - object::Archive *Ar = new object::Archive(std::move(ArBuf.get()), EC); - if (EC || !Ar) { + std::unique_ptr Ar = + llvm::make_unique(std::move(ArBuf.get()), EC); + assert(Ar); + if (EC) { Err.print(argv[0], errs()); return 1; } - EE->addArchive(Ar); + EE->addArchive(std::move(Ar)); } // If the target is Cygwin/MingW and we are generating remote code, we -- 2.34.1