[PATCH] D119795: [MTE] [HWASan] Unify VariableLocation replacement.
Florian Mayer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 14 16:42:43 PST 2022
fmayer created this revision.
Herald added a subscriber: hiraditya.
fmayer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
HWASan and MTE used to replace the debug variable locations differently,
which made the code hard to understand. Unify the two in one easier to
understand method.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119795
Files:
llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
Index: llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -143,5 +143,14 @@
return true;
}
+void replaceAllVariableLocationOps(AllocaInfo &Info, Value *Old, Value *New) {
+ for (auto DVI : Info.DbgVariableIntrinsics) {
+ for (size_t I = 0; I < DVI->getNumVariableLocationOps(); ++I) {
+ if (DVI->getVariableLocationOp(I) == Old)
+ DVI->replaceVariableLocationOp(I, New);
+ }
+ }
+}
+
} // namespace memtag
} // namespace llvm
Index: llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1379,16 +1379,7 @@
}
}
if (memtag::alignAndPadAlloca(Info, Align(Mapping.getObjectAlignment()))) {
- for (auto DVI : Info.DbgVariableIntrinsics) {
- SmallDenseSet<Value *> LocationOps(DVI->location_ops().begin(),
- DVI->location_ops().end());
- for (Value *V : LocationOps) {
- if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
- if (V == AI)
- DVI->replaceVariableLocationOp(V, Info.AI);
- }
- }
- }
+ memtag::replaceAllVariableLocationOps(Info, AI, Info.AI);
AI->eraseFromParent();
}
}
Index: llvm/lib/Target/AArch64/AArch64StackTagging.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64StackTagging.cpp
+++ llvm/lib/Target/AArch64/AArch64StackTagging.cpp
@@ -538,7 +538,7 @@
int NextTag = 0;
for (auto &I : SInfo.AllocasToInstrument) {
- const memtag::AllocaInfo &Info = I.second;
+ memtag::AllocaInfo &Info = I.second;
AllocaInst *AI = Info.AI;
int Tag = NextTag;
NextTag = (NextTag + 1) % 16;
@@ -593,8 +593,7 @@
}
// Fixup debug intrinsics to point to the new alloca.
- for (auto DVI : Info.DbgVariableIntrinsics)
- DVI->replaceVariableLocationOp(Info.OldAI, Info.AI);
+ memtag::replaceAllVariableLocationOps(Info, Info.OldAI, Info.AI);
}
// If we have instrumented at least one alloca, all unrecognized lifetime
Index: llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
+++ llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h
@@ -103,6 +103,7 @@
uint64_t getAllocaSizeInBytes(const AllocaInst &AI);
bool alignAndPadAlloca(memtag::AllocaInfo &Info, llvm::Align Align);
+void replaceAllVariableLocationOps(AllocaInfo &Info, Value *Old, Value *New);
} // namespace memtag
} // namespace llvm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119795.408668.patch
Type: text/x-patch
Size: 2915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220215/effd7bef/attachment.bin>
More information about the llvm-commits
mailing list