[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 19:15:27 PDT 2024
https://github.com/smanna12 updated https://github.com/llvm/llvm-project/pull/86018
>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 1/3] [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};
>From b55669044d397320a153c9b8940a4d1dc2f17af7 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Wed, 20 Mar 2024 15:07:39 -0700
Subject: [PATCH 2/3] Fix clang format errors
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e89a5368fb2f71..166f84d948fb91 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,9 +7431,9 @@ class MappableExprsHandler {
if (!PartialStruct.Base.isValid()) {
PartialStruct.LowestElem = {FieldIndex, LowestElem};
if (IsFinalArraySection) {
- Address HB = OASE &&
- CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
- .getAddress(CGF);
+ Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+ OASE, /*IsLowerBound=*/false)
+ .getAddress(CGF);
PartialStruct.HighestElem = {FieldIndex, HB};
} else {
PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7444,9 +7444,9 @@ class MappableExprsHandler {
PartialStruct.LowestElem = {FieldIndex, LowestElem};
} else if (FieldIndex > PartialStruct.HighestElem.first) {
if (IsFinalArraySection) {
- Address HB = OASE &&
- CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
- .getAddress(CGF);
+ Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+ OASE, /*IsLowerBound=*/false)
+ .getAddress(CGF);
PartialStruct.HighestElem = {FieldIndex, HB};
} else {
PartialStruct.HighestElem = {FieldIndex, LowestElem};
>From b80a60e0bd8959a6e6835209c5f5bacc6f4fea02 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" <soumi.manna at intel.com>
Date: Wed, 20 Mar 2024 19:14:21 -0700
Subject: [PATCH 3/3] Fix build failures
---
clang/lib/CodeGen/CGOpenMPRuntime.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 166f84d948fb91..6ebdbde80430e9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7430,10 +7430,10 @@ class MappableExprsHandler {
// Update info about the lowest and highest elements for this struct
if (!PartialStruct.Base.isValid()) {
PartialStruct.LowestElem = {FieldIndex, LowestElem};
- if (IsFinalArraySection) {
- Address HB = OASE && CGF.EmitOMPArraySectionExpr(
- OASE, /*IsLowerBound=*/false)
- .getAddress(CGF);
+ if (OASE && IsFinalArraySection) {
+ Address HB =
+ CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+ .getAddress(CGF);
PartialStruct.HighestElem = {FieldIndex, HB};
} else {
PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7443,10 +7443,10 @@ class MappableExprsHandler {
} else if (FieldIndex < PartialStruct.LowestElem.first) {
PartialStruct.LowestElem = {FieldIndex, LowestElem};
} else if (FieldIndex > PartialStruct.HighestElem.first) {
- if (IsFinalArraySection) {
- Address HB = OASE && CGF.EmitOMPArraySectionExpr(
- OASE, /*IsLowerBound=*/false)
- .getAddress(CGF);
+ if (OASE && IsFinalArraySection) {
+ Address HB =
+ CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+ .getAddress(CGF);
PartialStruct.HighestElem = {FieldIndex, HB};
} else {
PartialStruct.HighestElem = {FieldIndex, LowestElem};
More information about the cfe-commits
mailing list