Skip to content

Commit

Permalink
[Clang][OpenMP] Return empty QualType when a negative array was creat…
Browse files Browse the repository at this point in the history
…ed (#71552)

Fix #69198
  • Loading branch information
lwshanbd committed Nov 10, 2023
1 parent 9774d0c commit df2725f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions clang/lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions clang/test/OpenMP/bug69198.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %clang_cc1 -verify -fsyntax-only -fopenmp -x c %s

int c[-1]; // expected-error {{'c' declared as an array with a negative size}}

void foo (){
#pragma omp task depend(inout: c[:][:])
{
c[0] = 1;
}
}

0 comments on commit df2725f

Please sign in to comment.