[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 20 15:01:16 PDT 2024


https://github.com/smanna12 created https://github.com/llvm/llvm-project/pull/86018

This patch fixes potential dereferences in <unnamed>::MappableExprsHandler::generateInfoForComponentList() for passing null pointer OASE to EmitOMPArraySectionExpr().

>From 09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Wed, 20 Mar 2024 14:57:32 -0700
Subject: [PATCH] [NFC][Clang] Fix static analyzer bugs with dereference after
 null checks

This patch fixes potential dereferences in <unnamed>::MappableExprsHandler::generateInfoForComponentList() for passing null pointer OASE to EmitOMPArraySectionExpr().
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
           if (!PartialStruct.Base.isValid()) {
             PartialStruct.LowestElem = {FieldIndex, LowestElem};
             if (IsFinalArraySection) {
-              Address HB =
+              Address HB = OASE &&
                   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
                       .getAddress(CGF);
               PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
             PartialStruct.LowestElem = {FieldIndex, LowestElem};
           } else if (FieldIndex > PartialStruct.HighestElem.first) {
             if (IsFinalArraySection) {
-              Address HB =
+              Address HB = OASE &&
                   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
                       .getAddress(CGF);
               PartialStruct.HighestElem = {FieldIndex, HB};



More information about the cfe-commits mailing list