Skip to content

Commit 566fbb4

Browse files
authored
[RISCV] Defer creating RISCVInsertVSETVLI to avoid leak with -stop-after (#92303)
As noted in #91440 (comment), if the pass pipeline stops early because of -stop-after any allocated passes added with insertPass will not be freed if they haven't already been added. This was showing up as a failure on the address sanitizer buildbots. We can fix it by instead passing the pass ID instead so that allocation is deferred.
1 parent 6bf1859 commit 566fbb4

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

llvm/lib/Target/RISCV/RISCV.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void initializeRISCVExpandAtomicPseudoPass(PassRegistry &);
6060

6161
FunctionPass *createRISCVInsertVSETVLIPass();
6262
void initializeRISCVInsertVSETVLIPass(PassRegistry &);
63+
extern char &RISCVInsertVSETVLIID;
6364

6465
FunctionPass *createRISCVCoalesceVSETVLIPass();
6566
void initializeRISCVCoalesceVSETVLIPass(PassRegistry &);

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ class RISCVCoalesceVSETVLI : public MachineFunctionPass {
868868
} // end anonymous namespace
869869

870870
char RISCVInsertVSETVLI::ID = 0;
871+
char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
871872

872873
INITIALIZE_PASS(RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
873874
false, false)

llvm/lib/Target/RISCV/RISCVTargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,9 @@ void RISCVPassConfig::addPreRegAlloc() {
548548
// Run RISCVInsertVSETVLI after PHI elimination. On O1 and above do it after
549549
// register coalescing so needVSETVLIPHI doesn't need to look through COPYs.
550550
if (TM->getOptLevel() == CodeGenOptLevel::None)
551-
insertPass(&PHIEliminationID, createRISCVInsertVSETVLIPass());
551+
insertPass(&PHIEliminationID, &RISCVInsertVSETVLIID);
552552
else
553-
insertPass(&RegisterCoalescerID, createRISCVInsertVSETVLIPass());
553+
insertPass(&RegisterCoalescerID, &RISCVInsertVSETVLIID);
554554
}
555555

556556
void RISCVPassConfig::addFastRegAlloc() {

0 commit comments

Comments
 (0)