[llvm-branch-commits] [llvm] [MC] Move MCTargetOptions pointer from MCContext to MCAsmInfo (PR #180464)
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Feb 17 21:49:22 PST 2026
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 <i at maskray.me>
Date: Sun, 8 Feb 2026 21:23:29 -0800
Subject: [PATCH 1/2] 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");
>From 3b76dabb31797902c3e65d6e0ced0f9d108a1020 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 8 Feb 2026 23:19:34 -0800
Subject: [PATCH 2/2] BogusTargetmachine comment
Created using spr 1.3.5-bogner
---
llvm/unittests/CodeGen/MFCommon.inc | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/unittests/CodeGen/MFCommon.inc b/llvm/unittests/CodeGen/MFCommon.inc
index 2e91675a08d69..27f4c5163a111 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -119,11 +119,11 @@ public:
Target(), "", Triple(""), "", "", getTargetOptionsForBogusMachine(),
Reloc::Static, CodeModel::Small, CodeGenOptLevel::Default),
ST(*this) {
- // The empty Target() has no MCAsmInfoCtorFn, so createMCAsmInfo returns
- // null. Provide a default MCAsmInfo so that MCContext can be created.
+ // With an empty Triple, `initAsmInfo` cannot be called. Provide a
+ // default MCAsmInfo so that MCContext can be created.
auto MAI = std::make_unique<MCAsmInfo>();
+ AsmInfo = std::make_unique<MCAsmInfo>();
MAI->setTargetOptions(Options.MCOptions);
- AsmInfo = std::move(MAI);
}
~BogusTargetMachine() override = default;
More information about the llvm-branch-commits
mailing list