Skip to content

Commit d613d59

Browse files
committed
review changes
1 parent a7065f4 commit d613d59

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8715,11 +8715,12 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
87158715
}
87168716

87178717
// zero sized static arrays are not allowed in HIP device functions
8718-
if (getLangOpts().HIP &&
8719-
DeclAttrsMatchCUDAMode(getLangOpts(), getCurFunctionDecl())) {
8720-
if (QualType NextTy = NewVD->getType(); NextTy->isArrayType()) {
8718+
if (getLangOpts().HIP && LangOpts.CUDAIsDevice) {
8719+
if (FunctionDecl *FD = getCurFunctionDecl();
8720+
FD &&
8721+
(FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>())) {
87218722
if (const ConstantArrayType *ArrayT =
8722-
getASTContext().getAsConstantArrayType(NextTy);
8723+
getASTContext().getAsConstantArrayType(T);
87238724
ArrayT && ArrayT->isZeroSize()) {
87248725
Diag(NewVD->getLocation(), diag::err_typecheck_zero_array_size) << 2;
87258726
}

clang/test/SemaHIP/zero-sized-device-array.hip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
typedef float ZEROARR[0];
99

10+
float global_array[0];
11+
1012
__global__ void global_fun() {
1113
extern __shared__ float externArray[];
1214
ZEROARR TypeDef; // expected-error {{zero-length arrays are not permitted in HIP device code}}

0 commit comments

Comments
 (0)