diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp --- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp +++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp @@ -502,14 +502,6 @@ if (SInfo.AllocasToInstrument.empty()) return false; - for (auto &I : SInfo.AllocasToInstrument) { - memtag::AllocaInfo &Info = I.second; - assert(Info.AI && isInterestingAlloca(*Info.AI)); - auto *PrevAI = Info.AI; - if (memtag::alignAndPadAlloca(Info, kTagGranuleSize)) - PrevAI->eraseFromParent(); - } - std::unique_ptr DeleteDT; DominatorTree *DT = nullptr; if (auto *P = getAnalysisIfAvailable()) @@ -539,6 +531,10 @@ int NextTag = 0; for (auto &I : SInfo.AllocasToInstrument) { memtag::AllocaInfo &Info = I.second; + assert(Info.AI && isInterestingAlloca(*Info.AI)); + auto *PrevAI = Info.AI; + if (memtag::alignAndPadAlloca(Info, kTagGranuleSize)) + PrevAI->eraseFromParent(); AllocaInst *AI = Info.AI; int Tag = NextTag; NextTag = (NextTag + 1) % 16;