[C++11] Use 'nullptr'.
[oota-llvm.git] / unittests / ExecutionEngine / JIT / MultiJITTest.cpp
index 4018cd5ce2f2c94408650514a031557f60e49df7..f530e0de5d51f1186cb8b4f2633679596dc50cdb 100644 (file)
@@ -8,7 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ExecutionEngine/JIT.h"
-#include "llvm/Assembly/Parser.h"
+#include "llvm/AsmParser/Parser.h"
 #include "llvm/ExecutionEngine/GenericValue.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
@@ -21,12 +21,13 @@ using namespace llvm;
 namespace {
 
 // ARM, PowerPC and SystemZ tests disabled pending fix for PR10783.
-#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__)
+#if !defined(__arm__) && !defined(__powerpc__) && !defined(__s390__) \
+                      && !defined(__aarch64__)
 
 bool LoadAssemblyInto(Module *M, const char *assembly) {
   SMDiagnostic Error;
   bool success =
-    NULL != ParseAssemblyString(assembly, M, Error, M->getContext());
+    nullptr != ParseAssemblyString(assembly, M, Error, M->getContext());
   std::string errMsg;
   raw_string_ostream os(errMsg);
   Error.print("", os);
@@ -70,19 +71,19 @@ void createModule2(LLVMContext &Context2, Module *&M2, Function *&FooF2) {
 
 TEST(MultiJitTest, EagerMode) {
   LLVMContext Context1;
-  Module *M1 = 0;
-  Function *FooF1 = 0;
+  Module *M1 = nullptr;
+  Function *FooF1 = nullptr;
   createModule1(Context1, M1, FooF1);
 
   LLVMContext Context2;
-  Module *M2 = 0;
-  Function *FooF2 = 0;
+  Module *M2 = nullptr;
+  Function *FooF2 = nullptr;
   createModule2(Context2, M2, FooF2);
 
   // Now we create the JIT in eager mode
-  OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create());
+  std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create());
   EE1->DisableLazyCompilation(true);
-  OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create());
+  std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create());
   EE2->DisableLazyCompilation(true);
 
   // Call the `foo' function with no arguments:
@@ -100,19 +101,19 @@ TEST(MultiJitTest, EagerMode) {
 
 TEST(MultiJitTest, LazyMode) {
   LLVMContext Context1;
-  Module *M1 = 0;
-  Function *FooF1 = 0;
+  Module *M1 = nullptr;
+  Function *FooF1 = nullptr;
   createModule1(Context1, M1, FooF1);
 
   LLVMContext Context2;
-  Module *M2 = 0;
-  Function *FooF2 = 0;
+  Module *M2 = nullptr;
+  Function *FooF2 = nullptr;
   createModule2(Context2, M2, FooF2);
 
   // Now we create the JIT in lazy mode
-  OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create());
+  std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create());
   EE1->DisableLazyCompilation(false);
-  OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create());
+  std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create());
   EE2->DisableLazyCompilation(false);
 
   // Call the `foo' function with no arguments:
@@ -134,18 +135,18 @@ extern "C" {
 
 TEST(MultiJitTest, JitPool) {
   LLVMContext Context1;
-  Module *M1 = 0;
-  Function *FooF1 = 0;
+  Module *M1 = nullptr;
+  Function *FooF1 = nullptr;
   createModule1(Context1, M1, FooF1);
 
   LLVMContext Context2;
-  Module *M2 = 0;
-  Function *FooF2 = 0;
+  Module *M2 = nullptr;
+  Function *FooF2 = nullptr;
   createModule2(Context2, M2, FooF2);
 
   // Now we create two JITs
-  OwningPtr<ExecutionEngine> EE1(EngineBuilder(M1).create());
-  OwningPtr<ExecutionEngine> EE2(EngineBuilder(M2).create());
+  std::unique_ptr<ExecutionEngine> EE1(EngineBuilder(M1).create());
+  std::unique_ptr<ExecutionEngine> EE2(EngineBuilder(M2).create());
 
   Function *F1 = EE1->FindFunctionNamed("foo1");
   void *foo1 = EE1->getPointerToFunction(F1);
@@ -173,6 +174,14 @@ TEST(MultiJitTest, JitPool) {
     EXPECT_TRUE(fa != 0);
     fa = *(intptr_t *)fa;       // Bound value of IAT
   }
+#elif defined(__x86_64__)
+  // getPointerToNamedFunction might be indirect jump
+  // on Win32 x64 --enable-shared.
+  // FF 25 <pcrel32>: jmp *(RIP + pointer to IAT)
+  if (sa != fa && memcmp((char *)fa, "\xFF\x25", 2) == 0) {
+    fa += *(int32_t *)(fa + 2) + 6;     // Address to IAT(RIP)
+    fa = *(intptr_t *)fa;               // Bound value of IAT
+  }
 #endif
   EXPECT_TRUE(sa == fa);
 }