[llvm] [SelectionDAG] Fix null pointer dereference in resolveDanglingDebugInfo (PR #173500)

via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 25 11:33:45 PST 2025


https://github.com/MetalOxideSemi updated https://github.com/llvm/llvm-project/pull/173500

>From 859cff3e7f765f1499705f71318de87e12575eee Mon Sep 17 00:00:00 2001
From: Haoren Wang <haorenwange2 at outlook.com>
Date: Fri, 26 Dec 2025 03:27:14 +0800
Subject: [PATCH] [SelectionDAG] Fix null pointer dereference in
 resolveDanglingDebugInfo

When handling dbg_value intrinsics for aggregate types containing
empty structs, Val.getNode() could return null, causing a crash
when attempting to dereference it.

This patch adds a null check before accessing Val.getNode() in
resolveDanglingDebugInfo, preventing the crash while maintaining
correct debug info handling for valid cases.

The issue was triggered by:
1. A dbg_value intrinsic referencing an aggregate type with empty structs
2. An insertvalue operation that gets lowered to a null SDNode
3. Attempting to dereference the null node in resolveDanglingDebugInfo

Added regression test in CodeGen/Generic/selectiondag-dbgvalue-null-crash.ll
---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 9e342f9c4416f..e35c0d95f3941 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1504,7 +1504,6 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
   DanglingDebugInfoVector &DDIV = DanglingDbgInfoIt->second;
   for (auto &DDI : DDIV) {
     DebugLoc DL = DDI.getDebugLoc();
-    unsigned ValSDNodeOrder = Val.getNode()->getIROrder();
     unsigned DbgSDNodeOrder = DDI.getSDNodeOrder();
     DILocalVariable *Variable = DDI.getVariable();
     DIExpression *Expr = DDI.getExpression();
@@ -1518,6 +1517,7 @@ void SelectionDAGBuilder::resolveDanglingDebugInfo(const Value *V,
       // in the first place we should not be more successful here). Unless we
       // have some test case that prove this to be correct we should avoid
       // calling EmitFuncArgumentDbgValue here.
+      unsigned ValSDNodeOrder = Val.getNode()->getIROrder();
       if (!EmitFuncArgumentDbgValue(V, Variable, Expr, DL,
                                     FuncArgumentDbgValueKind::Value, Val)) {
         LLVM_DEBUG(dbgs() << "Resolve dangling debug info for "



More information about the llvm-commits mailing list