[clang] [Clang][OpenMP]Return null expr when a negative array was created. (PR #71552)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 7 10:22:31 PST 2023
https://github.com/lwshanbd updated https://github.com/llvm/llvm-project/pull/71552
>From 009afe8df3f17ba3b0f793ce144b8be41b15c90d Mon Sep 17 00:00:00 2001
From: Baodi Shan <lwshanbd at gmail.com>
Date: Tue, 7 Nov 2023 11:06:14 -0500
Subject: [PATCH 1/2] Return null expr when a negative array was created. Fix
llvm#69198
---
clang/lib/AST/Expr.cpp | 6 +++---
clang/lib/Sema/SemaOpenMP.cpp | 2 ++
clang/test/OpenMP/bug69198.c | 8 ++++++++
3 files changed, 13 insertions(+), 3 deletions(-)
create mode 100644 clang/test/OpenMP/bug69198.c
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
diff --git a/clang/test/OpenMP/bug69198.c b/clang/test/OpenMP/bug69198.c
new file mode 100644
index 000000000000000..ca80d994ea051b0
--- /dev/null
+++ b/clang/test/OpenMP/bug69198.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-apple-darwin10 %s
+// expected-no-diagnostics
+
+int c[-1];
+
+void foo (){
+ #pragma omp task depend(inout: c[:][:])
+}
>From 2853ed38590a4b29d095af03996506ae203ce928 Mon Sep 17 00:00:00 2001
From: Baodi Shan <lwshanbd at gmail.com>
Date: Tue, 7 Nov 2023 13:21:35 -0500
Subject: [PATCH 2/2] [Clang][OpenMP]: modify test for PR #71552
---
clang/test/OpenMP/bug69198.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/clang/test/OpenMP/bug69198.c b/clang/test/OpenMP/bug69198.c
index ca80d994ea051b0..10fabf46652b1dc 100644
--- a/clang/test/OpenMP/bug69198.c
+++ b/clang/test/OpenMP/bug69198.c
@@ -1,5 +1,4 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c -triple x86_64-apple-darwin10 %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -verify -fsyntax-only -fopenmp -x c %s
int c[-1];
More information about the cfe-commits
mailing list