Skip to content

Commit df2725f

Browse files
authored
[Clang][OpenMP] Return empty QualType when a negative array was created (#71552)
Fix #69198
1 parent 9774d0c commit df2725f

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,10 +4983,10 @@ QualType OMPArraySectionExpr::getBaseOriginalType(const Expr *Base) {
49834983
for (unsigned Cnt = 0; Cnt < ArraySectionCount; ++Cnt) {
49844984
if (OriginalTy->isAnyPointerType())
49854985
OriginalTy = OriginalTy->getPointeeType();
4986-
else {
4987-
assert (OriginalTy->isArrayType());
4986+
else if (OriginalTy->isArrayType())
49884987
OriginalTy = OriginalTy->castAsArrayTypeUnsafe()->getElementType();
4989-
}
4988+
else
4989+
return {};
49904990
}
49914991
return OriginalTy;
49924992
}

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21014,6 +21014,8 @@ Sema::ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data,
2101421014
if (OASE) {
2101521015
QualType BaseType =
2101621016
OMPArraySectionExpr::getBaseOriginalType(OASE->getBase());
21017+
if (BaseType.isNull())
21018+
return nullptr;
2101721019
if (const auto *ATy = BaseType->getAsArrayTypeUnsafe())
2101821020
ExprTy = ATy->getElementType();
2101921021
else

clang/test/OpenMP/bug69198.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -fopenmp -x c %s
2+
3+
int c[-1]; // expected-error {{'c' declared as an array with a negative size}}
4+
5+
void foo (){
6+
#pragma omp task depend(inout: c[:][:])
7+
{
8+
c[0] = 1;
9+
}
10+
}

0 commit comments

Comments
 (0)