From bf2f72fa10e3469b4f1bc6a85129c7074c65cfb2 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 11 Feb 2022 15:46:37 -0800 Subject: [PATCH] [hwasan] keep debug intrinsicts in AllocaInfo. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D119498 --- llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h | 2 +- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | 2 +- llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h index d858432..d1548ec 100644 --- a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h +++ b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h @@ -76,12 +76,12 @@ struct AllocaInfo { 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 index 5dbe321..34b0576 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -1341,7 +1341,7 @@ bool HWAddressSanitizer::instrumentStack( 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 index 5699ae0..bd4e4ef 100644 --- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp +++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp @@ -87,10 +87,14 @@ void StackInfoBuilder::visit(Instruction &Inst) { } 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 *AI = dyn_cast_or_null(V)) { + if (!IsInterestingAlloca(*AI)) + continue; + AllocaInfo &AInfo = Info.AllocasToInstrument[AI]; + auto &DVIVec = AInfo.DbgVariableIntrinsics; + if (DVIVec.empty() || DVIVec.back() != DVI) + DVIVec.push_back(DVI); + } } } Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst); -- 2.7.4