[llvm] [MIR2Vec] Fixing non x86 unittest failures (PR #162381)

S. VenkataKeerthy via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 7 15:12:34 PDT 2025


================
@@ -54,27 +54,31 @@ class MIR2VecVocabTestFixture : public ::testing::Test {
   std::unique_ptr<TargetMachine> TM;
   const TargetInstrInfo *TII;
 
+  static void SetUpTestCase() {
+    InitializeAllTargets();
+    InitializeAllTargetMCs();
+  }
+
   void SetUp() override {
-    LLVMInitializeX86TargetInfo();
-    LLVMInitializeX86Target();
-    LLVMInitializeX86TargetMC();
+    Triple TargetTriple("x86_64-unknown-linux-gnu");
+    std::string Error;
+    const Target *T = TargetRegistry::lookupTarget("", TargetTriple, Error);
+    if (!T) {
+      GTEST_SKIP();
+      return;
+    }
 
     Ctx = std::make_unique<LLVMContext>();
     M = std::make_unique<Module>("test", *Ctx);
-
-    // Set up X86 target
-    Triple TargetTriple("x86_64-unknown-linux-gnu");
     M->setTargetTriple(TargetTriple);
 
-    std::string Error;
-    const Target *TheTarget =
-        TargetRegistry::lookupTarget(M->getTargetTriple(), Error);
-    ASSERT_TRUE(TheTarget) << "Failed to lookup target: " << Error;
-
     TargetOptions Options;
-    TM = std::unique_ptr<TargetMachine>(TheTarget->createTargetMachine(
-        M->getTargetTriple(), "", "", Options, Reloc::Model::Static));
-    ASSERT_TRUE(TM);
+    TM = std::unique_ptr<TargetMachine>(
+        T->createTargetMachine(TargetTriple, "", "", Options, std::nullopt));
----------------
svkeerthy wrote:

Just being conservative here to skip such tests, as I was not completely sure if TM cannot not be nullptr if T is valid. 

https://github.com/llvm/llvm-project/pull/162381


More information about the llvm-commits mailing list