[ORC] Fix ORC on platforms without indirection support.

Previously this crashed because a nullptr (returned by
createLocalIndirectStubsManagerBuilder() on platforms without
indirection support) functor was unconditionally invoked.

Patch by Andres Freund. Thanks Andres!

llvm-svn: 328687
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
index f053407..fe3f694 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcCAPITest.cpp
@@ -86,7 +86,7 @@
 char *OrcCAPIExecutionTest::testFuncName = nullptr;
 
 TEST_F(OrcCAPIExecutionTest, TestEagerIRCompilation) {
-  if (!TM)
+  if (!SupportsJIT)
     return;
 
   LLVMOrcJITStackRef JIT =
@@ -112,7 +112,7 @@
 }
 
 TEST_F(OrcCAPIExecutionTest, TestLazyIRCompilation) {
-  if (!TM)
+  if (!SupportsIndirection)
     return;
 
   LLVMOrcJITStackRef JIT =
@@ -138,7 +138,7 @@
 }
 
 TEST_F(OrcCAPIExecutionTest, TestAddObjectFile) {
-  if (!TM)
+  if (!SupportsJIT)
     return;
 
   auto ObjBuffer = createTestObject();
@@ -163,7 +163,7 @@
 }
 
 TEST_F(OrcCAPIExecutionTest, TestDirectCallbacksAPI) {
-  if (!TM)
+  if (!SupportsIndirection)
     return;
 
   LLVMOrcJITStackRef JIT =
diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
index 28a5f08..108e275 100644
--- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
+++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h
@@ -17,6 +17,7 @@
 
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
+#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/LLVMContext.h"
@@ -24,6 +25,7 @@
 #include "llvm/IR/TypeBuilder.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/TargetRegistry.h"
 #include <memory>
 
 namespace llvm {
@@ -59,15 +61,20 @@
       // If we found a TargetMachine, check that it's one that Orc supports.
       const Triple& TT = TM->getTargetTriple();
 
-      if ((TT.getArch() != Triple::x86_64 && TT.getArch() != Triple::x86) ||
-          TT.isOSWindows())
-        TM = nullptr;
+      // Target can JIT?
+      SupportsJIT = TM->getTarget().hasJIT();
+      // Use ability to create callback manager to detect whether Orc
+      // has indirection support on this platform. This way the test
+      // and Orc code do not get out of sync.
+      SupportsIndirection = !!orc::createLocalCompileCallbackManager(TT, 0);
     }
   };
 
 protected:
   LLVMContext Context;
   std::unique_ptr<TargetMachine> TM;
+  bool SupportsJIT = false;
+  bool SupportsIndirection = false;
 };
 
 class ModuleBuilder {
diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
index 2156ae8..f52ee6b 100644
--- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
+++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayerTest.cpp
@@ -121,7 +121,7 @@
 }
 
 TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoDuplicateFinalization) {
-  if (!TM)
+  if (!SupportsJIT)
     return;
 
   SymbolStringPool SSP;
@@ -206,7 +206,7 @@
 }
 
 TEST_F(RTDyldObjectLinkingLayerExecutionTest, NoPrematureAllocation) {
-  if (!TM)
+  if (!SupportsJIT)
     return;
 
   SymbolStringPool SSP;