Skip to content

Commit 5c30093

Browse files
committed
Move diagnostics + don't rely on params order
Signed-off-by: Dmitry Sidorov <[email protected]>
1 parent d6cee4f commit 5c30093

File tree

4 files changed

+64
-44
lines changed

4 files changed

+64
-44
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,9 @@ the number of kernel parameters. The metadata contains an integer that is set
20072007
according to the values passed through the ``accessor`` property
20082008
``buffer_location``. These values are mapped to the actual locations of the
20092009
global buffers (such as DDR, QDR, etc) and applied to pointer kernel parameters.
2010-
The default value is -1.
2010+
Number of metadata arguments is the same as a number of kernel parameters, so
2011+
any parameter that isn't an ``accessor`` with ``buffer_location`` property is
2012+
annotated by '-1' in the metadata node.
20112013
}];
20122014
}
20132015

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10976,9 +10976,11 @@ def err_sycl_attibute_cannot_be_applied_here
1097610976
"static function or function in an anonymous namespace">;
1097710977
def err_sycl_compiletime_property_duplication : Error<
1097810978
"Can't apply %0 property twice to the same accessor">;
10979-
def err_sycl_invalid_property_template_param : Error<
10979+
def err_sycl_invalid_property_list_template_param : Error<
1098010980
"%0 template parameter must be a "
10981-
"%select{parameter pack|type|non-negative integer|property_list}1">;
10981+
"%select{parameter pack|type|non-negative integer}1">;
10982+
def err_sycl_invalid_accessor_property_template_param : Error<
10983+
"Fifth template parameter of the accessor must be of a property_list type">;
1098210984
def warn_sycl_attibute_function_raw_ptr
1098310985
: Warning<"SYCL 1.2.1 specification does not allow %0 attribute applied "
1098410986
"to a function with a raw pointer "

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,51 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
10841084
return false;
10851085
}
10861086

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+
10871132
void checkAccessorType(QualType Ty, SourceRange Loc) {
10881133
assert(Util::isSyclAccessorType(Ty) &&
10891134
"Should only be called on SYCL accessor types.");
@@ -1095,6 +1140,8 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
10951140
TemplateArgument TA = TAL.get(0);
10961141
const QualType TemplateArgTy = TA.getAsType();
10971142

1143+
if (TAL.size() > 5)
1144+
checkPropertyListType(TAL.get(5), Loc.getBegin());
10981145
llvm::DenseSet<QualType> Visited;
10991146
checkSYCLType(SemaRef, TemplateArgTy, Loc, Visited);
11001147
}
@@ -1188,26 +1235,10 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
11881235
if (AccTy->getTemplateArgs().size() < 6)
11891236
return;
11901237
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-
}
11961238
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-
12031239
const auto *PropListDecl =
12041240
cast<ClassTemplateSpecializationDecl>(PropListTy->getAsRecordDecl());
12051241
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-
}
12111242
// Move through TemplateArgs list of a property list and search for
12121243
// properties. If found - apply the appropriate attribute to ParmVarDecl.
12131244
for (TemplateArgument::pack_iterator Prop = TemplArg.pack_begin();
@@ -1233,17 +1264,7 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
12331264
const auto *PropDecl =
12341265
cast<ClassTemplateSpecializationDecl>(PropTy->getAsRecordDecl());
12351266
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-
}
12411267
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-
}
12471268
Param->addAttr(
12481269
SYCLIntelBufferLocationAttr::CreateImplicit(Ctx, LocationID));
12491270
}
@@ -1262,15 +1283,12 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
12621283
// Don't do -1 here because we count on this to be the first parameter added
12631284
// (if any).
12641285
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)
12691290
handleAccessorPropertyList(Params.back(), RecordDecl,
12701291
FD->getLocation());
1271-
++ParamIt;
1272-
for (; ParamIt != InitMethod->parameters().end(); ++ParamIt)
1273-
addParam(FD, (*ParamIt)->getType().getCanonicalType());
12741292
}
12751293
LastParamIndex = ParamIndex;
12761294
return true;
@@ -1341,13 +1359,11 @@ class SyclKernelDeclCreator : public SyclKernelFieldHandler {
13411359
// Don't do -1 here because we count on this to be the first parameter added
13421360
// (if any).
13431361
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());
13511367
}
13521368
LastParamIndex = ParamIndex;
13531369
return true;

clang/test/SemaSYCL/buffer_location.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int main() {
8282
#else
8383
//expected-error@+1{{buffer_location template parameter must be a non-negative integer}}
8484
accessorD.use();
85-
//expected-error@+1{{accessor's 5th template parameter must be a property_list}}
85+
//expected-error@+1{{Fifth template parameter of the accessor must be of a property_list type}}
8686
accessorE.use();
8787
//expected-error@+1{{Can't apply buffer_location property twice to the same accessor}}
8888
accessorF.use();

0 commit comments

Comments
 (0)