Skip to content

Commit 3b08b33

Browse files
committed
[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.
1 parent 9c18f03 commit 3b08b33

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class RISCVInstrInfoTest : public testing::TestWithParam<const char *> {
3131
std::unique_ptr<RISCVSubtarget> ST;
3232
std::unique_ptr<MachineModuleInfo> MMI;
3333
std::unique_ptr<MachineFunction> MF;
34+
std::unique_ptr<Module> M;
3435

3536
static void SetUpTestSuite() {
3637
LLVMInitializeRISCVTargetInfo();
@@ -49,10 +50,10 @@ class RISCVInstrInfoTest : public testing::TestWithParam<const char *> {
4950
CodeGenOptLevel::Default)));
5051

5152
Ctx = std::make_unique<LLVMContext>();
52-
Module M("Module", *Ctx);
53-
M.setDataLayout(TM->createDataLayout());
53+
M = std::make_unique<Module>("Module", *Ctx);
54+
M->setDataLayout(TM->createDataLayout());
5455
auto *FType = FunctionType::get(Type::getVoidTy(*Ctx), false);
55-
auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", &M);
56+
auto *F = Function::Create(FType, GlobalValue::ExternalLinkage, "Test", *M);
5657
MMI = std::make_unique<MachineModuleInfo>(TM.get());
5758

5859
ST = std::make_unique<RISCVSubtarget>(

0 commit comments

Comments
 (0)