[PATCH] D67089: Skip MCJIT unit tests if LLVM is not configured for native compilation

Sergej Jaskiewicz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 02:55:02 PDT 2019


broadwaylamb created this revision.
broadwaylamb added reviewers: dblaikie, lhames, andrew.w.kaylor.
broadwaylamb added a project: LLVM.
Herald added subscribers: kristof.beyls, javed.absar.

When running MCJIT unit test, ensure that the host target is something LLVM can generate code for.

Without this change, the tests could fail if LLVM was configured for cross-compilation e. g. from x86 to ARM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67089

Files:
  llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h


Index: llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
===================================================================
--- llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
+++ llvm/unittests/ExecutionEngine/MCJIT/MCJITTestAPICommon.h
@@ -21,13 +21,14 @@
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/TargetRegistry.h"
 
 // Used to skip tests on unsupported architectures and operating systems.
 // To skip a test, add this macro at the top of a test-case in a suite that
 // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
 #define SKIP_UNSUPPORTED_PLATFORM \
   do \
-    if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
+    if (!ArchSupportsMCJIT() || !OSSupportsMCJIT() || !HostCanBeTargeted()) \
       return; \
   while(0)
 
@@ -36,7 +37,7 @@
 class MCJITTestAPICommon {
 protected:
   MCJITTestAPICommon()
-    : HostTriple(sys::getDefaultTargetTriple())
+    : HostTriple(sys::getProcessTriple())
   {
     InitializeNativeTarget();
     InitializeNativeTargetAsmPrinter();
@@ -52,6 +53,11 @@
     HostTriple = Triple::normalize(HostTriple);
   }
 
+  bool HostCanBeTargeted() {
+    std::string Error;
+	return TargetRegistry::lookupTarget(HostTriple, Error) != 0;
+  }
+
   /// Returns true if the host architecture is known to support MCJIT
   bool ArchSupportsMCJIT() {
     Triple Host(HostTriple);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67089.218417.patch
Type: text/x-patch
Size: 1437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190903/f5ce4982/attachment.bin>


More information about the llvm-commits mailing list