diff --git a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h --- a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h +++ b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h @@ -19,7 +19,6 @@ #include "llvm/IR/Instruction.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Module.h" -#include "llvm/IR/ValueHandle.h" namespace llvm { namespace memtag { @@ -75,7 +74,6 @@ struct AllocaInfo { AllocaInst *AI; - TrackingVH OldAI; // Track through RAUW to replace debug uses. SmallVector LifetimeStart; SmallVector LifetimeEnd; SmallVector DbgVariableIntrinsics; @@ -102,7 +100,7 @@ }; uint64_t getAllocaSizeInBytes(const AllocaInst &AI); -bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align); +void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align); } // namespace memtag } // namespace llvm 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 @@ -48,6 +48,7 @@ #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/IntrinsicsAArch64.h" #include "llvm/IR/Metadata.h" +#include "llvm/IR/ValueHandle.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" #include "llvm/Support/Casting.h" @@ -532,9 +533,8 @@ 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(); + TrackingVH OldAI = Info.AI; + memtag::alignAndPadAlloca(Info, kTagGranuleSize); AllocaInst *AI = Info.AI; int Tag = NextTag; NextTag = (NextTag + 1) % 16; @@ -590,7 +590,7 @@ // Fixup debug intrinsics to point to the new alloca. for (auto DVI : Info.DbgVariableIntrinsics) - DVI->replaceVariableLocationOp(Info.OldAI, Info.AI); + DVI->replaceVariableLocationOp(OldAI, Info.AI); } // If we have instrumented at least one alloca, all unrecognized lifetime diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1378,8 +1378,7 @@ II->eraseFromParent(); } } - if (memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment()))) - AI->eraseFromParent(); + memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment())); } for (auto &I : SInfo.UnrecognizedLifetimes) I->eraseFromParent(); diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp --- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp +++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp @@ -67,7 +67,6 @@ if (AllocaInst *AI = dyn_cast(&Inst)) { if (IsInterestingAlloca(*AI)) { Info.AllocasToInstrument[AI].AI = AI; - Info.AllocasToInstrument[AI].OldAI = AI; } return; } @@ -109,7 +108,7 @@ return AI.getAllocationSizeInBits(DL).getValue() / 8; } -bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) { +void alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Alignment) { const Align NewAlignment = max(MaybeAlign(Info.AI->getAlign()), Alignment); Info.AI->setAlignment(NewAlignment); auto &Ctx = Info.AI->getFunction()->getContext(); @@ -117,7 +116,7 @@ uint64_t Size = getAllocaSizeInBytes(*Info.AI); uint64_t AlignedSize = alignTo(Size, Alignment); if (Size == AlignedSize) - return false; + return; // Add padding to the alloca. Type *AllocatedType = @@ -139,8 +138,8 @@ auto *NewPtr = new BitCastInst(NewAI, Info.AI->getType(), "", Info.AI); Info.AI->replaceAllUsesWith(NewPtr); + Info.AI->eraseFromParent(); Info.AI = NewAI; - return true; } } // namespace memtag