[llvm] 19fdf85 - [hwasan] keep debug intrinsicts in AllocaInfo.

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 11 10:57:04 PST 2022


Author: Florian Mayer
Date: 2022-02-11T10:56:53-08:00
New Revision: 19fdf85f5858fa0aaae5f28f7140fbf12643993c

URL: https://github.com/llvm/llvm-project/commit/19fdf85f5858fa0aaae5f28f7140fbf12643993c
DIFF: https://github.com/llvm/llvm-project/commit/19fdf85f5858fa0aaae5f28f7140fbf12643993c.diff

LOG: [hwasan] keep debug intrinsicts in AllocaInfo.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D119498

Added: 
    

Modified: 
    llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
    llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
    llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h b/llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
index d858432d0e4a..d1548ecb58c0 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<IntrinsicInst *, 2> LifetimeStart;
   SmallVector<IntrinsicInst *, 2> LifetimeEnd;
+  SmallVector<DbgVariableIntrinsic *, 2> DbgVariableIntrinsics;
 };
 
 struct StackInfo {
   MapVector<AllocaInst *, AllocaInfo> AllocasToInstrument;
   SmallVector<Instruction *, 4> UnrecognizedLifetimes;
-  DenseMap<AllocaInst *, std::vector<DbgVariableIntrinsic *>> AllocaDbgMap;
   SmallVector<Instruction *, 8> RetVec;
   bool CallsReturnTwice = false;
 };

diff  --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 5dbe3210c7cd..34b0576982f5 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 5699ae0e6d0e..c149723ace11 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -87,10 +87,13 @@ void StackInfoBuilder::visit(Instruction &Inst) {
   }
   if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
     for (Value *V : DVI->location_ops()) {
-      if (auto *Alloca = dyn_cast_or_null<AllocaInst>(V))
-        if (!Info.AllocaDbgMap.count(Alloca) ||
-            Info.AllocaDbgMap[Alloca].back() != DVI)
-          Info.AllocaDbgMap[Alloca].push_back(DVI);
+      if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
+        AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
+        auto &DVIVec = AInfo.DbgVariableIntrinsics;
+        if (IsInterestingAlloca(*AI) &&
+            (DVIVec.empty() || DVIVec.back() != DVI))
+          DVIVec.push_back(DVI);
+      }
     }
   }
   Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);


        


More information about the llvm-commits mailing list