@@ -1084,6 +1084,51 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
1084
1084
return false ;
1085
1085
}
1086
1086
1087
+ void checkPropertyListType (TemplateArgument PropList, SourceLocation Loc) {
1088
+ if (PropList.getKind () != TemplateArgument::ArgKind::Type) {
1089
+ SemaRef.Diag (Loc,
1090
+ diag::err_sycl_invalid_accessor_property_template_param);
1091
+ return ;
1092
+ }
1093
+ QualType PropListTy = PropList.getAsType ();
1094
+ if (!Util::isPropertyListType (PropListTy)) {
1095
+ SemaRef.Diag (Loc,
1096
+ diag::err_sycl_invalid_accessor_property_template_param);
1097
+ return ;
1098
+ }
1099
+ const auto *PropListDecl =
1100
+ cast<ClassTemplateSpecializationDecl>(PropListTy->getAsRecordDecl ());
1101
+ const auto TemplArg = PropListDecl->getTemplateArgs ()[0 ];
1102
+ if (TemplArg.getKind () != TemplateArgument::ArgKind::Pack) {
1103
+ SemaRef.Diag (Loc, diag::err_sycl_invalid_property_list_template_param)
1104
+ << " property_list" << /* parameter pack*/ 0 ;
1105
+ return ;
1106
+ }
1107
+ for (TemplateArgument::pack_iterator Prop = TemplArg.pack_begin ();
1108
+ Prop != TemplArg.pack_end (); ++Prop) {
1109
+ QualType PropTy = Prop->getAsType ();
1110
+ if (Util::isSyclBufferLocationType (PropTy))
1111
+ checkBufferLocationType (PropTy, Loc);
1112
+ }
1113
+ }
1114
+
1115
+ void checkBufferLocationType (QualType PropTy, SourceLocation Loc) {
1116
+ const auto *PropDecl =
1117
+ cast<ClassTemplateSpecializationDecl>(PropTy->getAsRecordDecl ());
1118
+ const auto BufferLoc = PropDecl->getTemplateArgs ()[0 ];
1119
+ if (BufferLoc.getKind () != TemplateArgument::ArgKind::Integral) {
1120
+ SemaRef.Diag (Loc, diag::err_sycl_invalid_property_list_template_param)
1121
+ << " buffer_location" << /* non-negative integer*/ 2 ;
1122
+ return ;
1123
+ }
1124
+ int LocationID = static_cast <int >(BufferLoc.getAsIntegral ().getExtValue ());
1125
+ if (LocationID < 0 ) {
1126
+ SemaRef.Diag (Loc, diag::err_sycl_invalid_property_list_template_param)
1127
+ << " buffer_location" << /* non-negative integer*/ 2 ;
1128
+ return ;
1129
+ }
1130
+ }
1131
+
1087
1132
void checkAccessorType (QualType Ty, SourceRange Loc) {
1088
1133
assert (Util::isSyclAccessorType (Ty) &&
1089
1134
" Should only be called on SYCL accessor types." );
@@ -1095,6 +1140,8 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
1095
1140
TemplateArgument TA = TAL.get (0 );
1096
1141
const QualType TemplateArgTy = TA.getAsType ();
1097
1142
1143
+ if (TAL.size () > 5 )
1144
+ checkPropertyListType (TAL.get (5 ), Loc.getBegin ());
1098
1145
llvm::DenseSet<QualType> Visited;
1099
1146
checkSYCLType (SemaRef, TemplateArgTy, Loc, Visited);
1100
1147
}
@@ -1188,26 +1235,10 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1188
1235
if (AccTy->getTemplateArgs ().size () < 6 )
1189
1236
return ;
1190
1237
const auto PropList = cast<TemplateArgument>(AccTy->getTemplateArgs ()[5 ]);
1191
- if (PropList.getKind () != TemplateArgument::ArgKind::Type) {
1192
- SemaRef.Diag (Loc, diag::err_sycl_invalid_property_template_param)
1193
- << " accessor's 5th" << /* type*/ 1 ;
1194
- return ;
1195
- }
1196
1238
QualType PropListTy = PropList.getAsType ();
1197
- if (!Util::isPropertyListType (PropListTy)) {
1198
- SemaRef.Diag (Loc, diag::err_sycl_invalid_property_template_param)
1199
- << " accessor's 5th" << /* property_list*/ 3 ;
1200
- return ;
1201
- }
1202
-
1203
1239
const auto *PropListDecl =
1204
1240
cast<ClassTemplateSpecializationDecl>(PropListTy->getAsRecordDecl ());
1205
1241
const auto TemplArg = PropListDecl->getTemplateArgs ()[0 ];
1206
- if (TemplArg.getKind () != TemplateArgument::ArgKind::Pack) {
1207
- SemaRef.Diag (Loc, diag::err_sycl_invalid_property_template_param)
1208
- << " property_list" << /* parameter pack*/ 0 ;
1209
- return ;
1210
- }
1211
1242
// Move through TemplateArgs list of a property list and search for
1212
1243
// properties. If found - apply the appropriate attribute to ParmVarDecl.
1213
1244
for (TemplateArgument::pack_iterator Prop = TemplArg.pack_begin ();
@@ -1233,17 +1264,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1233
1264
const auto *PropDecl =
1234
1265
cast<ClassTemplateSpecializationDecl>(PropTy->getAsRecordDecl ());
1235
1266
const auto BufferLoc = PropDecl->getTemplateArgs ()[0 ];
1236
- if (BufferLoc.getKind () != TemplateArgument::ArgKind::Integral) {
1237
- SemaRef.Diag (Loc, diag::err_sycl_invalid_property_template_param)
1238
- << " buffer_location" << /* non-negative integer*/ 2 ;
1239
- return ;
1240
- }
1241
1267
int LocationID = static_cast <int >(BufferLoc.getAsIntegral ().getExtValue ());
1242
- if (LocationID < 0 ) {
1243
- SemaRef.Diag (Loc, diag::err_sycl_invalid_property_template_param)
1244
- << " buffer_location" << /* non-negative integer*/ 2 ;
1245
- return ;
1246
- }
1247
1268
Param->addAttr (
1248
1269
SYCLIntelBufferLocationAttr::CreateImplicit (Ctx, LocationID));
1249
1270
}
@@ -1262,15 +1283,12 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1262
1283
// Don't do -1 here because we count on this to be the first parameter added
1263
1284
// (if any).
1264
1285
size_t ParamIndex = Params.size ();
1265
- ParmVarDecl **ParamIt = InitMethod->parameters (). begin ();
1266
- if (*ParamIt) {
1267
- addParam (FD, (*ParamIt)-> getType () .getCanonicalType ());
1268
- if (isAccessorType)
1286
+ for ( const ParmVarDecl *Param : InitMethod->parameters ()) {
1287
+ QualType ParamTy = Param-> getType ();
1288
+ addParam (FD, ParamTy .getCanonicalType ());
1289
+ if (ParamTy. getTypePtr ()-> isPointerType () && isAccessorType)
1269
1290
handleAccessorPropertyList (Params.back (), RecordDecl,
1270
1291
FD->getLocation ());
1271
- ++ParamIt;
1272
- for (; ParamIt != InitMethod->parameters ().end (); ++ParamIt)
1273
- addParam (FD, (*ParamIt)->getType ().getCanonicalType ());
1274
1292
}
1275
1293
LastParamIndex = ParamIndex;
1276
1294
return true ;
@@ -1341,13 +1359,11 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
1341
1359
// Don't do -1 here because we count on this to be the first parameter added
1342
1360
// (if any).
1343
1361
size_t ParamIndex = Params.size ();
1344
- ParmVarDecl **ParamIt = InitMethod->parameters ().begin ();
1345
- if (*ParamIt) {
1346
- addParam (BS, (*ParamIt)->getType ().getCanonicalType ());
1347
- handleAccessorPropertyList (Params.back (), RecordDecl, BS.getBeginLoc ());
1348
- ++ParamIt;
1349
- for (; ParamIt != InitMethod->parameters ().end (); ++ParamIt)
1350
- addParam (BS, (*ParamIt)->getType ().getCanonicalType ());
1362
+ for (const ParmVarDecl *Param : InitMethod->parameters ()) {
1363
+ QualType ParamTy = Param->getType ();
1364
+ addParam (BS, ParamTy.getCanonicalType ());
1365
+ if (ParamTy.getTypePtr ()->isPointerType ())
1366
+ handleAccessorPropertyList (Params.back (), RecordDecl, BS.getBeginLoc ());
1351
1367
}
1352
1368
LastParamIndex = ParamIndex;
1353
1369
return true ;
0 commit comments