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