Skip to content

Commit afa413a

Browse files
authored
[RemoveDIs][DebugInfo] Correctly visit DPValues in StackInfoBuilder::visit (#81247)
In `StackInfoBuilder::visit(Instruction &Inst)`, operations are performed on memory-related instructions, including debug intrinsics that refer to "interesting" allocas. There is a block that also visits DPValues attached to the instruction, but this block is near the end of the function; this has two problems: 1. The DPValues attached to an instruction precede that instruction, so they should always be processed before the instruction itself. 2. More importantly, some of the paths for visiting other instructions contain early returns, which will result in the DPValues not being visited at all. This patch simply moves the DPValue-visiting block to the top of the function, which should resolve both of these problems.
1 parent 8373cee commit afa413a

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ Instruction *getUntagLocationIfFunctionExit(Instruction &Inst) {
110110
}
111111

112112
void StackInfoBuilder::visit(Instruction &Inst) {
113+
// Check for non-intrinsic debug-info records.
114+
for (auto &DPV : Inst.getDbgValueRange()) {
115+
for (Value *V : DPV.location_ops()) {
116+
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
117+
if (!isInterestingAlloca(*AI))
118+
continue;
119+
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
120+
auto &DPVVec = AInfo.DbgVariableRecords;
121+
if (DPVVec.empty() || DPVVec.back() != &DPV)
122+
DPVVec.push_back(&DPV);
123+
}
124+
}
125+
}
126+
113127
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
114128
if (CI->canReturnTwice()) {
115129
Info.CallsReturnTwice = true;
@@ -150,20 +164,6 @@ void StackInfoBuilder::visit(Instruction &Inst) {
150164
}
151165
}
152166

153-
// Check for non-intrinsic debug-info records.
154-
for (auto &DPV : Inst.getDbgValueRange()) {
155-
for (Value *V : DPV.location_ops()) {
156-
if (auto *AI = dyn_cast_or_null<AllocaInst>(V)) {
157-
if (!isInterestingAlloca(*AI))
158-
continue;
159-
AllocaInfo &AInfo = Info.AllocasToInstrument[AI];
160-
auto &DPVVec = AInfo.DbgVariableRecords;
161-
if (DPVVec.empty() || DPVVec.back() != &DPV)
162-
DPVVec.push_back(&DPV);
163-
}
164-
}
165-
}
166-
167167
Instruction *ExitUntag = getUntagLocationIfFunctionExit(Inst);
168168
if (ExitUntag)
169169
Info.RetVec.push_back(ExitUntag);

llvm/test/Instrumentation/HWAddressSanitizer/dbg-declare-tag-offset.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
; RUN: opt -passes=hwasan -S -o - %s | FileCheck %s
22

3+
;; Also test with RemoveDIs to verify that debug intrinsics immediately
4+
;; preceding an alloca (or other instruction of interest to stack tagging) will
5+
;; be correctly processed.
6+
; RUN: opt --try-experimental-debuginfo-iterators -passes=hwasan -S -o - %s | FileCheck %s
7+
38
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
49
target triple = "aarch64--linux-android"
510

@@ -12,11 +17,11 @@ entry:
1217
%nodebug2 = alloca ptr
1318
%nodebug3 = alloca ptr
1419
%a = alloca ptr
15-
%b = alloca ptr
1620
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 32)
1721
call void @llvm.dbg.declare(metadata ptr %a, metadata !12, metadata !DIExpression()), !dbg !14
1822
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 32)
1923
call void @llvm.dbg.declare(metadata ptr %a, metadata !12, metadata !DIExpression()), !dbg !14
24+
%b = alloca ptr
2025
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 96)
2126
call void @llvm.dbg.declare(metadata ptr %b, metadata !13, metadata !DIExpression()), !dbg !14
2227
; CHECK: @llvm.dbg.declare{{.*}} !DIExpression(DW_OP_LLVM_tag_offset, 96)

0 commit comments

Comments
 (0)