Skip to content

Commit ac4808a

Browse files
authored
[SYCL][SCLA] Check allocated types are trivial (#13105)
Replace check for cv-unqualified object types with a check for cv-unqualified trivial types to be in line with the `sycl_ext_oneapi_private_alloca` extension specification: > `ElementType` must be a cv-unqualified trivial type --------- Signed-off-by: Victor Perez <[email protected]>
1 parent ba5feec commit ac4808a

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def err_intel_sycl_alloca_wrong_arg
191191
"'sycl::kernel_handler &'. Got %0">;
192192
def err_intel_sycl_alloca_wrong_type
193193
: Error<"__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' "
194-
"to a cv-unqualified object type. Got %0">;
194+
"to a cv-unqualified trivial type. Got %0">;
195195
def err_intel_sycl_alloca_wrong_size
196196
: Error<"__builtin_intel_sycl_alloca must be passed a specialization "
197197
"constant of integral value type as a template argument. Got %1 (%0)">;

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7809,22 +7809,22 @@ bool Sema::CheckIntelSYCLAllocaBuiltinFunctionCall(unsigned, CallExpr *Call) {
78097809

78107810
// Check the return type is `sycl::multi_ptr<ET,
78117811
// sycl::access::address_space::private_space, DecoratedAddress>`:
7812-
// - `ET`: non-const, non-volatile, non-void, non-function, non-reference type
7813-
constexpr auto CheckType = [](QualType RT) {
7812+
// - `ET`: cv-unqualified trivial type
7813+
constexpr auto CheckType = [](QualType RT, const ASTContext &Ctx) {
78147814
if (!isSyclType(RT, SYCLTypeAttr::multi_ptr))
78157815
return true;
78167816
// Check element type
78177817
const TemplateArgumentList &TAL =
78187818
cast<ClassTemplateSpecializationDecl>(RT->getAsRecordDecl())
78197819
->getTemplateArgs();
78207820
QualType ET = TAL.get(0).getAsType();
7821-
if (ET.isConstQualified() || ET.isVolatileQualified() || ET->isVoidType() ||
7822-
ET->isFunctionType() || ET->isReferenceType())
7821+
if (ET.isConstQualified() || ET.isVolatileQualified() ||
7822+
!ET.isTrivialType(Ctx))
78237823
return true;
78247824
constexpr uint64_t PrivateAS = 0;
78257825
return TAL.get(1).getAsIntegral() != PrivateAS;
78267826
};
7827-
if (CheckType(FD->getReturnType())) {
7827+
if (CheckType(FD->getReturnType(), getASTContext())) {
78287828
Diag(Loc, diag::err_intel_sycl_alloca_wrong_type) << FD->getReturnType();
78297829
return true;
78307830
}

clang/test/SemaSYCL/builtin-alloca-errors-device.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ constexpr sycl::specialization_id<float> badsize(1);
1212

1313
struct wrapped_int { int a; };
1414

15+
struct non_trivial { int a = 1; };
16+
1517
template <typename ElementType, auto &Size,
1618
sycl::access::decorated DecorateAddress>
1719
__SYCL_BUILTIN_ALIAS(__builtin_intel_sycl_alloca)
@@ -88,24 +90,27 @@ void test(sycl::kernel_handler &h) {
8890
// expected-error@+1 {{__builtin_intel_sycl_alloca expects to be passed an argument of type 'sycl::kernel_handler &'. Got 'const sycl::kernel_handler &'}}
8991
private_alloca_bad_5<float, size, sycl::access::decorated::yes>(h);
9092

91-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'multi_ptr<const float, access::address_space::private_space, (decorated)0>'}}
93+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<const float, access::address_space::private_space, (decorated)0>'}}
9294
sycl::ext::oneapi::experimental::private_alloca<const float, size, sycl::access::decorated::no>(h);
9395

94-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'multi_ptr<volatile float, access::address_space::private_space, (decorated)0>'}}
96+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<volatile float, access::address_space::private_space, (decorated)0>'}}
9597
sycl::ext::oneapi::experimental::private_alloca<volatile float, size, sycl::access::decorated::no>(h);
9698

97-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'multi_ptr<void, access::address_space::private_space, (decorated)1>'}}
99+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<void, access::address_space::private_space, (decorated)1>'}}
98100
sycl::ext::oneapi::experimental::private_alloca<void, size, sycl::access::decorated::yes>(h);
99101

100-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'multi_ptr<int *(int), access::address_space::private_space, (decorated)0>'}}
102+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<int *(int), access::address_space::private_space, (decorated)0>'}}
101103
sycl::ext::oneapi::experimental::private_alloca<int *(int), size, sycl::access::decorated::no>(h);
102104

103-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'multi_ptr<int &, access::address_space::private_space, (decorated)0>'}}
105+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<int &, access::address_space::private_space, (decorated)0>'}}
104106
sycl::ext::oneapi::experimental::private_alloca<int &, size, sycl::access::decorated::no>(h);
105107

106-
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified object type. Got 'sycl::multi_ptr<float, sycl::access::address_space::local_space, (decorated)0>'}}
108+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'sycl::multi_ptr<float, sycl::access::address_space::local_space, (decorated)0>'}}
107109
private_alloca_bad_6<float, size, sycl::access::decorated::no>(h);
108110

111+
// expected-error@+1 {{__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' to a cv-unqualified trivial type. Got 'multi_ptr<non_trivial, access::address_space::private_space, (decorated)1>'}}
112+
sycl::ext::oneapi::experimental::private_alloca<non_trivial, size, sycl::access::decorated::yes>(h);
113+
109114
// expected-error@+1 {{__builtin_intel_sycl_alloca must be passed a specialization constant of integral value type as a template argument. Got 'int'}}
110115
private_alloca_bad_7<float, int, sycl::access::decorated::no>(h);
111116

0 commit comments

Comments
 (0)