Skip to content

Commit 9484209

Browse files
committed
[DebugInfo] Do not change #dbg_declare type during salvage
When salvaging debug info for #dbg_declare, do not perform salvage that changes the type of the value, i.e. bail out on cast instructions. This ensures that we don't run afoul of the verifier check in llvm#134355.
1 parent 7d4ea77 commit 9484209

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

llvm/include/llvm/Transforms/Utils/Local.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,13 @@ void salvageDebugInfoForDbgValues(Instruction &I,
347347
/// Return = %a
348348
/// Ops = llvm::dwarf::DW_OP_LLVM_arg0 llvm::dwarf::DW_OP_add
349349
/// AdditionalValues = %b
350+
///
351+
/// \param KeepType If enabled, only perform salvage that does not modify
352+
/// the type of the value.
350353
Value *salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
351354
SmallVectorImpl<uint64_t> &Ops,
352-
SmallVectorImpl<Value *> &AdditionalValues);
355+
SmallVectorImpl<Value *> &AdditionalValues,
356+
bool KeepType = false);
353357

354358
/// Point debug users of \p From to \p To or salvage them. Use this function
355359
/// only when replacing all uses of \p From with \p To, with a guarantee that

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,8 @@ void llvm::salvageDebugInfoForDbgValues(
23982398
SmallVector<uint64_t, 16> Ops;
23992399
unsigned LocNo = std::distance(DVRLocation.begin(), LocItr);
24002400
uint64_t CurrentLocOps = SalvagedExpr->getNumLocationOperands();
2401-
Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues);
2401+
Op0 = salvageDebugInfoImpl(I, CurrentLocOps, Ops, AdditionalValues,
2402+
DVR->isDbgDeclare());
24022403
if (!Op0)
24032404
break;
24042405
SalvagedExpr =
@@ -2600,11 +2601,15 @@ Value *getSalvageOpsForIcmpOp(ICmpInst *Icmp, uint64_t CurrentLocOps,
26002601

26012602
Value *llvm::salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps,
26022603
SmallVectorImpl<uint64_t> &Ops,
2603-
SmallVectorImpl<Value *> &AdditionalValues) {
2604+
SmallVectorImpl<Value *> &AdditionalValues,
2605+
bool KeepType) {
26042606
auto &M = *I.getModule();
26052607
auto &DL = M.getDataLayout();
26062608

26072609
if (auto *CI = dyn_cast<CastInst>(&I)) {
2610+
if (KeepType)
2611+
return nullptr;
2612+
26082613
Value *FromValue = CI->getOperand(0);
26092614
// No-op casts are irrelevant for debug info.
26102615
if (CI->isNoopCast(DL)) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -codegenprepare -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
3+
4+
; Make sure we don't produce something like #dbg_declare(i64 %arg) here.
5+
define void @test(i64 %arg) {
6+
; CHECK-LABEL: define void @test(
7+
; CHECK-SAME: i64 [[ARG:%.*]]) {
8+
; CHECK-NEXT: #dbg_declare(ptr poison, [[META4:![0-9]+]], !DIExpression(), [[META6:![0-9]+]])
9+
; CHECK-NEXT: ret void
10+
;
11+
%inttoptr = inttoptr i64 %arg to ptr
12+
#dbg_declare(ptr %inttoptr, !4, !DIExpression(), !6)
13+
ret void
14+
}
15+
16+
!llvm.dbg.cu = !{!0}
17+
!llvm.module.flags = !{!3}
18+
19+
!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)
20+
!1 = !DIFile(filename: "test.cpp", directory: "/home/npopov/repos/llvm-project", checksumkind: CSK_MD5, checksum: "eabd3d442348430f50ca2f8c28d743e9")
21+
!2 = !{}
22+
!3 = !{i32 2, !"Debug Info Version", i32 3}
23+
!4 = !DILocalVariable(name: "c", scope: !5, file: !1, line: 26)
24+
!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)
25+
!6 = !DILocation(line: 26, column: 11, scope: !5)
26+
;.
27+
; 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)
28+
; CHECK: [[META1]] = !DIFile(filename: "test.cpp", directory: {{.*}})
29+
; CHECK: [[META2]] = !{}
30+
; CHECK: [[META4]] = !DILocalVariable(name: "c", scope: [[META5:![0-9]+]], file: [[META1]], line: 26)
31+
; 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]])
32+
; CHECK: [[META6]] = !DILocation(line: 26, column: 11, scope: [[META5]])
33+
;.

0 commit comments

Comments
 (0)