[clang] [Clang/AMDGPU] Zero sized arrays not allowed in HIP device code. (PR #113470)
Vigneshwar Jayakumar via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 28 08:06:42 PDT 2024
================
@@ -8714,6 +8714,31 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) {
}
}
+ // zero sized static arrays are not allowed in HIP device functions
+ if (LangOpts.CUDAIsDevice && LangOpts.HIP) {
+ if (FunctionDecl *FD = getCurFunctionDecl();
+ FD &&
+ (FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>())) {
+
+ auto Check = [&](QualType TypeToCheck, const VarDecl *VD) {
+ if (const ConstantArrayType *ArrayT =
+ getASTContext().getAsConstantArrayType(TypeToCheck);
+ ArrayT && ArrayT->isZeroSize()) {
+ Diag(VD->getLocation(), diag::err_typecheck_zero_array_size) << 2;
+ }
+ };
+ QualType NextTy = NewVD->getType();
+ while (NextTy->isAnyPointerType() || NextTy->isArrayType() ||
+ NextTy->isReferenceType()) {
----------------
VigneshwarJ wrote:
Yes, you are right. I got confused. That would not cause any issue, The while logic is unnecessary, updated to simply check if its an array type.
https://github.com/llvm/llvm-project/pull/113470
More information about the cfe-commits
mailing list