[llvm] 6d46337 - [RemoveDIs] Handle DPValues in replaceDbgDeclare (#73507)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 12 07:25:13 PST 2023
Author: Orlando Cazalet-Hyams
Date: 2023-12-12T15:25:08Z
New Revision: 6d46337e13f943e331ae4c048e2456347fc83174
URL: https://github.com/llvm/llvm-project/commit/6d46337e13f943e331ae4c048e2456347fc83174
DIFF: https://github.com/llvm/llvm-project/commit/6d46337e13f943e331ae4c048e2456347fc83174.diff
LOG: [RemoveDIs] Handle DPValues in replaceDbgDeclare (#73507)
The tests will become "live" once #74090 lands (see for more info).
Added:
Modified:
llvm/lib/Transforms/Utils/Local.cpp
llvm/test/DebugInfo/Generic/block-asan.ll
llvm/test/DebugInfo/X86/asan_debug_info.ll
llvm/test/Transforms/SafeStack/ARM/debug.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 63dcb64461641..19b787c10e8f6 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2131,19 +2131,22 @@ bool llvm::replaceDbgDeclare(Value *Address, Value *NewAddress,
DIBuilder &Builder, uint8_t DIExprFlags,
int Offset) {
SmallVector<DbgDeclareInst *, 1> DbgDeclares;
- findDbgDeclares(DbgDeclares, Address);
- for (DbgVariableIntrinsic *DII : DbgDeclares) {
- const DebugLoc &Loc = DII->getDebugLoc();
+ SmallVector<DPValue *, 1> DPValues;
+ findDbgDeclares(DbgDeclares, Address, &DPValues);
+
+ auto ReplaceOne = [&](auto *DII) {
auto *DIVar = DII->getVariable();
auto *DIExpr = DII->getExpression();
assert(DIVar && "Missing variable");
DIExpr = DIExpression::prepend(DIExpr, DIExprFlags, Offset);
- // Insert llvm.dbg.declare immediately before DII, and remove old
- // llvm.dbg.declare.
- Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, DII);
- DII->eraseFromParent();
- }
- return !DbgDeclares.empty();
+ DII->setExpression(DIExpr);
+ DII->replaceVariableLocationOp(Address, NewAddress);
+ };
+
+ for_each(DbgDeclares, ReplaceOne);
+ for_each(DPValues, ReplaceOne);
+
+ return !DbgDeclares.empty() || !DPValues.empty();
}
static void updateOneDbgValueForAlloca(const DebugLoc &Loc,
diff --git a/llvm/test/DebugInfo/Generic/block-asan.ll b/llvm/test/DebugInfo/Generic/block-asan.ll
index db49289bd6ece..ceaf3f1d5e9a3 100644
--- a/llvm/test/DebugInfo/Generic/block-asan.ll
+++ b/llvm/test/DebugInfo/Generic/block-asan.ll
@@ -1,4 +1,5 @@
; RUN: opt -S -passes=asan %s | FileCheck %s
+; RUN: opt --try-experimental-debuginfo-iterators -S -passes=asan %s | FileCheck %s
; The IR of this testcase is generated from the following C code:
; void bar (int);
diff --git a/llvm/test/DebugInfo/X86/asan_debug_info.ll b/llvm/test/DebugInfo/X86/asan_debug_info.ll
index 5e06b093c41d9..4a4743ee0df57 100644
--- a/llvm/test/DebugInfo/X86/asan_debug_info.ll
+++ b/llvm/test/DebugInfo/X86/asan_debug_info.ll
@@ -2,6 +2,10 @@
; RUN: llc -O0 -filetype=obj - -o - | \
; RUN: llvm-dwarfdump - | FileCheck %s
+; RUN: opt --try-experimental-debuginfo-iterators < %s -passes=asan -asan-use-after-return=never -S | \
+; RUN: llc -O0 -filetype=obj - -o - | \
+; RUN: llvm-dwarfdump - | FileCheck %s
+
; For this test case, ASan used to produce IR which resulted in the following
; DWARF (at -O0):
;
diff --git a/llvm/test/Transforms/SafeStack/ARM/debug.ll b/llvm/test/Transforms/SafeStack/ARM/debug.ll
index c38ee62fa6aa4..fbdb6361c2f6a 100644
--- a/llvm/test/Transforms/SafeStack/ARM/debug.ll
+++ b/llvm/test/Transforms/SafeStack/ARM/debug.ll
@@ -1,5 +1,7 @@
; RUN: opt -safe-stack -safestack-use-pointer-address < %s -S | FileCheck %s
; RUN: opt -passes=safe-stack -safestack-use-pointer-address < %s -S | FileCheck %s
+; RUN: opt --try-experimental-debuginfo-iterators -passes=safe-stack -safestack-use-pointer-address < %s -S | FileCheck %s
+
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv7-pc-linux-android"
More information about the llvm-commits
mailing list