Fix Clang-tidy modernize-use-nullptr warnings in examples and include directories...
[oota-llvm.git] / examples / ParallelJIT / ParallelJIT.cpp
index 64a388695ff2d136ed2cb24daa3c3eb07498e3be..27ea8b1419fb6a0460a71848c636fb9656132e98 100644 (file)
@@ -17,9 +17,9 @@
 // call into the JIT at the same time (or the best possible approximation of the
 // same time). This test had assertion errors until I got the locking right.
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/ExecutionEngine/Interpreter.h"
-#include "llvm/ExecutionEngine/JIT.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Instructions.h"
@@ -28,6 +28,7 @@
 #include "llvm/Support/TargetSelect.h"
 #include <iostream>
 #include <pthread.h>
+
 using namespace llvm;
 
 static Function* createAdd1(Module *M) {
@@ -38,7 +39,7 @@ static Function* createAdd1(Module *M) {
     cast<Function>(M->getOrInsertFunction("add1",
                                           Type::getInt32Ty(M->getContext()),
                                           Type::getInt32Ty(M->getContext()),
-                                          (Type *)0));
+                                          nullptr));
 
   // Add a basic block to the function. As before, it automatically inserts
   // because of the last argument.
@@ -69,7 +70,7 @@ static Function *CreateFibFunction(Module *M) {
     cast<Function>(M->getOrInsertFunction("fib",
                                           Type::getInt32Ty(M->getContext()),
                                           Type::getInt32Ty(M->getContext()),
-                                          (Type *)0));
+                                          nullptr));
 
   // Add a basic block to the function.
   BasicBlock *BB = BasicBlock::Create(M->getContext(), "EntryBlock", FibF);
@@ -129,16 +130,17 @@ public:
     n = 0;
     waitFor = 0;
 
-    int result = pthread_cond_init( &condition, NULL );
+    int result = pthread_cond_init( &condition, nullptr );
     assert( result == 0 );
 
-    result = pthread_mutex_init( &mutex, NULL );
+    result = pthread_mutex_init( &mutex, nullptr );
     assert( result == 0 );
   }
 
   ~WaitForThreads()
   {
     int result = pthread_cond_destroy( &condition );
+    (void)result;
     assert( result == 0 );
 
     result = pthread_mutex_destroy( &mutex );
@@ -149,6 +151,7 @@ public:
   void block()
   {
     int result = pthread_mutex_lock( &mutex );
+    (void)result;
     assert( result == 0 );
     n ++;
     //~ std::cout << "block() n " << n << " waitFor " << waitFor << std::endl;
@@ -178,6 +181,7 @@ public:
   void releaseThreads( size_t num )
   {
     int result = pthread_mutex_lock( &mutex );
+    (void)result;
     assert( result == 0 );
 
     if ( n >= num ) {
@@ -240,13 +244,14 @@ int main() {
   LLVMContext Context;
 
   // Create some module to put our function into it.
-  Module *M = new Module("test", Context);
+  std::unique_ptr<Module> Owner = make_unique<Module>("test", Context);
+  Module *M = Owner.get();
 
   Function* add1F = createAdd1( M );
   Function* fibF = CreateFibFunction( M );
 
   // Now we create the JIT.
-  ExecutionEngine* EE = EngineBuilder(M).create();
+  ExecutionEngine* EE = EngineBuilder(std::move(Owner)).create();
 
   //~ std::cout << "We just constructed this LLVM module:\n\n" << *M;
   //~ std::cout << "\n\nRunning foo: " << std::flush;
@@ -257,21 +262,21 @@ int main() {
   struct threadParams fib2 = { EE, fibF, 42 };
 
   pthread_t add1Thread;
-  int result = pthread_create( &add1Thread, NULL, callFunc, &add1 );
+  int result = pthread_create( &add1Thread, nullptr, callFunc, &add1 );
   if ( result != 0 ) {
           std::cerr << "Could not create thread" << std::endl;
           return 1;
   }
 
   pthread_t fibThread1;
-  result = pthread_create( &fibThread1, NULL, callFunc, &fib1 );
+  result = pthread_create( &fibThread1, nullptr, callFunc, &fib1 );
   if ( result != 0 ) {
           std::cerr << "Could not create thread" << std::endl;
           return 1;
   }
 
   pthread_t fibThread2;
-  result = pthread_create( &fibThread2, NULL, callFunc, &fib2 );
+  result = pthread_create( &fibThread2, nullptr, callFunc, &fib2 );
   if ( result != 0 ) {
           std::cerr << "Could not create thread" << std::endl;
           return 1;