Skip to content

Commit e8dff7b

Browse files
committed
[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.
1 parent 4a0ae4f commit e8dff7b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/Sema/SemaOpenACC.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,12 @@ ExprResult SemaOpenACC::ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc,
757757
!OriginalBaseTy->isConstantArrayType() &&
758758
!OriginalBaseTy->isDependentSizedArrayType()))) {
759759
bool IsArray = !OriginalBaseTy.isNull() && OriginalBaseTy->isArrayType();
760-
Diag(ColonLoc, diag::err_acc_subarray_no_length) << IsArray;
760+
SourceLocation DiagLoc = ColonLoc.isInvalid() ? LBLoc : ColonLoc;
761+
Diag(DiagLoc, diag::err_acc_subarray_no_length) << IsArray;
761762
// Fill in a dummy 'length' so that when we instantiate this we don't
762763
// double-diagnose here.
763764
ExprResult Recovery = SemaRef.CreateRecoveryExpr(
764-
ColonLoc, SourceLocation(), ArrayRef<Expr *>(), Context.IntTy);
765+
DiagLoc, SourceLocation(), ArrayRef<Expr *>(), Context.IntTy);
765766
Length = Recovery.isUsable() ? Recovery.get() : nullptr;
766767
}
767768

clang/test/SemaOpenACC/compute-construct-copy-clause.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ void uses(int IntParam, short *PointerParam, float ArrayParam[5], Complete Compo
6969
// expected-error@+1{{OpenACC 'present_or_copy' clause is not valid on 'loop' directive}}
7070
#pragma acc loop present_or_copy(LocalInt)
7171
for(int i = 5; i < 10;++i);
72+
73+
short *ArrayOfPtrs[5];
74+
#pragma acc parallel copy(ArrayOfPtrs[1:1])
75+
;
76+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
77+
#pragma acc parallel copy(ArrayOfPtrs[1:1][1])
78+
;
79+
// expected-error@+1{{OpenACC sub-array length is unspecified and cannot be inferred because the subscripted value is not an array}}
80+
#pragma acc parallel copy(ArrayOfPtrs[1:1][1:])
81+
;
82+
#pragma acc parallel copy(ArrayOfPtrs[1:1][1:2])
83+
;
84+
7285
}
7386
void ModList() {
7487
int V1;

0 commit comments

Comments
 (0)