https://github.com/MaskRay updated 
https://github.com/llvm/llvm-project/pull/180464

>From 3d2353bfd10a43748b9d99aa1cfecec01dc89120 Mon Sep 17 00:00:00 2001
From: Fangrui Song <[email protected]>
Date: Sun, 8 Feb 2026 21:23:29 -0800
Subject: [PATCH] fix unittest

Created using spr 1.3.5-bogner
---
 llvm/unittests/CodeGen/MFCommon.inc           | 8 +++++++-
 llvm/unittests/CodeGen/MachineInstrTest.cpp   | 3 +++
 llvm/unittests/CodeGen/MachineOperandTest.cpp | 2 ++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/llvm/unittests/CodeGen/MFCommon.inc 
b/llvm/unittests/CodeGen/MFCommon.inc
index c5e1c747bce32..2e91675a08d69 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -118,7 +118,13 @@ public:
       : CodeGenTargetMachineImpl(
             Target(), "", Triple(""), "", "", 
getTargetOptionsForBogusMachine(),
             Reloc::Static, CodeModel::Small, CodeGenOptLevel::Default),
-        ST(*this) {}
+        ST(*this) {
+    // The empty Target() has no MCAsmInfoCtorFn, so createMCAsmInfo returns
+    // null. Provide a default MCAsmInfo so that MCContext can be created.
+    auto MAI = std::make_unique<MCAsmInfo>();
+    MAI->setTargetOptions(Options.MCOptions);
+    AsmInfo = std::move(MAI);
+  }
 
   ~BogusTargetMachine() override = default;
 
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp 
b/llvm/unittests/CodeGen/MachineInstrTest.cpp
index ab28963b39311..f587dabd695bd 100644
--- a/llvm/unittests/CodeGen/MachineInstrTest.cpp
+++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp
@@ -37,7 +37,10 @@ namespace {
 // Include helper functions to ease the manipulation of MachineFunctions.
 #include "MFCommon.inc"
 
+MCTargetOptions MCOptions;
+
 std::unique_ptr<MCContext> createMCContext(MCAsmInfo *AsmInfo) {
+  AsmInfo->setTargetOptions(MCOptions);
   Triple TheTriple(/*ArchStr=*/"", /*VendorStr=*/"", /*OSStr=*/"",
                    /*EnvironmentStr=*/"elf");
   return std::make_unique<MCContext>(TheTriple, AsmInfo, nullptr, nullptr,
diff --git a/llvm/unittests/CodeGen/MachineOperandTest.cpp 
b/llvm/unittests/CodeGen/MachineOperandTest.cpp
index c0b2b1895975a..23b896cfd8265 100644
--- a/llvm/unittests/CodeGen/MachineOperandTest.cpp
+++ b/llvm/unittests/CodeGen/MachineOperandTest.cpp
@@ -349,7 +349,9 @@ TEST(MachineOperandTest, PrintMetadata) {
 }
 
 TEST(MachineOperandTest, PrintMCSymbol) {
+  MCTargetOptions MCOptions;
   MCAsmInfo MAI;
+  MAI.setTargetOptions(MCOptions);
   Triple T = Triple("unknown-unknown-unknown");
   MCContext Ctx(T, &MAI, /*MRI=*/nullptr, /*MSTI=*/nullptr);
   MCSymbol *Sym = Ctx.getOrCreateSymbol("foo");

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to