[llvm] [llvm] Fix potential null dereference in IR/Verifier (PR #157458)

Daniel Kuts via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 9 11:54:41 PDT 2025


https://github.com/apach301 updated https://github.com/llvm/llvm-project/pull/157458

>From 8ecbd8a53d15792737b1dcb0f1ae6178d9bebbee Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 16:07:53 +0300
Subject: [PATCH 1/2] [llvm] Fix potential null dereference in IR/Verifier

---
 llvm/lib/IR/Verifier.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index f38871f09f35f..57ea5b53647aa 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3188,7 +3188,7 @@ void Verifier::visitFunction(const Function &F) {
     if (SP && ((Scope != SP) && !Seen.insert(SP).second))
       return;
 
-    CheckDI(SP->describes(&F),
+    CheckDI(SP && SP->describes(&F),
             "!dbg attachment points at wrong subprogram for function", N, &F,
             &I, DL, Scope, SP);
   };

>From 3ea9bd1b17e0c67b75b20aaa3cb71bdaf7d24208 Mon Sep 17 00:00:00 2001
From: Daniel Kuts <kutz at ispras.ru>
Date: Tue, 9 Sep 2025 21:54:32 +0300
Subject: [PATCH 2/2] Remove redunand checks for NULL

---
 llvm/lib/IR/Verifier.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 57ea5b53647aa..81a53722f4899 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3185,10 +3185,10 @@ void Verifier::visitFunction(const Function &F) {
 
     // Scope and SP could be the same MDNode and we don't want to skip
     // validation in that case
-    if (SP && ((Scope != SP) && !Seen.insert(SP).second))
+    if ((Scope != SP) && !Seen.insert(SP).second)
       return;
 
-    CheckDI(SP && SP->describes(&F),
+    CheckDI(SP->describes(&F),
             "!dbg attachment points at wrong subprogram for function", N, &F,
             &I, DL, Scope, SP);
   };



More information about the llvm-commits mailing list