aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authorOrlando Cazalet-Hyams <orlando.hyams@sony.com>2024-02-13 09:11:09 +0000
committerGitHub <noreply@github.com>2024-02-13 09:11:09 +0000
commitd860ea96b1d4bcc13bf269e9b108d8f5e0c21d93 (patch)
tree650693b282f6e1be4dfdea1fd66947d134e38bba /llvm/lib
parent5b015229b77d6ea7916a503d88661b04d4867e7c (diff)
downloadllvm-d860ea96b1d4bcc13bf269e9b108d8f5e0c21d93.zip
llvm-d860ea96b1d4bcc13bf269e9b108d8f5e0c21d93.tar.gz
llvm-d860ea96b1d4bcc13bf269e9b108d8f5e0c21d93.tar.bz2
[HWASAN] Update dbg.assign intrinsics in HWAsan pass (#79864)
llvm.dbg.assign intrinsics have 2 {value, expression} pairs; fix hwasan to update the second expression. Fixes #76545. This is #78606 rebased and with the addition of DPValue handling. Note the addition of --try-experimental-debuginfo-iterators in the tests and some shuffling of code in MemoryTaggingSupport.cpp.
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp4
-rw-r--r--llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp13
-rw-r--r--llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp21
3 files changed, 27 insertions, 11 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index d8c1b0d..eaa5cb3 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -2214,10 +2214,6 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
if (F.hasFnAttribute(Attribute::OptimizeNone))
return /*Changed*/ false;
- // FIXME: https://github.com/llvm/llvm-project/issues/76545
- if (F.hasFnAttribute(Attribute::SanitizeHWAddress))
- return /*Changed*/ false;
-
bool Changed = false;
auto *DL = &F.getParent()->getDataLayout();
// Collect a map of {backing storage : dbg.declares} (currently "backing
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index c2a4632..393afc9 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1371,6 +1371,14 @@ static bool isLifetimeIntrinsic(Value *V) {
return II && II->isLifetimeStartOrEnd();
}
+static DbgAssignIntrinsic *DynCastToDbgAssign(DbgVariableIntrinsic *DVI) {
+ return dyn_cast<DbgAssignIntrinsic>(DVI);
+}
+
+static DPValue *DynCastToDbgAssign(DPValue *DPV) {
+ return DPV->isDbgAssign() ? DPV : nullptr;
+}
+
bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
Value *StackTag, Value *UARTag,
const DominatorTree &DT,
@@ -1437,6 +1445,11 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
if (DPtr->getVariableLocationOp(LocNo) == AI)
DPtr->setExpression(DIExpression::appendOpsToArg(
DPtr->getExpression(), NewOps, LocNo));
+ if (auto *DAI = DynCastToDbgAssign(DPtr)) {
+ if (DAI->getAddress() == AI)
+ DAI->setAddressExpression(DIExpression::prependOpcodes(
+ DAI->getAddressExpression(), NewOps));
+ }
};
llvm::for_each(Info.DbgVariableIntrinsics, AnnotateDbgRecord);
diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
index 4336695..1ffa003 100644
--- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp
@@ -110,18 +110,22 @@ Instruction *getUntagLocationIfFunctionExit(Instruction &Inst) {
}
void StackInfoBuilder::visit(Instruction &Inst) {
- // Check for non-intrinsic debug-info records.
+ // Visit non-intrinsic debug-info records attached to Inst.
for (auto &DPV : Inst.getDbgValueRange()) {
- for (Value *V : DPV.location_ops()) {
+ auto AddIfInteresting = [&](Value *V) {
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
if (!isInterestingAlloca(*AI))
- continue;
+ return;
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
auto &DPVVec = AInfo.DbgVariableRecords;
if (DPVVec.empty() || DPVVec.back() != &DPV)
DPVVec.push_back(&DPV);
}
- }
+ };
+
+ for_each(DPV.location_ops(), AddIfInteresting);
+ if (DPV.isDbgAssign())
+ AddIfInteresting(DPV.getAddress());
}
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
@@ -152,16 +156,19 @@ void StackInfoBuilder::visit(Instruction &Inst) {
return;
}
if (auto *DVI = dyn_cast<DbgVariableIntrinsic>(&Inst)) {
- for (Value *V : DVI->location_ops()) {
+ auto AddIfInteresting = [&](Value *V) {
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
if (!isInterestingAlloca(*AI))
- continue;
+ return;
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
auto &DVIVec = AInfo.DbgVariableIntrinsics;
if (DVIVec.empty() || DVIVec.back() != DVI)
DVIVec.push_back(DVI);
}
- }
+ };
+ for_each(DVI->location_ops(), AddIfInteresting);
+ if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI))
+ AddIfInteresting(DAI->getAddress());
}
Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);