Make it explicit that ExecutionEngine takes ownership of the modules.
[oota-llvm.git] / examples / Kaleidoscope / Chapter7 / toy.cpp
index c2c337c900880565748a7ae97951ef1337e1f1b6..89e8368a14dc484f49bed1317b40d675066dbc5e 100644 (file)
@@ -1099,11 +1099,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);