[PATCH] D157468: [RISCV] Add bounds check before use on returned iterator.
Anmol P. Paralkar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 8 18:47:03 PDT 2023
anmolparalkar-nxp created this revision.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, arichardson.
Herald added a project: All.
anmolparalkar-nxp requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.
Check iterator validity before use; fixes crash on internal benchmark.
https://reviews.llvm.org/D157468
Files:
llvm/lib/Target/RISCV/RISCVPushPopOptimizer.cpp
Index: llvm/lib/Target/RISCV/RISCVPushPopOptimizer.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVPushPopOptimizer.cpp
+++ llvm/lib/Target/RISCV/RISCVPushPopOptimizer.cpp
@@ -132,8 +132,10 @@
for (auto &MBB : Fn) {
MachineBasicBlock::iterator MBBI = containsPop(MBB);
MachineBasicBlock::iterator NextI = next_nodbg(MBBI, MBB.end());
- if (MBBI != MBB.end() && NextI->getOpcode() == RISCV::PseudoRET)
+ if (MBBI != MBB.end() && NextI != MBB.end() &&
+ NextI->getOpcode() == RISCV::PseudoRET) {
Modified |= usePopRet(MBBI, NextI, adjustRetVal(MBBI));
+ }
}
return Modified;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157468.548435.patch
Type: text/x-patch
Size: 673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230809/ab2dd12c/attachment.bin>
More information about the llvm-commits
mailing list