Replace NULL macros with nullptr literals.

Change-Id: Id2311cda59dd42c74b3ed54d3ff6cfd509012738
diff --git a/lib/Core/BCCContext.cpp b/lib/Core/BCCContext.cpp
index 4edccaa..c0a307f 100644
--- a/lib/Core/BCCContext.cpp
+++ b/lib/Core/BCCContext.cpp
@@ -25,12 +25,12 @@
 
 using namespace bcc;
 
-static BCCContext *GlobalContext = NULL;
+static BCCContext *GlobalContext = nullptr;
 
 BCCContext *BCCContext::GetOrCreateGlobalContext() {
-  if (GlobalContext == NULL) {
+  if (GlobalContext == nullptr) {
     GlobalContext = new (std::nothrow) BCCContext();
-    if (GlobalContext == NULL) {
+    if (GlobalContext == nullptr) {
       ALOGE("Out of memory when allocating global BCCContext!");
     }
   }
@@ -39,7 +39,7 @@
 
 void BCCContext::DestroyGlobalContext() {
   delete GlobalContext;
-  GlobalContext = NULL;
+  GlobalContext = nullptr;
 }
 
 BCCContext::BCCContext() : mImpl(new BCCContextImpl(*this)) { }
@@ -49,7 +49,7 @@
   if (this == GlobalContext) {
     // We're deleting the context returned from GetOrCreateGlobalContext().
     // Reset the GlobalContext.
-    GlobalContext = NULL;
+    GlobalContext = nullptr;
   }
 }
 
diff --git a/lib/Core/Compiler.cpp b/lib/Core/Compiler.cpp
index f38f322..d6a8543 100644
--- a/lib/Core/Compiler.cpp
+++ b/lib/Core/Compiler.cpp
@@ -41,7 +41,7 @@
   case kSuccess:
     return "Successfully compiled.";
   case kInvalidConfigNoTarget:
-    return "Invalid compiler config supplied (getTarget() returns NULL.) "
+    return "Invalid compiler config supplied (getTarget() returns nullptr.) "
            "(missing call to CompilerConfig::initialize()?)";
   case kErrCreateTargetMachine:
     return "Failed to create llvm::TargetMachine.";
@@ -87,11 +87,11 @@
 //===----------------------------------------------------------------------===//
 // Instance Methods
 //===----------------------------------------------------------------------===//
-Compiler::Compiler() : mTarget(NULL), mEnableLTO(true) {
+Compiler::Compiler() : mTarget(nullptr), mEnableLTO(true) {
   return;
 }
 
-Compiler::Compiler(const CompilerConfig &pConfig) : mTarget(NULL),
+Compiler::Compiler(const CompilerConfig &pConfig) : mTarget(nullptr),
                                                     mEnableLTO(true) {
   const std::string &triple = pConfig.getTriple();
 
@@ -106,7 +106,7 @@
 }
 
 enum Compiler::ErrorCode Compiler::config(const CompilerConfig &pConfig) {
-  if (pConfig.getTarget() == NULL) {
+  if (pConfig.getTarget() == nullptr) {
     return kInvalidConfigNoTarget;
   }
 
@@ -119,8 +119,8 @@
                                                  pConfig.getCodeModel(),
                                                  pConfig.getOptimizationLevel());
 
-  if (new_target == NULL) {
-    return ((mTarget != NULL) ? kErrSwitchTargetMachine :
+  if (new_target == nullptr) {
+    return ((mTarget != nullptr) ? kErrSwitchTargetMachine :
                                 kErrCreateTargetMachine);
   }
 
@@ -145,14 +145,14 @@
 }
 
 enum Compiler::ErrorCode Compiler::runLTO(Script &pScript) {
-  llvm::DataLayoutPass *data_layout_pass = NULL;
+  llvm::DataLayoutPass *data_layout_pass = nullptr;
 
   // Pass manager for link-time optimization
   llvm::PassManager lto_passes;
 
   // Prepare DataLayout target data from Module
   data_layout_pass = new (std::nothrow) llvm::DataLayoutPass(*mTarget->getDataLayout());
-  if (data_layout_pass == NULL) {
+  if (data_layout_pass == nullptr) {
     return kErrDataLayoutNoMemory;
   }
 
@@ -193,14 +193,14 @@
 enum Compiler::ErrorCode Compiler::runCodeGen(Script &pScript,
                                               llvm::raw_ostream &pResult) {
   llvm::DataLayoutPass *data_layout_pass;
-  llvm::MCContext *mc_context = NULL;
+  llvm::MCContext *mc_context = nullptr;
 
   // Create pass manager for MC code generation.
   llvm::PassManager codegen_passes;
 
   // Prepare DataLayout target data from Module
   data_layout_pass = new (std::nothrow) llvm::DataLayoutPass(*mTarget->getDataLayout());
-  if (data_layout_pass == NULL) {
+  if (data_layout_pass == nullptr) {
     return kErrDataLayoutNoMemory;
   }
 
@@ -246,12 +246,12 @@
   llvm::Module &module = pScript.getSource().getModule();
   enum ErrorCode err;
 
-  if (mTarget == NULL) {
+  if (mTarget == nullptr) {
     return kErrNoTargetMachine;
   }
 
   // Materialize the bitcode module.
-  if (module.getMaterializer() != NULL) {
+  if (module.getMaterializer() != nullptr) {
     // A module with non-null materializer means that it is a lazy-load module.
     // Materialize it now via invoking MaterializeAllPermanently(). This
     // function returns false when the materialization is successful.
@@ -287,7 +287,7 @@
 
   // Open the output file decorated in llvm::raw_ostream.
   llvm::raw_ostream *out = pResult.dup();
-  if (out == NULL) {
+  if (out == nullptr) {
     return kErrPrepareOutput;
   }
 
diff --git a/lib/Core/Source.cpp b/lib/Core/Source.cpp
index 2fd9d55..8ec19af 100644
--- a/lib/Core/Source.cpp
+++ b/lib/Core/Source.cpp
@@ -36,7 +36,7 @@
 // Helper function to load the bitcode. This uses "bitcode lazy load" feature to
 // reduce the startup time. On success, return the LLVM module object created
 // and take the ownership of input memory buffer (i.e., pInput). On error,
-// return NULL and will NOT take the ownership of pInput.
+// return nullptr and will NOT take the ownership of pInput.
 static inline llvm::Module *helper_load_bitcode(llvm::LLVMContext &pContext,
                                                 llvm::MemoryBuffer *pInput) {
   llvm::ErrorOr<llvm::Module *> moduleOrError = llvm::getLazyBitcodeModule(pInput, pContext);
@@ -65,20 +65,20 @@
   llvm::MemoryBuffer *input_memory =
       llvm::MemoryBuffer::getMemBuffer(input_data, "", false);
 
-  if (input_memory == NULL) {
+  if (input_memory == nullptr) {
     ALOGE("Unable to load bitcode `%s' from buffer!", pName);
-    return NULL;
+    return nullptr;
   }
 
   llvm::Module *module = helper_load_bitcode(pContext.mImpl->mLLVMContext,
                                              input_memory);
-  if (module == NULL) {
+  if (module == nullptr) {
     delete input_memory;
-    return NULL;
+    return nullptr;
   }
 
   Source *result = CreateFromModule(pContext, *module, /* pNoDelete */false);
-  if (result == NULL) {
+  if (result == nullptr) {
     delete module;
   }
 
@@ -92,20 +92,20 @@
   if (mb_or_error.getError()) {
     ALOGE("Failed to load bitcode from path %s! (%s)", pPath.c_str(),
           mb_or_error.getError().message().c_str());
-    return NULL;
+    return nullptr;
   }
   std::unique_ptr<llvm::MemoryBuffer> input_data = std::move(mb_or_error.get());
 
   llvm::MemoryBuffer *input_memory = input_data.release();
   llvm::Module *module = helper_load_bitcode(pContext.mImpl->mLLVMContext,
                                              input_memory);
-  if (module == NULL) {
+  if (module == nullptr) {
     delete input_memory;
-    return NULL;
+    return nullptr;
   }
 
   Source *result = CreateFromModule(pContext, *module, /* pNoDelete */false);
-  if (result == NULL) {
+  if (result == nullptr) {
     delete module;
   }
 
@@ -119,11 +119,11 @@
   if (llvm::verifyModule(pModule, &ErrorStream)) {
     ALOGE("Bitcode of RenderScript module does not pass verification: `%s'!",
           ErrorStream.str().c_str());
-    return NULL;
+    return nullptr;
   }
 
   Source *result = new (std::nothrow) Source(pContext, pModule, pNoDelete);
-  if (result == NULL) {
+  if (result == nullptr) {
     ALOGE("Out of memory during Source object allocation for `%s'!",
           pModule.getModuleIdentifier().c_str());
   }
@@ -169,13 +169,13 @@
   llvm::Module *module =
       new (std::nothrow) llvm::Module(pName, pContext.mImpl->mLLVMContext);
 
-  if (module == NULL) {
+  if (module == nullptr) {
     ALOGE("Out of memory when creating empty LLVM module `%s'!", pName.c_str());
-    return NULL;
+    return nullptr;
   }
 
   Source *result = CreateFromModule(pContext, *module, /* pNoDelete */false);
-  if (result == NULL) {
+  if (result == nullptr) {
     delete module;
   }
 
diff --git a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
index 8797ce1..867b7ab 100644
--- a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
+++ b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
@@ -38,7 +38,7 @@
 #else
   mObject = ELFObject<32>::read(reader);
 #endif
-  if (mObject == NULL) {
+  if (mObject == nullptr) {
     ALOGE("Unable to load the ELF object!");
     return false;
   }
@@ -51,7 +51,7 @@
   mSymTab = static_cast<ELFSectionSymTab<32> *>(
                  mObject->getSectionByName(".symtab"));
 #endif
-  if (mSymTab == NULL) {
+  if (mSymTab == nullptr) {
     ALOGW("Object doesn't contain any symbol table.");
   }
 
@@ -125,7 +125,7 @@
       ELFSectionBits<32> *section =
           static_cast<ELFSectionBits<32> *>(mObject->getSectionByIndex(i));
 #endif
-      if (section != NULL) {
+      if (section != nullptr) {
         uintptr_t address = reinterpret_cast<uintptr_t>(section->getBuffer());
 #ifdef __LP64__
         LOG_FATAL_IF(address > 0xFFFFFFFFFFFFFFFFu, "Out of bound address for Elf64_Addr");
@@ -142,8 +142,8 @@
 }
 
 void *ELFObjectLoaderImpl::getSymbolAddress(const char *pName) const {
-  if (mSymTab == NULL) {
-    return NULL;
+  if (mSymTab == nullptr) {
+    return nullptr;
   }
 
 #ifdef __LP64__
@@ -151,9 +151,9 @@
 #else
   const ELFSymbol<32> *symbol = mSymTab->getByName(pName);
 #endif
-  if (symbol == NULL) {
+  if (symbol == nullptr) {
     ALOGV("Request symbol '%s' is not found in the object!", pName);
-    return NULL;
+    return nullptr;
   }
 
   return symbol->getAddress(mObject->getHeader()->getMachine(),
@@ -161,7 +161,7 @@
 }
 
 size_t ELFObjectLoaderImpl::getSymbolSize(const char *pName) const {
-  if (mSymTab == NULL) {
+  if (mSymTab == nullptr) {
     return 0;
   }
 
@@ -171,7 +171,7 @@
   const ELFSymbol<32> *symbol = mSymTab->getByName(pName);
 #endif
 
-  if (symbol == NULL) {
+  if (symbol == nullptr) {
     ALOGV("Request symbol '%s' is not found in the object!", pName);
     return 0;
   }
@@ -183,7 +183,7 @@
 bool
 ELFObjectLoaderImpl::getSymbolNameList(std::vector<const char *>& pNameList,
                                        ObjectLoader::SymbolType pType) const {
-  if (mSymTab == NULL) {
+  if (mSymTab == nullptr) {
     return false;
   }
 
@@ -208,14 +208,14 @@
 #else
     ELFSymbol<32> *symbol = (*mSymTab)[i];
 #endif
-    if (symbol == NULL) {
+    if (symbol == nullptr) {
       continue;
     }
 
     if ((pType == ObjectLoader::kUnknownType) ||
         (symbol->getType() == elf_type)) {
       const char *symbol_name = symbol->getName();
-      if (symbol_name != NULL) {
+      if (symbol_name != nullptr) {
         pNameList.push_back(symbol_name);
       }
     }
diff --git a/lib/ExecutionEngine/ELFObjectLoaderImpl.h b/lib/ExecutionEngine/ELFObjectLoaderImpl.h
index 8734558..1490bcb 100644
--- a/lib/ExecutionEngine/ELFObjectLoaderImpl.h
+++ b/lib/ExecutionEngine/ELFObjectLoaderImpl.h
@@ -40,7 +40,7 @@
 #endif
 
 public:
-  ELFObjectLoaderImpl() : ObjectLoaderImpl(), mObject(NULL), mSymTab(NULL) { }
+  ELFObjectLoaderImpl() : ObjectLoaderImpl(), mObject(nullptr), mSymTab(nullptr) { }
 
   virtual bool load(const void *pMem, size_t pMemSize);
 
diff --git a/lib/ExecutionEngine/GDBJITRegistrar.cpp b/lib/ExecutionEngine/GDBJITRegistrar.cpp
index 68d6833..3afc984 100644
--- a/lib/ExecutionEngine/GDBJITRegistrar.cpp
+++ b/lib/ExecutionEngine/GDBJITRegistrar.cpp
@@ -116,10 +116,10 @@
   __jit_debug_descriptor.action_flag = JIT_REGISTER_FN;
 
   // Insert this entry at the head of the list.
-  JITCodeEntry->prev_entry = NULL;
+  JITCodeEntry->prev_entry = nullptr;
   jit_code_entry* NextEntry = __jit_debug_descriptor.first_entry;
   JITCodeEntry->next_entry = NextEntry;
-  if (NextEntry != NULL) {
+  if (NextEntry != nullptr) {
     NextEntry->prev_entry = JITCodeEntry;
   }
   __jit_debug_descriptor.first_entry = JITCodeEntry;
@@ -128,13 +128,13 @@
 }
 
 GDBJITRegistrar* RegistrarSingleton() {
-  static GDBJITRegistrar* sRegistrar = NULL;
-  if (sRegistrar == NULL) {
+  static GDBJITRegistrar* sRegistrar = nullptr;
+  if (sRegistrar == nullptr) {
     // The mutex is here so that it won't slow down access once the registrar
     //   is instantiated
     llvm::MutexGuard locked(JITDebugLock);
     // Check again to be sure another thread didn't create this while we waited
-    if (sRegistrar == NULL) {
+    if (sRegistrar == nullptr) {
       sRegistrar = new GDBJITRegistrar;
     }
   }
@@ -225,7 +225,7 @@
   }
 
   delete JITCodeEntry;
-  JITCodeEntry = NULL;
+  JITCodeEntry = nullptr;
 }
 
 } // end namespace
diff --git a/lib/ExecutionEngine/ObjectLoader.cpp b/lib/ExecutionEngine/ObjectLoader.cpp
index 79209d3..bb9a205 100644
--- a/lib/ExecutionEngine/ObjectLoader.cpp
+++ b/lib/ExecutionEngine/ObjectLoader.cpp
@@ -30,10 +30,10 @@
                                  const char *pName,
                                  SymbolResolverInterface &pResolver,
                                  bool pEnableGDBDebug) {
-  ObjectLoader *result = NULL;
+  ObjectLoader *result = nullptr;
 
   // Check parameters.
-  if ((pMemStart == NULL) || (pMemSize <= 0)) {
+  if ((pMemStart == nullptr) || (pMemSize <= 0)) {
     ALOGE("Invalid memory '%s' was given to load (memory addr: %p, size: %u)",
           pName, pMemStart, static_cast<unsigned>(pMemSize));
     goto bail;
@@ -41,7 +41,7 @@
 
   // Create result object
   result = new (std::nothrow) ObjectLoader();
-  if (result == NULL) {
+  if (result == nullptr) {
     ALOGE("Out of memory when create object loader for %s!", pName);
     goto bail;
   }
@@ -50,7 +50,7 @@
   // to detect the object file type and to select the one appropriated. Directly
   // try out the ELF object loader.
   result->mImpl = new (std::nothrow) ELFObjectLoaderImpl();
-  if (result->mImpl == NULL) {
+  if (result->mImpl == nullptr) {
     ALOGE("Out of memory when create ELF object loader for %s", pName);
     goto bail;
   }
@@ -79,7 +79,7 @@
     // section lives in the process image. Therefore, a writable memory with its
     // contents initialized to the contents of pFile is created.
     result->mDebugImage = new (std::nothrow) uint8_t [ pMemSize ];
-    if (result->mDebugImage != NULL) {
+    if (result->mDebugImage != nullptr) {
       ::memcpy(result->mDebugImage, pMemStart, pMemSize);
       if (!result->mImpl->prepareDebugImage(result->mDebugImage, pMemSize)) {
         ALOGW("GDB debug for %s is enabled by the user but won't work due to "
@@ -96,22 +96,22 @@
 
 bail:
   delete result;
-  return NULL;
+  return nullptr;
 }
 
 ObjectLoader *ObjectLoader::Load(FileBase &pFile,
                                  SymbolResolverInterface &pResolver,
                                  bool pEnableGDBDebug) {
   size_t file_size;
-  android::FileMap *file_map = NULL;
+  android::FileMap *file_map = nullptr;
   const char *input_filename = pFile.getName().c_str();
-  ObjectLoader *result = NULL;
+  ObjectLoader *result = nullptr;
 
   // Check the inputs.
   if (pFile.hasError()) {
     ALOGE("Input file %s to the object loader is in the invalid state! (%s)",
           input_filename, pFile.getErrorMessage().c_str());
-    return NULL;
+    return nullptr;
   }
 
   // Get the file size.
@@ -119,21 +119,21 @@
   if (pFile.hasError()) {
     ALOGE("Failed to get size of file %s! (%s)", input_filename,
           pFile.getErrorMessage().c_str());
-    return NULL;
+    return nullptr;
   }
 
   // Abort on empty file.
   if (file_size <= 0) {
     ALOGE("Empty file %s to the object loader.", input_filename);
-    return NULL;
+    return nullptr;
   }
 
   // Create memory map for the input file.
   file_map = pFile.createMap(0, file_size, /* pIsReadOnly */true);
-  if ((file_map == NULL) || pFile.hasError())  {
+  if ((file_map == nullptr) || pFile.hasError())  {
     ALOGE("Failed to map the file %s to the memory! (%s)", input_filename,
           pFile.getErrorMessage().c_str());
-    return NULL;
+    return nullptr;
   }
 
   // Delegate the load request.
diff --git a/lib/ExecutionEngine/SymbolResolverProxy.cpp b/lib/ExecutionEngine/SymbolResolverProxy.cpp
index 8a9073c..7644d59 100644
--- a/lib/ExecutionEngine/SymbolResolverProxy.cpp
+++ b/lib/ExecutionEngine/SymbolResolverProxy.cpp
@@ -22,13 +22,13 @@
   // Search the address of the symbol by following the chain of resolvers.
   for (auto resolver : mChain) {
     void *addr = resolver->getAddress(pName);
-    if (addr != NULL) {
+    if (addr != nullptr) {
       return addr;
     }
   }
 
   // Symbol not found or there's no resolver containing in the chain.
-  return NULL;
+  return nullptr;
 }
 
 void SymbolResolverProxy::chainResolver(SymbolResolverInterface &pResolver) {
diff --git a/lib/ExecutionEngine/SymbolResolvers.cpp b/lib/ExecutionEngine/SymbolResolvers.cpp
index 4194a6b..1112ee2 100644
--- a/lib/ExecutionEngine/SymbolResolvers.cpp
+++ b/lib/ExecutionEngine/SymbolResolvers.cpp
@@ -21,7 +21,7 @@
 #else
 /* TODO hack: definitions from bionic/libc/include/dlfcn.h */
 void* dlopen(const char*  filename, int flag) {
-  return NULL;
+  return nullptr;
 }
 
 int dlclose(void*  handle) {
@@ -33,7 +33,7 @@
 }
 
 void* dlsym(void*  handle, const char*  symbol) {
-  return NULL;
+  return nullptr;
 }
 
 #define RTLD_NOW    0
@@ -54,7 +54,7 @@
 // DyldSymbolResolver
 //===----------------------------------------------------------------------===//
 DyldSymbolResolver::DyldSymbolResolver(const char *pFileName,
-                                       bool pLazyBinding) : mError(NULL) {
+                                       bool pLazyBinding) : mError(nullptr) {
   int flags = (pLazyBinding) ? RTLD_LAZY : RTLD_NOW;
 
   // Make the symbol within the given library to be local such that it won't
@@ -62,34 +62,34 @@
   flags |= RTLD_LOCAL;
 
   mHandle = ::dlopen(pFileName, flags);
-  if (mHandle == NULL) {
+  if (mHandle == nullptr) {
     const char *err = ::dlerror();
 
 #define DYLD_ERROR_MSG_PATTERN  "Failed to load %s! (%s)"
     size_t error_length = ::strlen(DYLD_ERROR_MSG_PATTERN) +
                           ::strlen(pFileName) + 1;
-    if (err != NULL) {
+    if (err != nullptr) {
       error_length += ::strlen(err);
     }
 
     mError = new (std::nothrow) char [error_length];
-    if (mError != NULL) {
+    if (mError != nullptr) {
       ::snprintf(mError, error_length, DYLD_ERROR_MSG_PATTERN, pFileName,
-                 ((err != NULL) ? err : ""));
+                 ((err != nullptr) ? err : ""));
     }
   }
 #undef DYLD_ERROR_MSG_PATTERN
 }
 
 void *DyldSymbolResolver::getAddress(const char *pName) {
-  assert((mHandle != NULL) && "Invalid DyldSymbolResolver!");
+  assert((mHandle != nullptr) && "Invalid DyldSymbolResolver!");
   return ::dlsym(mHandle, pName);
 }
 
 DyldSymbolResolver::~DyldSymbolResolver() {
-  if (mHandle != NULL) {
+  if (mHandle != nullptr) {
     ::dlclose(mHandle);
-    mHandle = NULL;
+    mHandle = nullptr;
   }
   delete [] mError;
 }
diff --git a/lib/Renderscript/RSCompiler.cpp b/lib/Renderscript/RSCompiler.cpp
index 5547ad2..dc5ba6a 100644
--- a/lib/Renderscript/RSCompiler.cpp
+++ b/lib/Renderscript/RSCompiler.cpp
@@ -46,7 +46,7 @@
 
   // Special RS functions should always be global symbols.
   const char **special_functions = RSExecutable::SpecialFunctionNames;
-  while (*special_functions != NULL) {
+  while (*special_functions != nullptr) {
     export_symbols.push_back(*special_functions);
     special_functions++;
   }
diff --git a/lib/Renderscript/RSCompilerDriver.cpp b/lib/Renderscript/RSCompilerDriver.cpp
index 4d90470..9ae2e03 100644
--- a/lib/Renderscript/RSCompilerDriver.cpp
+++ b/lib/Renderscript/RSCompilerDriver.cpp
@@ -58,8 +58,8 @@
 }
 
 RSCompilerDriver::RSCompilerDriver(bool pUseCompilerRT) :
-    mConfig(NULL), mCompiler(), mDebugContext(false),
-    mLinkRuntimeCallback(NULL), mEnableGlobalMerge(true) {
+    mConfig(nullptr), mCompiler(), mDebugContext(false),
+    mLinkRuntimeCallback(nullptr), mEnableGlobalMerge(true) {
   init::Initialize();
 }
 
@@ -72,15 +72,15 @@
                                            const char* expectedCompileCommandLine,
                                            SymbolResolverProxy& pResolver) {
   // android::StopWatch load_time("bcc: RSCompilerDriver::loadScript time");
-  if ((pCacheDir == NULL) || (pResName == NULL)) {
+  if ((pCacheDir == nullptr) || (pResName == nullptr)) {
     ALOGE("Missing pCacheDir and/or pResName");
-    return NULL;
+    return nullptr;
   }
 
-  if ((pBitcode == NULL) || (pBitcodeSize <= 0)) {
+  if ((pBitcode == nullptr) || (pBitcodeSize <= 0)) {
     ALOGE("No bitcode supplied! (bitcode: %p, size of bitcode: %zu)",
           pBitcode, pBitcodeSize);
-    return NULL;
+    return nullptr;
   }
 
   // {pCacheDir}/{pResName}.o
@@ -96,7 +96,7 @@
   if (read_output_mutex.hasError() || !read_output_mutex.lock()) {
     ALOGE("Unable to acquire the read lock for %s! (%s)", output_path.c_str(),
           read_output_mutex.getErrorMessage().c_str());
-    return NULL;
+    return nullptr;
   }
 
   //===--------------------------------------------------------------------===//
@@ -104,11 +104,11 @@
   //===--------------------------------------------------------------------===//
   InputFile *object_file = new (std::nothrow) InputFile(output_path.c_str());
 
-  if ((object_file == NULL) || object_file->hasError()) {
+  if ((object_file == nullptr) || object_file->hasError()) {
       //      ALOGE("Unable to open the %s for read! (%s)", output_path.c_str(),
       //            object_file->getErrorMessage().c_str());
     delete object_file;
-    return NULL;
+    return nullptr;
   }
 
   //===--------------------------------------------------------------------===//
@@ -121,7 +121,7 @@
           output_path.c_str(), info_path.c_str(),
           object_file->getErrorMessage().c_str());
     delete object_file;
-    return NULL;
+    return nullptr;
   }
 
   //===---------------------------------------------------------------------===//
@@ -133,9 +133,9 @@
   // Release the lock on object_file.
   object_file->unlock();
 
-  if (info == NULL) {
+  if (info == nullptr) {
     delete object_file;
-    return NULL;
+    return nullptr;
   }
 
   //===---------------------------------------------------------------------===//
@@ -155,17 +155,17 @@
                           expectedBuildFingerprint.c_str())) {
       delete object_file;
       delete info;
-      return NULL;
+      return nullptr;
   }
 
   //===--------------------------------------------------------------------===//
   // Create the RSExecutable.
   //===--------------------------------------------------------------------===//
   RSExecutable *executable = RSExecutable::Create(*info, *object_file, pResolver);
-  if (executable == NULL) {
+  if (executable == nullptr) {
     delete object_file;
     delete info;
-    return NULL;
+    return nullptr;
   }
 
   return executable;
@@ -185,7 +185,7 @@
   EnableGlobalMerge = mEnableGlobalMerge;
 #endif
 
-  if (mConfig != NULL) {
+  if (mConfig != nullptr) {
     // Renderscript bitcode may have their optimization flag configuration
     // different than the previous run of RS compilation.
     if (mConfig->getOptimizationLevel() != script_opt_level) {
@@ -195,7 +195,7 @@
   } else {
     // Haven't run the compiler ever.
     mConfig = new (std::nothrow) CompilerConfig(DEFAULT_TARGET_TRIPLE_STRING);
-    if (mConfig == NULL) {
+    if (mConfig == nullptr) {
       // Return false since mConfig remains NULL and out-of-memory.
       return false;
     }
@@ -204,7 +204,7 @@
   }
 
 #if defined(PROVIDE_ARM_CODEGEN)
-  assert((pScript.getInfo() != NULL) && "NULL RS info!");
+  assert((pScript.getInfo() != nullptr) && "NULL RS info!");
   bool script_full_prec = (pScript.getInfo()->getFloatPrecisionRequirement() ==
                            RSInfo::FP_Full);
   if (mConfig->getFullPrecision() != script_full_prec) {
@@ -223,7 +223,7 @@
                                                     const char* compileCommandLineToEmbed,
                                                     bool saveInfoFile, bool pDumpIR) {
   // android::StopWatch compile_time("bcc: RSCompilerDriver::compileScript time");
-  RSInfo *info = NULL;
+  RSInfo *info = nullptr;
 
   //===--------------------------------------------------------------------===//
   // Extract RS-specific information from source bitcode.
@@ -232,7 +232,7 @@
   // compiler therefore it should be extracted before compilation.
   info = RSInfo::ExtractFromSource(pScript.getSource(), pSourceHash, compileCommandLineToEmbed,
                                    getBuildFingerPrint().c_str());
-  if (info == NULL) {
+  if (info == nullptr) {
     return Compiler::kErrInvalidSource;
   }
 
@@ -280,7 +280,7 @@
     // Setup the config to the compiler.
     bool compiler_need_reconfigure = setupConfig(pScript);
 
-    if (mConfig == NULL) {
+    if (mConfig == nullptr) {
       ALOGE("Failed to setup config for RS compiler to compile %s!",
             pOutputPath);
       return Compiler::kErrInvalidSource;
@@ -295,8 +295,8 @@
       }
     }
 
-    OutputFile *ir_file = NULL;
-    llvm::raw_fd_ostream *IRStream = NULL;
+    OutputFile *ir_file = nullptr;
+    llvm::raw_fd_ostream *IRStream = nullptr;
     if (pDumpIR) {
       std::string path(pOutputPath);
       path.append(".ll");
@@ -360,14 +360,14 @@
   //===--------------------------------------------------------------------===//
   // Check parameters.
   //===--------------------------------------------------------------------===//
-  if ((pCacheDir == NULL) || (pResName == NULL)) {
+  if ((pCacheDir == nullptr) || (pResName == nullptr)) {
     ALOGE("Invalid parameter passed to RSCompilerDriver::build()! (cache dir: "
           "%s, resource name: %s)", ((pCacheDir) ? pCacheDir : "(null)"),
                                     ((pResName) ? pResName : "(null)"));
     return false;
   }
 
-  if ((pBitcode == NULL) || (pBitcodeSize <= 0)) {
+  if ((pBitcode == nullptr) || (pBitcodeSize <= 0)) {
     ALOGE("No bitcode supplied! (bitcode: %p, size of bitcode: %u)",
           pBitcode, static_cast<unsigned>(pBitcodeSize));
     return false;
@@ -392,7 +392,7 @@
   //===--------------------------------------------------------------------===//
   Source *source = Source::CreateFromBuffer(pContext, pResName,
                                             pBitcode, pBitcodeSize);
-  if (source == NULL) {
+  if (source == nullptr) {
     return false;
   }
 
@@ -432,7 +432,7 @@
 
   RSInfo* info = RSInfo::ExtractFromSource(pScript.getSource(), bitcode_sha1,
                                            compileCommandLineToEmbed, buildFingerprintToEmbed);
-  if (info == NULL) {
+  if (info == nullptr) {
     return false;
   }
   pScript.setInfo(info);
diff --git a/lib/Renderscript/RSEmbedInfo.cpp b/lib/Renderscript/RSEmbedInfo.cpp
index b19519f..06fe547 100644
--- a/lib/Renderscript/RSEmbedInfo.cpp
+++ b/lib/Renderscript/RSEmbedInfo.cpp
@@ -54,7 +54,7 @@
 public:
   RSEmbedInfoPass()
       : ModulePass(ID),
-        M(NULL) {
+        M(nullptr) {
   }
 
   static std::string getRSInfoString(const llvm::Module *module) {
diff --git a/lib/Renderscript/RSExecutable.cpp b/lib/Renderscript/RSExecutable.cpp
index 06f9b5f..f0b95ae 100644
--- a/lib/Renderscript/RSExecutable.cpp
+++ b/lib/Renderscript/RSExecutable.cpp
@@ -32,7 +32,7 @@
   "init",      // Initialization routine called implicitly on startup.
   ".rs.dtor",  // Static global destructor for a script instance.
   ".rs.info",  // Variable containing string of RS metadata info.
-  NULL         // Must be NULL-terminated.
+  nullptr         // Must be nullptr-terminated.
 };
 
 RSExecutable *RSExecutable::Create(RSInfo &pInfo,
@@ -43,18 +43,18 @@
   ObjectLoader *loader = ObjectLoader::Load(pObjFile,
                                             pResolver,
                                             pInfo.hasDebugInformation());
-  if (loader == NULL) {
-    return NULL;
+  if (loader == nullptr) {
+    return nullptr;
   }
 
   // Now, all things required to build a RSExecutable object are ready.
   RSExecutable *result = new (std::nothrow) RSExecutable(pInfo,
                                                          pObjFile,
                                                          *loader);
-  if (result == NULL) {
+  if (result == nullptr) {
     ALOGE("Out of memory when create object to hold RS result file for %s!",
           pObjFile.getName().c_str());
-    return NULL;
+    return nullptr;
   }
 
   unsigned idx;
@@ -68,7 +68,7 @@
        var_iter++, idx++) {
     const char *name = *var_iter;
     void *addr = result->getSymbolAddress(name);
-    if (addr == NULL) {
+    if (addr == nullptr) {
         //ALOGW("RS export var at entry #%u named %s cannot be found in the result "
         //"object!", idx, name);
     }
@@ -170,7 +170,7 @@
       void *func = mLoader->getSymbolAddress(func_name);
       size_t func_size = mLoader->getSymbolSize(func_name);
 
-      if (func == NULL) {
+      if (func == nullptr) {
         continue;
       }
       DisassembleResult result =
diff --git a/lib/Renderscript/RSForEachExpand.cpp b/lib/Renderscript/RSForEachExpand.cpp
index 8185256..ec3d330 100644
--- a/lib/Renderscript/RSForEachExpand.cpp
+++ b/lib/Renderscript/RSForEachExpand.cpp
@@ -103,7 +103,7 @@
     // We only handle the case for legacy root() functions here, so this is
     // hard-coded to look at only the first such function.
     llvm::MDNode *SigNode = ExportForEachMetadata->getOperand(0);
-    if (SigNode != NULL && SigNode->getNumOperands() == 1) {
+    if (SigNode != nullptr && SigNode->getNumOperands() == 1) {
       llvm::Value *SigVal = SigNode->getOperand(0);
       if (SigVal->getValueID() == llvm::Value::MDStringVal) {
         llvm::StringRef SigString =
@@ -307,7 +307,7 @@
 
 public:
   RSForEachExpandPass(bool pEnableStepOpt)
-      : ModulePass(ID), Module(NULL), Context(NULL),
+      : ModulePass(ID), Module(nullptr), Context(nullptr),
         mEnableStepOpt(pEnableStepOpt) {
 
   }
@@ -348,8 +348,8 @@
     llvm::Value *Arg_x2      = &*(ExpandedFunctionArgIter++);
     llvm::Value *Arg_outstep = &*(ExpandedFunctionArgIter);
 
-    llvm::Value *InStep  = NULL;
-    llvm::Value *OutStep = NULL;
+    llvm::Value *InStep  = nullptr;
+    llvm::Value *OutStep = nullptr;
 
     // Construct the actual function body.
     llvm::IRBuilder<> Builder(ExpandedFunction->getEntryBlock().begin());
@@ -358,8 +358,8 @@
     // Note that we load any loop-invariant arguments before entering the Loop.
     llvm::Function::arg_iterator FunctionArgIter = Function->arg_begin();
 
-    llvm::Type  *InTy      = NULL;
-    llvm::Value *InBasePtr = NULL;
+    llvm::Type  *InTy      = nullptr;
+    llvm::Value *InBasePtr = nullptr;
     if (bcinfo::MetadataExtractor::hasForEachSignatureIn(Signature)) {
       llvm::Value    *InsMember  = Builder.CreateStructGEP(Arg_p,
                                                            PARAM_FIELD_INS);
@@ -385,8 +385,8 @@
       InBasePtr = Builder.CreateLoad(InputAddr, "input_base");
     }
 
-    llvm::Type *OutTy = NULL;
-    llvm::Value *OutBasePtr = NULL;
+    llvm::Type *OutTy = nullptr;
+    llvm::Value *OutBasePtr = nullptr;
     if (bcinfo::MetadataExtractor::hasForEachSignatureOut(Signature)) {
       OutTy = (FunctionArgIter++)->getType();
       OutStep = getStepValue(&DL, OutTy, Arg_outstep);
@@ -395,7 +395,7 @@
                      Builder.CreateStructGEP(Arg_p, PARAM_FIELD_OUT));
     }
 
-    llvm::Value *UsrData = NULL;
+    llvm::Value *UsrData = nullptr;
     if (bcinfo::MetadataExtractor::hasForEachSignatureUsrData(Signature)) {
       llvm::Type *UsrDataTy = (FunctionArgIter++)->getType();
       UsrData = Builder.CreatePointerCast(Builder.CreateLoad(
@@ -407,7 +407,7 @@
       FunctionArgIter++;
     }
 
-    llvm::Value *Y = NULL;
+    llvm::Value *Y = nullptr;
     if (bcinfo::MetadataExtractor::hasForEachSignatureY(Signature)) {
       Y = Builder.CreateLoad(
             Builder.CreateStructGEP(Arg_p, PARAM_FIELD_Y), "Y");
@@ -423,8 +423,8 @@
     // Populate the actual call to kernel().
     llvm::SmallVector<llvm::Value*, 8> RootArgs;
 
-    llvm::Value *InPtr  = NULL;
-    llvm::Value *OutPtr = NULL;
+    llvm::Value *InPtr  = nullptr;
+    llvm::Value *OutPtr = nullptr;
 
     // Calculate the current input and output pointers
     //
@@ -524,7 +524,7 @@
      */
     size_t NumInputs = Function->arg_size();
 
-    llvm::Value *Y = NULL;
+    llvm::Value *Y = nullptr;
     if (bcinfo::MetadataExtractor::hasForEachSignatureY(Signature)) {
       Y = Builder.CreateLoad(
             Builder.CreateStructGEP(Arg_p, PARAM_FIELD_Y), "Y");
@@ -543,9 +543,9 @@
     llvm::Function::arg_iterator ArgIter = Function->arg_begin();
 
     // Check the return type
-    llvm::Type     *OutTy      = NULL;
-    llvm::Value    *OutStep    = NULL;
-    llvm::LoadInst *OutBasePtr = NULL;
+    llvm::Type     *OutTy      = nullptr;
+    llvm::Value    *OutStep    = nullptr;
+    llvm::LoadInst *OutBasePtr = nullptr;
 
     bool PassOutByPointer = false;
 
@@ -651,7 +651,7 @@
 
     // Output
 
-    llvm::Value *OutPtr = NULL;
+    llvm::Value *OutPtr = nullptr;
     if (OutBasePtr) {
       llvm::Value *OutOffset = Builder.CreateSub(IV, Arg_x1);
 
diff --git a/lib/Renderscript/RSInfo.cpp b/lib/Renderscript/RSInfo.cpp
index bfc26d1..bd25327 100644
--- a/lib/Renderscript/RSInfo.cpp
+++ b/lib/Renderscript/RSInfo.cpp
@@ -88,7 +88,7 @@
     return true;
 }
 
-RSInfo::RSInfo(size_t pStringPoolSize) : mStringPool(NULL) {
+RSInfo::RSInfo(size_t pStringPoolSize) : mStringPool(nullptr) {
   ::memset(&mHeader, 0, sizeof(mHeader));
 
   ::memcpy(mHeader.magic, RSINFO_MAGIC, sizeof(mHeader.magic));
@@ -105,15 +105,15 @@
   if (pStringPoolSize > 0) {
     mHeader.strPoolSize = pStringPoolSize;
     mStringPool = new (std::nothrow) char [ mHeader.strPoolSize ];
-    if (mStringPool == NULL) {
+    if (mStringPool == nullptr) {
       ALOGE("Out of memory when allocate memory for string pool in RSInfo "
             "constructor (size: %u)!", mHeader.strPoolSize);
     }
     ::memset(mStringPool, 0, mHeader.strPoolSize);
   }
-  mSourceHash = NULL;
-  mCompileCommandLine = NULL;
-  mBuildFingerprint = NULL;
+  mSourceHash = nullptr;
+  mCompileCommandLine = nullptr;
+  mBuildFingerprint = nullptr;
 }
 
 RSInfo::~RSInfo() {
@@ -153,14 +153,16 @@
   ALOGV("\tHeader size: %u", mHeader.headerSize);
   ALOGV("\tString pool size: %u", mHeader.strPoolSize);
 
-  if (mSourceHash == NULL) {
+  if (mSourceHash == nullptr) {
       ALOGV("Source hash: NULL!");
   } else {
       ALOGV("Source hash: %s", stringFromSourceHash(mSourceHash).c_str());
   }
 
-  ALOGV("Compile Command Line: ", mCompileCommandLine ? mCompileCommandLine : "(NULL)");
-  ALOGV("mBuildFingerprint: ", mBuildFingerprint ? mBuildFingerprint : "(NULL)");
+  ALOGV("Compile Command Line: ", mCompileCommandLine ? mCompileCommandLine :
+                                                        "(NULL)");
+  ALOGV("mBuildFingerprint: ", mBuildFingerprint ? mBuildFingerprint :
+                                                   "(NULL)");
 
 #define DUMP_LIST_HEADER(_name, _header) do { \
   ALOGV(_name ":"); \
@@ -213,7 +215,7 @@
   if (pStrIdx >= mHeader.strPoolSize) {
     ALOGE("String index #%u is out of range in string pool (size: %u)!",
           pStrIdx, mHeader.strPoolSize);
-    return NULL;
+    return nullptr;
   }
   return &mStringPool[ pStrIdx ];
 }
diff --git a/lib/Renderscript/RSInfoExtractor.cpp b/lib/Renderscript/RSInfoExtractor.cpp
index d302cdf..bafce38 100644
--- a/lib/Renderscript/RSInfoExtractor.cpp
+++ b/lib/Renderscript/RSInfoExtractor.cpp
@@ -54,7 +54,7 @@
 const llvm::StringRef object_slot_metadata_name("#rs_object_slots");
 
 inline llvm::StringRef getStringFromOperand(const llvm::Value *pString) {
-  if ((pString != NULL) && (pString->getValueID() == llvm::Value::MDStringVal)) {
+  if ((pString != nullptr) && (pString->getValueID() == llvm::Value::MDStringVal)) {
     return static_cast<const llvm::MDString *>(pString)->getString();
   }
   return llvm::StringRef();
@@ -62,14 +62,14 @@
 
 template<size_t NumOperands>
 inline size_t getMetadataStringLength(const llvm::NamedMDNode *pMetadata) {
-  if (pMetadata == NULL) {
+  if (pMetadata == nullptr) {
     return 0;
   }
 
   size_t string_size = 0;
   for (unsigned i = 0, e = pMetadata->getNumOperands(); i < e; i++) {
     llvm::MDNode *node = pMetadata->getOperand(i);
-    if ((node != NULL) && (node->getNumOperands() >= NumOperands)) {
+    if ((node != nullptr) && (node->getNumOperands() >= NumOperands)) {
       // Compiler try its best to unroll this loop since NumOperands is a
       // template parameter (therefore the number of iteration can be determined
       // at compile-time and it's usually small.)
@@ -131,13 +131,13 @@
   size_t string_pool_size = 1;
   off_t cur_string_pool_offset = 0;
 
-  RSInfo *result = NULL;
+  RSInfo *result = nullptr;
 
   // Handle legacy case for pre-ICS bitcode that doesn't contain a metadata
   // section for ForEach. We generate a full signature for a "root" function.
-  if ((export_foreach_name == NULL) || (export_foreach_signature == NULL)) {
-    export_foreach_name = NULL;
-    export_foreach_signature = NULL;
+  if ((export_foreach_name == nullptr) || (export_foreach_signature == nullptr)) {
+    export_foreach_name = nullptr;
+    export_foreach_signature = nullptr;
     string_pool_size += 5;  // insert "root\0" for #rs_export_foreach_name
   }
 
@@ -153,13 +153,13 @@
 
   // Allocate result object
   result = new (std::nothrow) RSInfo(string_pool_size);
-  if (result == NULL) {
+  if (result == nullptr) {
     ALOGE("Out of memory when create RSInfo object for %s!", module_name);
     goto bail;
   }
 
   // Check string pool.
-  if (result->mStringPool == NULL) {
+  if (result->mStringPool == nullptr) {
     ALOGE("Out of memory when allocate string pool in RSInfo object for %s!",
           module_name);
     goto bail;
@@ -171,13 +171,13 @@
   // Populate all the strings and data.
 #define FOR_EACH_NODE_IN(_metadata, _node)  \
   for (unsigned i = 0, e = (_metadata)->getNumOperands(); i != e; i++)  \
-    if (((_node) = (_metadata)->getOperand(i)) != NULL)
+    if (((_node) = (_metadata)->getOperand(i)) != nullptr)
   //===--------------------------------------------------------------------===//
   // #pragma
   //===--------------------------------------------------------------------===//
   // Pragma is actually a key-value pair. The value can be an empty string while
   // the key cannot.
-  if (pragma != NULL) {
+  if (pragma != nullptr) {
     llvm::MDNode *node;
     FOR_EACH_NODE_IN(pragma, node) {
         llvm::StringRef key = getStringFromOperand(node->getOperand(0));
@@ -191,12 +191,12 @@
               writeString(val, result->mStringPool, &cur_string_pool_offset)));
         } // key.empty()
     } // FOR_EACH_NODE_IN
-  } // pragma != NULL
+  } // pragma != nullptr
 
   //===--------------------------------------------------------------------===//
   // #rs_export_var
   //===--------------------------------------------------------------------===//
-  if (export_var != NULL) {
+  if (export_var != nullptr) {
     llvm::MDNode *node;
     FOR_EACH_NODE_IN(export_var, node) {
       llvm::StringRef name = getStringFromOperand(node->getOperand(0));
@@ -213,7 +213,7 @@
   //===--------------------------------------------------------------------===//
   // #rs_export_func
   //===--------------------------------------------------------------------===//
-  if (export_func != NULL) {
+  if (export_func != nullptr) {
     llvm::MDNode *node;
     FOR_EACH_NODE_IN(export_func, node) {
       llvm::StringRef name = getStringFromOperand(node->getOperand(0));
@@ -245,7 +245,7 @@
   // for-eachable. In this case, #rs_export_foreach (the function name) and
   // #rs_export_foreach metadata (the signature) is one-to-one mapping among
   // their entries.
-  if ((export_foreach_name != NULL) && (export_foreach_signature != NULL)) {
+  if ((export_foreach_name != nullptr) && (export_foreach_signature != nullptr)) {
     unsigned num_foreach_function;
 
     // Should be one-to-one mapping.
@@ -264,15 +264,15 @@
       llvm::MDNode *signature_node = export_foreach_signature->getOperand(i);
 
       llvm::StringRef name, signature_string;
-      if (name_node != NULL) {
+      if (name_node != nullptr) {
         name = getStringFromOperand(name_node->getOperand(0));
       }
-      if (signature_node != NULL) {
+      if (signature_node != nullptr) {
         signature_string = getStringFromOperand(signature_node->getOperand(0));
       }
 
       if (!name.empty() && !signature_string.empty()) {
-        // Both name_node and signature_node are not NULL nodes.
+        // Both name_node and signature_node are not nullptr nodes.
         uint32_t signature;
         if (signature_string.getAsInteger(10, signature)) {
           ALOGE("Non-integer signature value '%s' for function %s found in %s!",
@@ -287,7 +287,7 @@
         // if both of them are empty.
         if (name.empty() && signature_string.empty()) {
           ALOGW("Entries #%u at #rs_export_foreach_name and #rs_export_foreach"
-                " are both NULL in %s! (skip)", i, module_name);
+                " are both nullptr in %s! (skip)", i, module_name);
           continue;
         } else {
           ALOGE("Entries #%u at %s is NULL in %s! (skip)", i,
@@ -309,7 +309,7 @@
   //===--------------------------------------------------------------------===//
   // #rs_object_slots
   //===--------------------------------------------------------------------===//
-  if (object_slots != NULL) {
+  if (object_slots != nullptr) {
     llvm::MDNode *node;
     for (unsigned int i = 0; i <= export_var->getNumOperands(); i++) {
       result->mObjectSlots.push_back(0);
@@ -360,7 +360,7 @@
   // The root context of the debug information in the bitcode is put under
   // the metadata named "llvm.dbg.cu".
   result->mHeader.hasDebugInformation =
-      static_cast<uint8_t>(module.getNamedMetadata("llvm.dbg.cu") != NULL);
+      static_cast<uint8_t>(module.getNamedMetadata("llvm.dbg.cu") != nullptr);
 
   assert((cur_string_pool_offset == string_pool_size) &&
             "Unexpected string pool size!");
@@ -369,5 +369,5 @@
 
 bail:
   delete result;
-  return NULL;
+  return nullptr;
 }
diff --git a/lib/Renderscript/RSInfoReader.cpp b/lib/Renderscript/RSInfoReader.cpp
index 00b0a3c..d997aac 100644
--- a/lib/Renderscript/RSInfoReader.cpp
+++ b/lib/Renderscript/RSInfoReader.cpp
@@ -46,12 +46,12 @@
   const char *key = pInfo.getStringFromPool(pItem.key);
   const char *value =pInfo.getStringFromPool(pItem.value);
 
-  if (key == NULL) {
+  if (key == nullptr) {
     ALOGE("Invalid string index %d for key in RS pragma list.", pItem.key);
     return false;
   }
 
-  if (value == NULL) {
+  if (value == nullptr) {
     ALOGE("Invalid string index %d for value in RS pragma list.", pItem.value);
     return false;
   }
@@ -80,7 +80,7 @@
 {
   const char *name = pInfo.getStringFromPool(pItem.name);
 
-  if (name == NULL) {
+  if (name == nullptr) {
     ALOGE("Invalid string index %d for name in RS export vars.", pItem.name);
     return false;
   }
@@ -98,7 +98,7 @@
 {
   const char *name = pInfo.getStringFromPool(pItem.name);
 
-  if (name == NULL) {
+  if (name == nullptr) {
     ALOGE("Invalid string index %d for name in RS export funcs.", pItem.name);
     return false;
   }
@@ -116,7 +116,7 @@
 {
   const char *name = pInfo.getStringFromPool(pItem.name);
 
-  if (name == NULL) {
+  if (name == nullptr) {
     ALOGE("Invalid string index %d for name in RS export foreachs.", pItem.name);
     return false;
   }
@@ -147,8 +147,8 @@
 } // end anonymous namespace
 
 RSInfo *RSInfo::ReadFromFile(InputFile &pInput) {
-  android::FileMap *map = NULL;
-  RSInfo *result = NULL;
+  android::FileMap *map = nullptr;
+  RSInfo *result = nullptr;
   const uint8_t *data;
   const rsinfo::Header *header;
   size_t filesize;
@@ -171,7 +171,7 @@
   // Create memory map for the file.
   map = pInput.createMap(/* pOffset */cur_input_offset,
                          /* pLength */filesize - cur_input_offset);
-  if (map == NULL) {
+  if (map == nullptr) {
     ALOGE("Failed to map RS info file %s to the memory! (%s)",
           input_filename, pInput.getErrorMessage().c_str());
     goto bail;
@@ -226,7 +226,7 @@
 
   // File seems ok, create result RSInfo object.
   result = new (std::nothrow) RSInfo(header->strPoolSize);
-  if (result == NULL) {
+  if (result == nullptr) {
     ALOGE("Out of memory when create RSInfo object for %s!", input_filename);
     goto bail;
   }
@@ -240,7 +240,7 @@
   if (header->strPoolSize > 0) {
     // Copy the string pool. The string pool is immediately after the header at
     // the offset header->headerSize.
-    if (result->mStringPool == NULL) {
+    if (result->mStringPool == nullptr) {
       ALOGE("Out of memory when allocate string pool for RS info file %s!",
             input_filename);
       goto bail;
@@ -252,19 +252,19 @@
   // Populate all the data to the result object.
   result->mSourceHash =
               reinterpret_cast<const uint8_t*>(result->getStringFromPool(header->sourceSha1Idx));
-  if (result->mSourceHash == NULL) {
+  if (result->mSourceHash == nullptr) {
       ALOGE("Invalid string index %d for SHA-1 checksum of source.", header->sourceSha1Idx);
       goto bail;
   }
 
   result->mCompileCommandLine = result->getStringFromPool(header->compileCommandLineIdx);
-  if (result->mCompileCommandLine == NULL) {
+  if (result->mCompileCommandLine == nullptr) {
       ALOGE("Invalid string index %d for compile command line.", header->compileCommandLineIdx);
       goto bail;
   }
 
   result->mBuildFingerprint = result->getStringFromPool(header->buildFingerprintIdx);
-  if (result->mBuildFingerprint == NULL) {
+  if (result->mBuildFingerprint == nullptr) {
       ALOGE("Invalid string index %d for build fingerprint.", header->buildFingerprintIdx);
       goto bail;
   }
@@ -300,11 +300,11 @@
   return result;
 
 bail:
-  if (map != NULL) {
+  if (map != nullptr) {
     map->release();
   }
 
   delete result;
 
-  return NULL;
+  return nullptr;
 } // RSInfo::ReadFromFile
diff --git a/lib/Renderscript/RSScript.cpp b/lib/Renderscript/RSScript.cpp
index 884de22..2dadc66 100644
--- a/lib/Renderscript/RSScript.cpp
+++ b/lib/Renderscript/RSScript.cpp
@@ -24,18 +24,18 @@
 using namespace bcc;
 
 bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) {
-  bccAssert(core_lib != NULL);
+  bccAssert(core_lib != nullptr);
 
   // Using the same context with the source in pScript.
   BCCContext &context = pScript.getSource().getContext();
 
   Source *libclcore_source = Source::CreateFromFile(context, core_lib);
-  if (libclcore_source == NULL) {
+  if (libclcore_source == nullptr) {
     ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
     return false;
   }
 
-  if (NULL != pScript.mLinkRuntimeCallback) {
+  if (pScript.mLinkRuntimeCallback != nullptr) {
     pScript.mLinkRuntimeCallback(&pScript,
         &pScript.getSource().getModule(), &libclcore_source->getModule());
   }
@@ -51,12 +51,12 @@
 }
 
 RSScript::RSScript(Source &pSource)
-  : Script(pSource), mInfo(NULL), mCompilerVersion(0),
-    mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(NULL),
+  : Script(pSource), mInfo(nullptr), mCompilerVersion(0),
+    mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr),
     mEmbedInfo(false) { }
 
 bool RSScript::doReset() {
-  mInfo = NULL;
+  mInfo = nullptr;
   mCompilerVersion = 0;
   mOptimizationLevel = kOptLvl3;
   return true;
diff --git a/lib/Support/CompilerConfig.cpp b/lib/Support/CompilerConfig.cpp
index 1411ce6..25ae709 100644
--- a/lib/Support/CompilerConfig.cpp
+++ b/lib/Support/CompilerConfig.cpp
@@ -28,7 +28,7 @@
 using namespace bcc;
 
 CompilerConfig::CompilerConfig(const std::string &pTriple)
-  : mTriple(pTriple), mFullPrecision(true), mTarget(NULL) {
+  : mTriple(pTriple), mFullPrecision(true), mTarget(nullptr) {
   //===--------------------------------------------------------------------===//
   // Default setting of register sheduler
   //===--------------------------------------------------------------------===//
@@ -79,7 +79,7 @@
 bool CompilerConfig::initializeTarget() {
   std::string error;
   mTarget = llvm::TargetRegistry::lookupTarget(mTriple, error);
-  if (mTarget != NULL) {
+  if (mTarget != nullptr) {
     return true;
   } else {
     ALOGE("Cannot initialize llvm::Target for given triple '%s'! (%s)",
@@ -89,7 +89,7 @@
 }
 
 bool CompilerConfig::initializeArch() {
-  if (mTarget != NULL) {
+  if (mTarget != nullptr) {
     mArchType = llvm::Triple::getArchTypeForLLVMName(mTarget->getName());
   } else {
     mArchType = llvm::Triple::UnknownArch;
diff --git a/lib/Support/Disassembler.cpp b/lib/Support/Disassembler.cpp
index e899df2..f1265aa 100644
--- a/lib/Support/Disassembler.cpp
+++ b/lib/Support/Disassembler.cpp
@@ -71,20 +71,20 @@
   DisassembleResult result = kDisassembleSuccess;
   uint64_t i = 0;
 
-  const llvm::MCSubtargetInfo *subtarget_info = NULL;
-  const llvm::MCDisassembler *disassembler = NULL;
-  const llvm::MCInstrInfo *mc_inst_info = NULL;
-  const llvm::MCRegisterInfo *mc_reg_info = NULL;
-  const llvm::MCAsmInfo *asm_info = NULL;
-  llvm::MCInstPrinter *inst_printer = NULL;
+  const llvm::MCSubtargetInfo *subtarget_info = nullptr;
+  const llvm::MCDisassembler *disassembler = nullptr;
+  const llvm::MCInstrInfo *mc_inst_info = nullptr;
+  const llvm::MCRegisterInfo *mc_reg_info = nullptr;
+  const llvm::MCAsmInfo *asm_info = nullptr;
+  llvm::MCInstPrinter *inst_printer = nullptr;
 
-  BufferMemoryObject *input_function = NULL;
+  BufferMemoryObject *input_function = nullptr;
 
   std::string error;
   const llvm::Target* target =
       llvm::TargetRegistry::lookupTarget(pTriple, error);
 
-  if (target == NULL) {
+  if (target == nullptr) {
     ALOGE("Invalid target triple for disassembler: %s (%s)!",
           pTriple, error.c_str());
     return kDisassembleUnknownTarget;
@@ -93,7 +93,7 @@
   subtarget_info =
       target->createMCSubtargetInfo(pTriple, /* CPU */"", /* Features */"");;
 
-  if (subtarget_info == NULL) {
+  if (subtarget_info == nullptr) {
     result = kDisassembleFailedSetup;
     goto bail;
   }
@@ -106,8 +106,8 @@
 
   asm_info = target->createMCAsmInfo(pTriple);
 
-  if ((disassembler == NULL) || (mc_inst_info == NULL) ||
-      (mc_reg_info == NULL) || (asm_info == NULL)) {
+  if ((disassembler == nullptr) || (mc_inst_info == nullptr) ||
+      (mc_reg_info == nullptr) || (asm_info == nullptr)) {
     result = kDisassembleFailedSetup;
     goto bail;
   }
@@ -116,14 +116,14 @@
                                              *asm_info, *mc_inst_info,
                                              *mc_reg_info, *subtarget_info);
 
-  if (inst_printer == NULL) {
+  if (inst_printer == nullptr) {
     result = kDisassembleFailedSetup;
     goto bail;
   }
 
   input_function = new (std::nothrow) BufferMemoryObject(pFunc, pFuncSize);
 
-  if (input_function == NULL) {
+  if (input_function == nullptr) {
     result = kDisassembleOutOfMemory;
     goto bail;
   }
@@ -193,7 +193,7 @@
 
   // Open the output file decorated in llvm::raw_ostream.
   llvm::raw_ostream *output = pOutput.dup();
-  if (output == NULL) {
+  if (output == nullptr) {
     return kDisassembleFailedPrepareOutput;
   }
 
diff --git a/lib/Support/FileBase.cpp b/lib/Support/FileBase.cpp
index bca2775..05e8c37 100644
--- a/lib/Support/FileBase.cpp
+++ b/lib/Support/FileBase.cpp
@@ -225,19 +225,19 @@
 android::FileMap *FileBase::createMap(off_t pOffset, size_t pLength,
                                       bool pIsReadOnly) {
   if (mFD < 0 || hasError()) {
-    return NULL;
+    return nullptr;
   }
 
   android::FileMap *map = new (std::nothrow) android::FileMap();
-  if (map == NULL) {
+  if (map == nullptr) {
     mError = make_error_code(std::errc::not_enough_memory);
-    return NULL;
+    return nullptr;
   }
 
-  if (!map->create(NULL, mFD, pOffset, pLength, pIsReadOnly)) {
+  if (!map->create(nullptr, mFD, pOffset, pLength, pIsReadOnly)) {
     detectError();
     map->release();
-    return NULL;
+    return nullptr;
   }
 
   return map;
diff --git a/lib/Support/Initialization.cpp b/lib/Support/Initialization.cpp
index 6ad4f48..5d32385 100644
--- a/lib/Support/Initialization.cpp
+++ b/lib/Support/Initialization.cpp
@@ -43,7 +43,7 @@
 
   // Setup error handler for LLVM.
   llvm::remove_fatal_error_handler();
-  llvm::install_fatal_error_handler(llvm_error_handler, NULL);
+  llvm::install_fatal_error_handler(llvm_error_handler, nullptr);
 
 #if defined(PROVIDE_ARM_CODEGEN)
   LLVMInitializeARMAsmPrinter();
diff --git a/lib/Support/InputFile.cpp b/lib/Support/InputFile.cpp
index 054edc7..5701d20 100644
--- a/lib/Support/InputFile.cpp
+++ b/lib/Support/InputFile.cpp
@@ -28,7 +28,7 @@
     return -1;
   }
 
-  if ((count <= 0) || (pBuf == NULL)) {
+  if ((count <= 0) || (pBuf == nullptr)) {
     // Keep safe and issue a warning.
     ALOGW("InputFile::read: count = %zu, buffer = %p", count, pBuf);
     return 0;
diff --git a/lib/Support/OutputFile.cpp b/lib/Support/OutputFile.cpp
index e1dbf06..dab02b9 100644
--- a/lib/Support/OutputFile.cpp
+++ b/lib/Support/OutputFile.cpp
@@ -32,7 +32,7 @@
     return -1;
   }
 
-  if ((count <= 0) || (pBuf == NULL)) {
+  if ((count <= 0) || (pBuf == nullptr)) {
     // Keep safe and issue a warning.
     ALOGW("OutputFile::write: count = %zu, buffer = %p", count, pBuf);
     return 0;
@@ -79,7 +79,7 @@
     if (newfd < 0) {
       if (errno != EINTR) {
         detectError();
-        return NULL;
+        return nullptr;
       }
       // EINTR
       continue;
@@ -91,7 +91,7 @@
   llvm::raw_fd_ostream *result =
       new (std::nothrow) llvm::raw_fd_ostream(newfd, /* shouldClose */true);
 
-  if (result == NULL) {
+  if (result == nullptr) {
     mError = std::make_error_code(std::errc::not_enough_memory);
   }