Make it explicit that ExecutionEngine takes ownership of the modules.
[oota-llvm.git] / examples / Kaleidoscope / Chapter5 / toy.cpp
index a31b5b4792afb1978d04e269a04dab176a29a486..550504259eee280aabe0f798144b3ee14a474630 100644 (file)
@@ -817,11 +817,13 @@ int main() {
   getNextToken();
 
   // Make the module, which holds all the code.
-  TheModule = new Module("my cool jit", Context);
+  std::unique_ptr<Module> Owner = make_unique<Module>("my cool jit", Context);
+  TheModule = Owner.get();
 
   // Create the JIT.  This takes ownership of the module.
   std::string ErrStr;
-  TheExecutionEngine = EngineBuilder(TheModule).setErrorStr(&ErrStr).create();
+  TheExecutionEngine =
+      EngineBuilder(std::move(Owner)).setErrorStr(&ErrStr).create();
   if (!TheExecutionEngine) {
     fprintf(stderr, "Could not create ExecutionEngine: %s\n", ErrStr.c_str());
     exit(1);