[llvm] [NFCI] Check for non-null before dereferencing a VPBB ptr (PR #190403)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 13:57:53 PDT 2026


https://github.com/calebwat created https://github.com/llvm/llvm-project/pull/190403

A VPBB variable is possibly null (defined via a ternary), but is subsequently dereferenced without a check included. This patch adds a check for it to avoid any possibly null dereference. This was found via static analysis, there is not a known case right now where this issue is hit.


>From 03c44897fe11d6f430aa136b867ec6c778996ed3 Mon Sep 17 00:00:00 2001
From: "Watts, Caleb" <caleb.watts at intel.com>
Date: Fri, 3 Apr 2026 13:54:04 -0700
Subject: [PATCH] [NFCI] Check for non-null before dereferencing a VPBB ptr

A VPBB variable is possibly null (defined via a ternary), but is subsequently dereferenced without a check included. This patch adds a check for it to avoid any possibly null dereference. This was found via static analysis, there is not a known case right now where this issue is hit.
---
 llvm/lib/Transforms/Vectorize/VPlanUtils.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 04b6348665a05..0f83300670b68 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -410,10 +410,12 @@ bool vputils::isUniformAcrossVFsAndUFs(VPValue *V) {
     return all_of(R->operands(), isUniformAcrossVFsAndUFs);
   }
 
-  if (VPRegionBlock *EnclosingRegion = VPBB->getEnclosingLoopRegion()) {
-    // Canonical IV is uniform.
-    if (V == EnclosingRegion->getCanonicalIV())
-      return true;
+  if (VPBB) {
+    if (VPRegionBlock *EnclosingRegion = VPBB->getEnclosingLoopRegion()) {
+      // Canonical IV is uniform.
+      if (V == EnclosingRegion->getCanonicalIV())
+        return true;
+    }
   }
 
   return TypeSwitch<const VPRecipeBase *, bool>(R)



More information about the llvm-commits mailing list