[clang] [Clang][OpenMP] Ignore the null array and avoid the assertion. (PR #71551)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 7 07:52:10 PST 2023


https://github.com/lwshanbd created https://github.com/llvm/llvm-project/pull/71551

Fixes #69198.

>From c9f0185489389762a13417533e3b2c7a306e53e0 Mon Sep 17 00:00:00 2001
From: Baodi Shan <lwshanbd at gmail.com>
Date: Tue, 7 Nov 2023 10:33:28 -0500
Subject: [PATCH] Ignore the null array and avoid the assertion. Fixes
 llvm#69198

---
 clang/lib/AST/Expr.cpp        | 6 +++---
 clang/lib/Sema/SemaOpenMP.cpp | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 74a9c49a795b4fc..55c6b732b7081f4 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4983,10 +4983,10 @@ QualType OMPArraySectionExpr::getBaseOriginalType(const Expr *Base) {
   for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
     if (OriginalTy->isAnyPointerType())
       OriginalTy = OriginalTy->getPointeeType();
-    else {
-      assert (OriginalTy->isArrayType());
+    else if (OriginalTy->isArrayType())
       OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
-    }
+    else
+      return {};
   }
   return OriginalTy;
 }
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index e05fa54d8118319..dcdd6e7a3f5c762 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -21014,6 +21014,8 @@ Sema::ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
           if (OASE) {
             QualType BaseType =
                 OMPArraySectionExpr::getBaseOriginalType(OASE->getBase());
+            if (BaseType.isNull())
+              return nullptr;
             if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
               ExprTy = ATy->getElementType();
             else



More information about the cfe-commits mailing list