Skip to content

Commit 20507a9

Browse files
authored
[Verifier][CGP] Allow integer argument to dbg_declare (#134803)
Relaxes the newly added verifier rule to also allow an integer argument to dbg_declare, which is interpreted as a pointer. Adjust CGP to deal with it gracefully. Fixes #134523. Alternative to #134601.
1 parent 716b02d commit 20507a9

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,9 @@ static bool processDbgDeclare(FunctionLoweringInfo &FuncInfo,
15561556
if (processIfEntryValueDbgDeclare(FuncInfo, Address, Expr, Var, DbgLoc))
15571557
return true;
15581558

1559+
if (!Address->getType()->isPointerTy())
1560+
return false;
1561+
15591562
MachineFunction *MF = FuncInfo.MF;
15601563
const DataLayout &DL = MF->getDataLayout();
15611564

llvm/lib/IR/Verifier.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6658,9 +6658,12 @@ void Verifier::visit(DbgVariableRecord &DVR) {
66586658
"invalid #dbg record address/value", &DVR, MD);
66596659
if (auto *VAM = dyn_cast<ValueAsMetadata>(MD)) {
66606660
visitValueAsMetadata(*VAM, F);
6661-
if (DVR.isDbgDeclare())
6662-
CheckDI(VAM->getValue()->getType()->isPointerTy(),
6663-
"location of #dbg_declare must be a pointer", &DVR, MD);
6661+
if (DVR.isDbgDeclare()) {
6662+
// Allow integers here to support inttoptr salvage.
6663+
Type *Ty = VAM->getValue()->getType();
6664+
CheckDI(Ty->isPointerTy() || Ty->isIntegerTy(),
6665+
"location of #dbg_declare must be a pointer or int", &DVR, MD);
6666+
}
66646667
} else if (auto *AL = dyn_cast<DIArgList>(MD)) {
66656668
visitDIArgList(*AL, F);
66666669
}

llvm/test/CodeGen/AArch64/selectiondag-order.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ end: ; preds = %body
5353
; AARCH64-CHECK: BB1_1:
5454

5555

56-
define i64 @simulateWithDbgDeclare(<2 x i32> %a, ptr %ptr) local_unnamed_addr {
56+
define i64 @simulateWithDbgDeclare(<2 x i32> %a) local_unnamed_addr {
5757
entry:
5858
%rand = tail call i64 @lrand48() #3
59-
tail call void @llvm.dbg.declare(metadata ptr %ptr, metadata !6, metadata !7), !dbg !8
59+
tail call void @llvm.dbg.declare(metadata i64 %rand, metadata !6, metadata !7), !dbg !8
6060
br label %body
6161

6262
body: ; preds = %body, %entry

llvm/test/CodeGen/X86/selectiondag-order.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ end: ; preds = %body
5353
; X86-CHECK: callq lrand48
5454
; X86-CHECK: movq %rax, %rbx
5555

56-
define i64 @simulateWithDbgDeclare(<2 x i32> %a, ptr %ptr) local_unnamed_addr {
56+
define i64 @simulateWithDbgDeclare(<2 x i32> %a) local_unnamed_addr {
5757
entry:
5858
%rand = tail call i64 @lrand48() #3
59-
tail call void @llvm.dbg.declare(metadata ptr %ptr, metadata !6, metadata !7), !dbg !8
59+
tail call void @llvm.dbg.declare(metadata i64 %rand, metadata !6, metadata !7), !dbg !8
6060
br label %body
6161

6262
body: ; preds = %body, %entry
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 salvaging an dbg_declare on inttoptr does not crash.
5+
define void @test(i64 %arg) {
6+
; CHECK-LABEL: define void @test(
7+
; CHECK-SAME: i64 [[ARG:%.*]]) {
8+
; CHECK-NEXT: #dbg_declare(i64 [[ARG]], [[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)