[llvm] [llvm] Fix possible null dereference in Transforms/Scalar (PR #157461)

Daniel Kuts via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 06:34:53 PDT 2025


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

>From 3f873d194c7bd0bfb09c8c3024b2e0d2e843a64e Mon Sep 17 00:00:00 2001
From: Daniil Kutz <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 16:13:34 +0300
Subject: [PATCH 1/2] [llvm] Fix possible null dereference in Transforms/Scalar

---
 llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index 434b55868c99d..33f06e2abe801 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -521,7 +521,7 @@ struct MainSwitch {
 
     Instruction *SIUse = dyn_cast<Instruction>(SI->user_back());
     // The use of the select inst should be either a phi or another select.
-    if (!SIUse && !(isa<PHINode>(SIUse) || isa<SelectInst>(SIUse)))
+    if (SIUse && !(isa<PHINode>(SIUse) || isa<SelectInst>(SIUse)))
       return false;
 
     BasicBlock *SIBB = SI->getParent();

>From 59eae88284c2ef925038e60ceade38f1017e4784 Mon Sep 17 00:00:00 2001
From: Daniel Kuts <kutz at ispras.ru>
Date: Mon, 8 Sep 2025 16:34:45 +0300
Subject: [PATCH 2/2] Update llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Co-authored-by: Nikita Popov <github at npopov.com>
---
 llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
index 33f06e2abe801..22cb385652644 100644
--- a/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
@@ -521,7 +521,7 @@ struct MainSwitch {
 
     Instruction *SIUse = dyn_cast<Instruction>(SI->user_back());
     // The use of the select inst should be either a phi or another select.
-    if (SIUse && !(isa<PHINode>(SIUse) || isa<SelectInst>(SIUse)))
+    if (!SIUse || !(isa<PHINode>(SIUse) || isa<SelectInst>(SIUse)))
       return false;
 
     BasicBlock *SIBB = SI->getParent();



More information about the llvm-commits mailing list