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 @@ -76,12 +76,12 @@ AllocaInst *AI; SmallVector LifetimeStart; SmallVector LifetimeEnd; + SmallVector DbgVariableIntrinsics; }; struct StackInfo { MapVector AllocasToInstrument; SmallVector UnrecognizedLifetimes; - DenseMap> AllocaDbgMap; SmallVector RetVec; bool CallsReturnTwice = false; }; 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 @@ -1341,7 +1341,7 @@ AI->replaceUsesWithIf(Replacement, [AILong](Use &U) { return U.getUser() != AILong; }); - for (auto *DDI : SInfo.AllocaDbgMap.lookup(AI)) { + for (auto *DDI : Info.DbgVariableIntrinsics) { // Prepend "tag_offset, N" to the dwarf expression. // Tag offset logically applies to the alloca pointer, and it makes sense // to put it at the beginning of the expression. 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 @@ -87,10 +87,13 @@ } if (auto *DVI = dyn_cast(&Inst)) { for (Value *V : DVI->location_ops()) { - if (auto *Alloca = dyn_cast_or_null(V)) - if (!Info.AllocaDbgMap.count(Alloca) || - Info.AllocaDbgMap[Alloca].back() != DVI) - Info.AllocaDbgMap[Alloca].push_back(DVI); + if (auto *Alloca = dyn_cast_or_null(V)) { + AllocaInfo &AI = Info.AllocasToInstrument[Alloca]; + auto &DVIVec = AI.DbgVariableIntrinsics; + if (IsInterestingAlloca(*Alloca) && + (DVIVec.empty() || DVIVec.back() != DVI)) + DVIVec.push_back(DVI); + } } } Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);