[clang] e8dff7b - [OpenACC] Fix location of array-section diagnostic.
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 20 09:04:36 PDT 2025
Author: erichkeane
Date: 2025-05-20T09:04:32-07:00
New Revision: e8dff7bea468525ec966061324baed88d67b025d
URL: https://github.com/llvm/llvm-project/commit/e8dff7bea468525ec966061324baed88d67b025d
DIFF: https://github.com/llvm/llvm-project/commit/e8dff7bea468525ec966061324baed88d67b025d.diff
LOG: [OpenACC] Fix location of array-section diagnostic.
In a sub-subscript of an array-section, it is actually an array section.
So make sure we get the location correct when there isn't a 'colon' to
look at.
Added:
Modified:
clang/lib/Sema/SemaOpenACC.cpp
clang/test/SemaOpenACC/compute-construct-copy-clause.c
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index cd045996f60b6..f8ed8a8db29ae 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -757,11 +757,12 @@ ExprResult SemaOpenACC::ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc,
!OriginalBaseTy->isConstantArrayType() &&
!OriginalBaseTy->isDependentSizedArrayType()))) {
bool IsArray = !OriginalBaseTy.isNull() && OriginalBaseTy->isArrayType();
- Diag(ColonLoc, diag::err_acc_subarray_no_length) << IsArray;
+ SourceLocation DiagLoc = ColonLoc.isInvalid() ? LBLoc : ColonLoc;
+ Diag(DiagLoc, diag::err_acc_subarray_no_length) << IsArray;
// Fill in a dummy 'length' so that when we instantiate this we don't
// double-diagnose here.
ExprResult Recovery = SemaRef.CreateRecoveryExpr(
- ColonLoc, SourceLocation(), ArrayRef<Expr *>(), Context.IntTy);
+ DiagLoc, SourceLocation(), ArrayRef<Expr *>(), Context.IntTy);
Length = Recovery.isUsable() ? Recovery.get() : nullptr;
}
diff --git a/clang/test/SemaOpenACC/compute-construct-copy-clause.c b/clang/test/SemaOpenACC/compute-construct-copy-clause.c
index e83bdab64c246..67682488fbe89 100644
--- a/clang/test/SemaOpenACC/compute-construct-copy-clause.c
+++ b/clang/test/SemaOpenACC/compute-construct-copy-clause.c
@@ -69,6 +69,19 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
// expected-error at +1{{OpenACC 'present_or_copy' clause is not valid on 'loop' directive}}
#pragma acc loop present_or_copy(LocalInt)
for(int i = 5; i < 10;++i);
+
+ short *ArrayOfPtrs[5];
+#pragma acc parallel copy(ArrayOfPtrs[1:1])
+ ;
+ // expected-error at +1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
+#pragma acc parallel copy(ArrayOfPtrs[1:1][1])
+ ;
+ // expected-error at +1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
+#pragma acc parallel copy(ArrayOfPtrs[1:1][1:])
+ ;
+#pragma acc parallel copy(ArrayOfPtrs[1:1][1:2])
+ ;
+
}
void ModList() {
int V1;
More information about the cfe-commits
mailing list