Skip to content

[DebugInfo] Do not change #dbg_declare type during salvage #134601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion llvm/include/llvm/Transforms/Utils/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,13 @@ void salvageDebugInfoForDbgValues(Instruction &I,
/// Return = %a
/// Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add
/// AdditionalValues = %b
///
/// \param KeepType If enabled, only perform salvage that does not modify
/// the type of the value.
Value *salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
SmallVectorImpl<uint64_t> &Ops,
SmallVectorImpl<Value *> &AdditionalValues);
SmallVectorImpl<Value *> &AdditionalValues,
bool KeepType = false);

/// Point debug users of \p From to \p To or salvage them. Use this function
/// only when replacing all uses of \p From with \p To, with a guarantee that
Expand Down
9 changes: 7 additions & 2 deletions llvm/lib/Transforms/Utils/Local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,8 @@ void llvm::salvageDebugInfoForDbgValues(
SmallVector<uint64_t, 16> Ops;
unsigned LocNo = std::distance(DVRLocation.begin(), LocItr);
uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands();
Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues);
Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues,
DVR->isDbgDeclare());
if (!Op0)
break;
SalvagedExpr =
Expand Down Expand Up @@ -2600,11 +2601,15 @@ Value *getSalvageOpsForIcmpOp(ICmpInst *Icmp, uint64_t CurrentLocOps,

Value *llvm::salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
SmallVectorImpl<uint64_t> &Ops,
SmallVectorImpl<Value *> &AdditionalValues) {
SmallVectorImpl<Value *> &AdditionalValues,
bool KeepType) {
auto &M = *I.getModule();
auto &DL = M.getDataLayout();

if (auto *CI = dyn_cast<CastInst>(&I)) {
if (KeepType)
return nullptr;

Value *FromValue = CI->getOperand(0);
// No-op casts are irrelevant for debug info.
if (CI->isNoopCast(DL)) {
Expand Down
33 changes: 33 additions & 0 deletions llvm/test/Transforms/CodeGenPrepare/X86/cast-debuginfo-salvage.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -codegenprepare -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s

; Make sure we don't produce something like #dbg_declare(i64 %arg) here.
define void @test(i64 %arg) {
; CHECK-LABEL: define void @test(
; CHECK-SAME: i64 [[ARG:%.*]]) {
; CHECK-NEXT: #dbg_declare(ptr poison, [[META4:![0-9]+]], !DIExpression(), [[META6:![0-9]+]])
; CHECK-NEXT: ret void
;
%inttoptr = inttoptr i64 %arg to ptr
#dbg_declare(ptr %inttoptr, !4, !DIExpression(), !6)
ret void
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.cpp", directory: "/home/npopov/repos/llvm-project", checksumkind: CSK_MD5, checksum: "eabd3d442348430f50ca2f8c28d743e9")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !DILocalVariable(name: "c", scope: !5, file: !1, line: 26)
!5 = distinct !DISubprogram(name: "n<(lambda at test.cpp:39:14)>", linkageName: "_ZN1m1nIZN1o1pEvEUl1kE_EE5arrayT_i", scope: null, file: !1, line: 25, spFlags: DISPFlagDefinition, unit: !0)
!6 = !DILocation(line: 26, column: 11, scope: !5)
;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[META2:![0-9]+]], globals: [[META2]], splitDebugInlining: false, nameTableKind: None)
; CHECK: [[META1]] = !DIFile(filename: "test.cpp", directory: {{.*}})
; CHECK: [[META2]] = !{}
; CHECK: [[META4]] = !DILocalVariable(name: "c", scope: [[META5:![0-9]+]], file: [[META1]], line: 26)
; CHECK: [[META5]] = distinct !DISubprogram(name: "n<(lambda at test.cpp:39:14)>", linkageName: "_ZN1m1nIZN1o1pEvEUl1kE_EE5arrayT_i", scope: null, file: [[META1]], line: 25, spFlags: DISPFlagDefinition, unit: [[META0]])
; CHECK: [[META6]] = !DILocation(line: 26, column: 11, scope: [[META5]])
;.