diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1565,7 +1565,7 @@ if (VI.inStackSlot()) RegVar->initializeMMI(VI.Expr, VI.getStackSlot()); else { - MachineLocation MLoc(VI.getEntryValueRegister(), /*IsIndirect*/ true); + MachineLocation MLoc(VI.getEntryValueRegister(), /*IsIndirect*/ false); auto LocEntry = DbgValueLocEntry(MLoc); RegVar->initializeDbgValue(DbgValueLoc(VI.Expr, LocEntry)); } diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -1943,6 +1943,8 @@ if (!PhysReg) return false; + // Append an op deref to account for the fact that this is a dbg_declare. + Expr = DIExpression::append(Expr, dwarf::DW_OP_deref); MF->setVariableDbgInfo(DebugInst.getVariable(), Expr, *PhysReg, DebugInst.getDebugLoc()); return true; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1357,6 +1357,8 @@ // Find the corresponding livein physical register to this argument. for (auto [PhysReg, VirtReg] : FuncInfo.RegInfo->liveins()) if (VirtReg == ArgVReg) { + // Append an op deref to account for the fact that this is a dbg_declare. + Expr = DIExpression::append(Expr, dwarf::DW_OP_deref); FuncInfo.MF->setVariableDbgInfo(Var, Expr, PhysReg, DbgLoc); LLVM_DEBUG(dbgs() << "processDbgDeclare: setVariableDbgInfo Var=" << *Var << ", Expr=" << *Expr << ", MCRegister=" << PhysReg diff --git a/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll b/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll --- a/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll +++ b/llvm/test/CodeGen/AArch64/dbg-declare-swift-async.ll @@ -3,11 +3,11 @@ ; RUN: llc -O0 -fast-isel=false -global-isel=false -stop-after=finalize-isel %s -o - | FileCheck %s ; CHECK: void @foo -; CHECK-NEXT: dbg.declare(metadata {{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]]), !dbg ![[LOC:.*]] +; CHECK-NEXT: dbg.declare(metadata {{.*}}, metadata ![[VAR:.*]], metadata !DIExpression([[EXPR:.*]])), !dbg ![[LOC:.*]] ; CHECK: entry_values: -; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '![[EXPR]]', +; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '!DIExpression([[EXPR]], DW_OP_deref)', ; CHECK-NEXT: debug-info-location: '![[LOC]] -; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '![[EXPR]]' +; CHECK-NEXT: entry-value-register: '$x22', debug-info-variable: '![[VAR]]', debug-info-expression: '!DIExpression([[EXPR]], DW_OP_deref)' ; CHECK-NEXT: debug-info-location: '![[LOC]] ; CHECK-NOT: DBG_VALUE diff --git a/llvm/test/DebugInfo/AArch64/dbg-entry-value-swiftasync.mir b/llvm/test/DebugInfo/AArch64/dbg-entry-value-swiftasync.mir --- a/llvm/test/DebugInfo/AArch64/dbg-entry-value-swiftasync.mir +++ b/llvm/test/DebugInfo/AArch64/dbg-entry-value-swiftasync.mir @@ -36,7 +36,7 @@ - { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16, stack-id: default, callee-saved-register: '$lr', callee-saved-restored: true } entry_values: - - { entry-value-register: '$x22', debug-info-variable: '!10', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1)', + - { entry-value-register: '$x22', debug-info-variable: '!10', debug-info-expression: '!DIExpression(DW_OP_LLVM_entry_value, 1, DW_OP_deref)', debug-info-location: '!12' } body: | bb.0 (%ir-block.0):