[llvm] a5a8a05 - [SelectionDAG] Handle IntToPtr constants in dbg.value

Felipe de Azevedo Piovezan via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 3 11:13:13 PDT 2022


Author: Felipe de Azevedo Piovezan
Date: 2022-08-03T14:10:05-04:00
New Revision: a5a8a05c78c0d1298c4128aaafd0275354198afb

URL: https://github.com/llvm/llvm-project/commit/a5a8a05c78c0d1298c4128aaafd0275354198afb
DIFF: https://github.com/llvm/llvm-project/commit/a5a8a05c78c0d1298c4128aaafd0275354198afb.diff

LOG: [SelectionDAG] Handle IntToPtr constants in dbg.value

The function `handleDebugValue` has custom logic to handle certain kinds
constants, namely integers, floats and null pointers. However, it does
not handle constant pointers created from IntToPtr ConstantExpressions.
This patch addresses the issue by replacing the Constant with its
integer operand.

A similar bug was addressed for GlobalISel in D130642.

Reviewed By: aprantl, #debug-info

Differential Revision: https://reviews.llvm.org/D130908

Added: 
    llvm/test/CodeGen/AArch64/inttoptr_debug_value.ll

Modified: 
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 2239148bf4476..40b3f683f56b8 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1344,6 +1344,13 @@ bool SelectionDAGBuilder::handleDebugValue(ArrayRef<const Value *> Values,
       continue;
     }
 
+    // Look through IntToPtr constants.
+    if (auto *CE = dyn_cast<ConstantExpr>(V))
+      if (CE->getOpcode() == Instruction::IntToPtr) {
+        LocationOps.emplace_back(SDDbgOperand::fromConst(CE->getOperand(0)));
+        continue;
+      }
+
     // If the Value is a frame index, we can create a FrameIndex debug value
     // without relying on the DAG at all.
     if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {

diff  --git a/llvm/test/CodeGen/AArch64/inttoptr_debug_value.ll b/llvm/test/CodeGen/AArch64/inttoptr_debug_value.ll
new file mode 100644
index 0000000000000..5ff5292c0e73f
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/inttoptr_debug_value.ll
@@ -0,0 +1,25 @@
+; RUN: llc -o - --print-after-isel %s 2>&1 | FileCheck %s
+
+target triple = "arm64-apple-ios13.4.0"
+define void @foo() !dbg !6 {
+  ; CHECK: DBG_VALUE 42, $noreg, !"myvar", !DIExpression()
+  call void @llvm.dbg.value(metadata ptr inttoptr (i64 42 to ptr), metadata !9, metadata !DIExpression()), !dbg !11
+  ret void
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+!1 = !DIFile(filename: "t.ll", directory: "/")
+!2 = !{}
+!5 = !{i32 4, !"Debug Info Version", i32 3}
+!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+!7 = !DISubroutineType(types: !2)
+!8 = !{!9}
+!9 = !DILocalVariable(name: "myvar", scope: !6, file: !1, line: 1, type: !10)
+!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
+!11 = !DILocation(line: 1, column: 1, scope: !6)
+!12 = !DILocation(line: 2, column: 1, scope: !6)


        


More information about the llvm-commits mailing list