[PATCH] D134641: [AMDGPU][Backend] Fix user-after-free in AMDGPUReleaseVGPRs::isLastVGPRUseVMEMStore
Juan Manuel Martinez CaamaƱo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 06:24:37 PDT 2022
jmmartinez created this revision.
Herald added subscribers: kosarev, foad, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl, arsenm.
Herald added a project: All.
jmmartinez requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134641
Files:
llvm/lib/Target/AMDGPU/AMDGPUReleaseVGPRs.cpp
Index: llvm/lib/Target/AMDGPU/AMDGPUReleaseVGPRs.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUReleaseVGPRs.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUReleaseVGPRs.cpp
@@ -57,7 +57,7 @@
// false in case we have a cycle.
BlockVMEMStoreType::iterator It;
bool Inserted;
- std::tie(It, Inserted) = BlockVMEMStore.insert({&MBB, false});
+ std::tie(It, Inserted) = BlockVMEMStore.try_emplace(&MBB, false);
bool &CacheEntry = It->second;
if (!Inserted)
return CacheEntry;
@@ -76,6 +76,8 @@
// Recursive call into parent blocks. Look into predecessors if there is no
// vgpr used in this block.
+ // The iterator is not invalidated by the recursive calls since we grew the
+ // dictionary to hold all the entries in advance
return CacheEntry = llvm::any_of(MBB.predecessors(),
[this](MachineBasicBlock *Parent) {
return isLastVGPRUseVMEMStore(*Parent);
@@ -120,6 +122,9 @@
SII = ST.getInstrInfo();
TRI = ST.getRegisterInfo();
+ // we grow BlockVMEMStore to prevent the invalidation of its iterators
+ BlockVMEMStore.grow(MF.size());
+
bool Changed = false;
for (auto &MBB : MF) {
Changed |= runOnMachineBasicBlock(MBB);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134641.462889.patch
Type: text/x-patch
Size: 1340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220926/0ef391b7/attachment.bin>
More information about the llvm-commits
mailing list