//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/OwningPtr.h"
+#include "MCJITTestBase.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
-#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/ExecutionEngine/ObjectCache.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
-#include "MCJITTestBase.h"
#include "gtest/gtest.h"
using namespace llvm;
virtual ~TestObjectCache() {
// Free any buffers we've allocated.
- SmallVector<MemoryBuffer *, 2>::iterator it, end;
+ SmallVectorImpl<MemoryBuffer *>::iterator it, end;
end = AllocatedBuffers.end();
for (it = AllocatedBuffers.begin(); it != end; ++it) {
delete *it;
const MemoryBuffer* BufferFound = getObjectInternal(M);
ModulesLookedUp.insert(M->getModuleIdentifier());
if (!BufferFound)
- return NULL;
+ return nullptr;
// Our test cache wants to maintain ownership of its object buffers
// so we make a copy here for the execution engine.
return MemoryBuffer::getMemBufferCopy(BufferFound->getBuffer());
const std::string ModuleID = M->getModuleIdentifier();
StringMap<const MemoryBuffer *>::iterator it = ObjMap.find(ModuleID);
if (it == ObjMap.end())
- return 0;
+ return nullptr;
return it->second;
}
void compileAndRun(int ExpectedRC = OriginalRC) {
// This function shouldn't be called until after SetUp.
- ASSERT_TRUE(TheJIT.isValid());
- ASSERT_TRUE(0 != Main);
+ ASSERT_TRUE(bool(TheJIT));
+ ASSERT_TRUE(nullptr != Main);
// We may be using a null cache, so ensure compilation is valid.
TheJIT->finalizeObject();
void *vPtr = TheJIT->getPointerToFunction(Main);
- EXPECT_TRUE(0 != vPtr)
+ EXPECT_TRUE(nullptr != vPtr)
<< "Unable to get pointer to main() from JIT";
int (*FuncPtr)(void) = (int(*)(void))(intptr_t)vPtr;
TEST_F(MCJITObjectCacheTest, SetNullObjectCache) {
SKIP_UNSUPPORTED_PLATFORM;
- createJIT(M.take());
+ createJIT(M.release());
- TheJIT->setObjectCache(NULL);
+ TheJIT->setObjectCache(nullptr);
compileAndRun();
}
TEST_F(MCJITObjectCacheTest, VerifyBasicObjectCaching) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<TestObjectCache> Cache(new TestObjectCache);
+ std::unique_ptr<TestObjectCache> Cache(new TestObjectCache);
// Save a copy of the module pointer before handing it off to MCJIT.
const Module * SavedModulePointer = M.get();
- createJIT(M.take());
+ createJIT(M.release());
TheJIT->setObjectCache(Cache.get());
// Verify that our object cache does not contain the module yet.
const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SavedModulePointer);
- EXPECT_EQ(0, ObjBuffer);
+ EXPECT_EQ(nullptr, ObjBuffer);
compileAndRun();
// Verify that our object cache now contains the module.
ObjBuffer = Cache->getObjectInternal(SavedModulePointer);
- EXPECT_TRUE(0 != ObjBuffer);
+ EXPECT_TRUE(nullptr != ObjBuffer);
// Verify that the cache was only notified once.
EXPECT_FALSE(Cache->wereDuplicatesInserted());
TEST_F(MCJITObjectCacheTest, VerifyLoadFromCache) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<TestObjectCache> Cache(new TestObjectCache);
+ std::unique_ptr<TestObjectCache> Cache(new TestObjectCache);
// Compile this module with an MCJIT engine
- createJIT(M.take());
+ createJIT(M.release());
TheJIT->setObjectCache(Cache.get());
TheJIT->finalizeObject();
const Module * SecondModulePointer = M.get();
// Create a new MCJIT instance to load this module then execute it.
- createJIT(M.take());
+ createJIT(M.release());
TheJIT->setObjectCache(Cache.get());
compileAndRun();
TEST_F(MCJITObjectCacheTest, VerifyNonLoadFromCache) {
SKIP_UNSUPPORTED_PLATFORM;
- OwningPtr<TestObjectCache> Cache(new TestObjectCache);
+ std::unique_ptr<TestObjectCache> Cache(new TestObjectCache);
// Compile this module with an MCJIT engine
- createJIT(M.take());
+ createJIT(M.release());
TheJIT->setObjectCache(Cache.get());
TheJIT->finalizeObject();
const Module * SecondModulePointer = M.get();
// Create a new MCJIT instance to load this module then execute it.
- createJIT(M.take());
+ createJIT(M.release());
TheJIT->setObjectCache(Cache.get());
// Verify that our object cache does not contain the module yet.
const MemoryBuffer *ObjBuffer = Cache->getObjectInternal(SecondModulePointer);
- EXPECT_EQ(0, ObjBuffer);
+ EXPECT_EQ(nullptr, ObjBuffer);
// Run the function and look for the replacement return code.
compileAndRun(ReplacementRC);
// Verify that our object cache now contains the module.
ObjBuffer = Cache->getObjectInternal(SecondModulePointer);
- EXPECT_TRUE(0 != ObjBuffer);
+ EXPECT_TRUE(nullptr != ObjBuffer);
// Verify that MCJIT didn't try to cache this again.
EXPECT_FALSE(Cache->wereDuplicatesInserted());