Skip to content

Commit bf2f72f

Browse files
committed
[hwasan] keep debug intrinsicts in AllocaInfo.
Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D119498
1 parent cb1bee4 commit bf2f72f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

llvm/include/llvm/Transforms/Utils/MemoryTaggingSupport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ struct AllocaInfo {
7676
AllocaInst *AI;
7777
SmallVector<IntrinsicInst *, 2> LifetimeStart;
7878
SmallVector<IntrinsicInst *, 2> LifetimeEnd;
79+
SmallVector<DbgVariableIntrinsic *, 2> DbgVariableIntrinsics;
7980
};
8081

8182
struct StackInfo {
8283
MapVector<AllocaInst *, AllocaInfo> AllocasToInstrument;
8384
SmallVector<Instruction *, 4> UnrecognizedLifetimes;
84-
DenseMap<AllocaInst *, std::vector<DbgVariableIntrinsic *>> AllocaDbgMap;
8585
SmallVector<Instruction *, 8> RetVec;
8686
bool CallsReturnTwice = false;
8787
};

llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ bool HWAddressSanitizer::instrumentStack(
13411341
AI->replaceUsesWithIf(Replacement,
13421342
[AILong](Use &U) { return U.getUser() != AILong; });
13431343

1344-
for (auto *DDI : SInfo.AllocaDbgMap.lookup(AI)) {
1344+
for (auto *DDI : Info.DbgVariableIntrinsics) {
13451345
// Prepend "tag_offset, N" to the dwarf expression.
13461346
// Tag offset logically applies to the alloca pointer, and it makes sense
13471347
// to put it at the beginning of the expression.

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ void StackInfoBuilder::visit(Instruction &Inst) {
8787
}
8888
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
8989
for (Value *V : DVI->location_ops()) {
90-
if (auto *Alloca = dyn_cast_or_null<AllocaInst>(V))
91-
if (!Info.AllocaDbgMap.count(Alloca) ||
92-
Info.AllocaDbgMap[Alloca].back() != DVI)
93-
Info.AllocaDbgMap[Alloca].push_back(DVI);
90+
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
91+
if (!IsInterestingAlloca(*AI))
92+
continue;
93+
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
94+
auto &DVIVec = AInfo.DbgVariableIntrinsics;
95+
if (DVIVec.empty() || DVIVec.back() != DVI)
96+
DVIVec.push_back(DVI);
97+
}
9498
}
9599
}
96100
Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);

0 commit comments

Comments
 (0)