[llvm] 3b08b33 - [RISCV][test] Fix lifetime bug with Module in test
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 18 03:46:38 PST 2023
Author: Alex Bradbury
Date: 2023-12-18T11:45:21Z
New Revision: 3b08b3340d5adbd001cd1b328f6fd6ecf5d92f4a
URL: https://github.com/llvm/llvm-project/commit/3b08b3340d5adbd001cd1b328f6fd6ecf5d92f4a
DIFF: https://github.com/llvm/llvm-project/commit/3b08b3340d5adbd001cd1b328f6fd6ecf5d92f4a.diff
LOG: [RISCV][test] Fix lifetime bug with Module in test
As pointed out by @s-barannikov in post-commit review of #72356, the
module is destroyed at the end of the constructor.
Added:
Modified:
llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp b/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
index b4c96a9c2a62ce..5ef86bb3f7b46e 100644
--- a/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
+++ b/llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp
@@ -31,6 +31,7 @@ class RISCVInstrInfoTest : public testing::TestWithParam<const char *> {
std::unique_ptr<RISCVSubtarget> ST;
std::unique_ptr<MachineModuleInfo> MMI;
std::unique_ptr<MachineFunction> MF;
+ std::unique_ptr<Module> M;
static void SetUpTestSuite() {
LLVMInitializeRISCVTargetInfo();
@@ -49,10 +50,10 @@ class RISCVInstrInfoTest : public testing::TestWithParam<const char *> {
CodeGenOptLevel::Default)));
Ctx = std::make_unique<LLVMContext>();
- Module M("Module", *Ctx);
- M.setDataLayout(TM->createDataLayout());
+ M = std::make_unique<Module>("Module", *Ctx);
+ M->setDataLayout(TM->createDataLayout());
auto *FType = FunctionType::get(Type::getVoidTy(*Ctx), false);
- auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", &M);
+ auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
MMI = std::make_unique<MachineModuleInfo>(TM.get());
ST = std::make_unique<RISCVSubtarget>(
More information about the llvm-commits
mailing list