Skip to content

Commit a292214

Browse files
[SYCL] Mark kernel object as invalid if incorrect accessor format (#4274)
If kernel object is marked invalid, we do not continue processing it, i.e. the compiler does not proceed to generate the corresponding openCL kernel. Invalid captures/kernel object fields should cause kernel object to be marked as invalid. This patch fixes a bug where invalid accessors did not do so. Part 1 of fix for - #4115 Signed-off-by: Elizabeth Andrews <[email protected]>
1 parent 349c798 commit a292214

File tree

2 files changed

+68
-64
lines changed

2 files changed

+68
-64
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,71 +1605,71 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
16051605
return false;
16061606
}
16071607

1608-
void checkPropertyListType(TemplateArgument PropList, SourceLocation Loc) {
1609-
if (PropList.getKind() != TemplateArgument::ArgKind::Type) {
1610-
SemaRef.Diag(Loc,
1611-
diag::err_sycl_invalid_accessor_property_template_param);
1612-
return;
1613-
}
1608+
bool checkPropertyListType(TemplateArgument PropList, SourceLocation Loc) {
1609+
if (PropList.getKind() != TemplateArgument::ArgKind::Type)
1610+
return SemaRef.Diag(
1611+
Loc, diag::err_sycl_invalid_accessor_property_template_param);
1612+
16141613
QualType PropListTy = PropList.getAsType();
1615-
if (!Util::isAccessorPropertyListType(PropListTy)) {
1616-
SemaRef.Diag(Loc,
1617-
diag::err_sycl_invalid_accessor_property_template_param);
1618-
return;
1619-
}
1614+
if (!Util::isAccessorPropertyListType(PropListTy))
1615+
return SemaRef.Diag(
1616+
Loc, diag::err_sycl_invalid_accessor_property_template_param);
1617+
16201618
const auto *AccPropListDecl =
16211619
cast<ClassTemplateSpecializationDecl>(PropListTy->getAsRecordDecl());
1622-
if (AccPropListDecl->getTemplateArgs().size() != 1) {
1623-
SemaRef.Diag(Loc, diag::err_sycl_invalid_property_list_param_number)
1624-
<< "accessor_property_list";
1625-
return;
1626-
}
1620+
if (AccPropListDecl->getTemplateArgs().size() != 1)
1621+
return SemaRef.Diag(Loc,
1622+
diag::err_sycl_invalid_property_list_param_number)
1623+
<< "accessor_property_list";
1624+
16271625
const auto TemplArg = AccPropListDecl->getTemplateArgs()[0];
1628-
if (TemplArg.getKind() != TemplateArgument::ArgKind::Pack) {
1629-
SemaRef.Diag(Loc,
1630-
diag::err_sycl_invalid_accessor_property_list_template_param)
1631-
<< /*accessor_property_list*/ 0 << /*parameter pack*/ 0;
1632-
return;
1633-
}
1626+
if (TemplArg.getKind() != TemplateArgument::ArgKind::Pack)
1627+
return SemaRef.Diag(
1628+
Loc,
1629+
diag::err_sycl_invalid_accessor_property_list_template_param)
1630+
<< /*accessor_property_list*/ 0 << /*parameter pack*/ 0;
1631+
16341632
for (TemplateArgument::pack_iterator Prop = TemplArg.pack_begin();
16351633
Prop != TemplArg.pack_end(); ++Prop) {
1636-
if (Prop->getKind() != TemplateArgument::ArgKind::Type) {
1637-
SemaRef.Diag(
1638-
Loc, diag::err_sycl_invalid_accessor_property_list_template_param)
1639-
<< /*accessor_property_list pack argument*/ 1 << /*type*/ 1;
1640-
return;
1641-
}
1634+
if (Prop->getKind() != TemplateArgument::ArgKind::Type)
1635+
return SemaRef.Diag(
1636+
Loc,
1637+
diag::err_sycl_invalid_accessor_property_list_template_param)
1638+
<< /*accessor_property_list pack argument*/ 1 << /*type*/ 1;
16421639
QualType PropTy = Prop->getAsType();
1643-
if (Util::isSyclBufferLocationType(PropTy))
1644-
checkBufferLocationType(PropTy, Loc);
1640+
if (Util::isSyclBufferLocationType(PropTy) &&
1641+
checkBufferLocationType(PropTy, Loc))
1642+
return true;
16451643
}
1644+
return false;
16461645
}
16471646

1648-
void checkBufferLocationType(QualType PropTy, SourceLocation Loc) {
1647+
bool checkBufferLocationType(QualType PropTy, SourceLocation Loc) {
16491648
const auto *PropDecl =
16501649
cast<ClassTemplateSpecializationDecl>(PropTy->getAsRecordDecl());
1651-
if (PropDecl->getTemplateArgs().size() != 1) {
1652-
SemaRef.Diag(Loc, diag::err_sycl_invalid_property_list_param_number)
1653-
<< "buffer_location";
1654-
return;
1655-
}
1650+
if (PropDecl->getTemplateArgs().size() != 1)
1651+
return SemaRef.Diag(Loc,
1652+
diag::err_sycl_invalid_property_list_param_number)
1653+
<< "buffer_location";
1654+
16561655
const auto BufferLoc = PropDecl->getTemplateArgs()[0];
1657-
if (BufferLoc.getKind() != TemplateArgument::ArgKind::Integral) {
1658-
SemaRef.Diag(Loc,
1659-
diag::err_sycl_invalid_accessor_property_list_template_param)
1660-
<< /*buffer_location*/ 2 << /*non-negative integer*/ 2;
1661-
return;
1662-
}
1656+
if (BufferLoc.getKind() != TemplateArgument::ArgKind::Integral)
1657+
return SemaRef.Diag(
1658+
Loc,
1659+
diag::err_sycl_invalid_accessor_property_list_template_param)
1660+
<< /*buffer_location*/ 2 << /*non-negative integer*/ 2;
1661+
16631662
int LocationID = static_cast<int>(BufferLoc.getAsIntegral().getExtValue());
1664-
if (LocationID < 0) {
1665-
SemaRef.Diag(Loc,
1666-
diag::err_sycl_invalid_accessor_property_list_template_param)
1667-
<< /*buffer_location*/ 2 << /*non-negative integer*/ 2;
1668-
return;
1669-
}
1663+
if (LocationID < 0)
1664+
return SemaRef.Diag(
1665+
Loc,
1666+
diag::err_sycl_invalid_accessor_property_list_template_param)
1667+
<< /*buffer_location*/ 2 << /*non-negative integer*/ 2;
1668+
1669+
return false;
16701670
}
16711671

1672-
void checkAccessorType(QualType Ty, SourceRange Loc) {
1672+
bool checkAccessorType(QualType Ty, SourceRange Loc) {
16731673
assert(Util::isSyclAccessorType(Ty) &&
16741674
"Should only be called on SYCL accessor types.");
16751675

@@ -1678,13 +1678,13 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
16781678
dyn_cast<ClassTemplateSpecializationDecl>(RecD)) {
16791679
const TemplateArgumentList &TAL = CTSD->getTemplateArgs();
16801680
TemplateArgument TA = TAL.get(0);
1681-
const QualType TemplateArgTy = TA.getAsType();
1681+
llvm::DenseSet<QualType> Visited;
1682+
checkSYCLType(SemaRef, TA.getAsType(), Loc, Visited);
16821683

16831684
if (TAL.size() > 5)
1684-
checkPropertyListType(TAL.get(5), Loc.getBegin());
1685-
llvm::DenseSet<QualType> Visited;
1686-
checkSYCLType(SemaRef, TemplateArgTy, Loc, Visited);
1685+
return checkPropertyListType(TAL.get(5), Loc.getBegin());
16871686
}
1687+
return false;
16881688
}
16891689

16901690
public:
@@ -1706,12 +1706,12 @@ class SyclKernelFieldChecker : public SyclKernelFieldHandler {
17061706

17071707
bool handleSyclAccessorType(const CXXRecordDecl *, const CXXBaseSpecifier &BS,
17081708
QualType FieldTy) final {
1709-
checkAccessorType(FieldTy, BS.getBeginLoc());
1709+
IsInvalid |= checkAccessorType(FieldTy, BS.getBeginLoc());
17101710
return isValid();
17111711
}
17121712

17131713
bool handleSyclAccessorType(FieldDecl *FD, QualType FieldTy) final {
1714-
checkAccessorType(FieldTy, FD->getLocation());
1714+
IsInvalid |= checkAccessorType(FieldTy, FD->getLocation());
17151715
return isValid();
17161716
}
17171717

clang/test/SemaSYCL/buffer_location.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ int main() {
5454
cl::sycl::ext::oneapi::accessor_property_list<
5555
another_property>>
5656
accessorC;
57+
58+
cl::sycl::kernel_single_task<class kernel_function>(
59+
[=]() {
60+
// expected-no-diagnostics
61+
Obj.use();
62+
accessorA.use();
63+
accessorB.use();
64+
accessorC.use();
65+
});
5766
#else
5867
cl::sycl::accessor<int, 1, cl::sycl::access::mode::read_write,
5968
cl::sycl::access::target::global_buffer,
@@ -72,23 +81,18 @@ int main() {
7281
buffer_location<1>,
7382
buffer_location<2>>>
7483
accessorF;
75-
#endif
7684
cl::sycl::kernel_single_task<class kernel_function>(
7785
[=]() {
78-
#ifndef TRIGGER_ERROR
79-
// expected-no-diagnostics
80-
Obj.use();
81-
accessorA.use();
82-
accessorB.use();
83-
accessorC.use();
84-
#else
8586
//expected-error@+1{{buffer_location template parameter must be a non-negative integer}}
8687
accessorD.use();
8788
//expected-error@+1{{sixth template parameter of the accessor must be of accessor_property_list type}}
8889
accessorE.use();
90+
});
91+
cl::sycl::kernel_single_task<class kernel_function>(
92+
[=]() {
8993
//expected-error@+1{{can't apply buffer_location property twice to the same accessor}}
9094
accessorF.use();
91-
#endif
9295
});
96+
#endif
9397
return 0;
9498
}

0 commit comments

Comments
 (0)