Skip to content

[SYCL][SCLA] Check allocated types are trivial #13105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def err_intel_sycl_alloca_wrong_arg
"'sycl::kernel_handler &'. Got %0">;
def err_intel_sycl_alloca_wrong_type
: Error<"__builtin_intel_sycl_alloca can only return 'sycl::private_ptr' "
"to a cv-unqualified object type. Got %0">;
"to a cv-unqualified trivial type. Got %0">;
def err_intel_sycl_alloca_wrong_size
: Error<"__builtin_intel_sycl_alloca must be passed a specialization "
"constant of integral value type as a template argument. Got %1 (%0)">;
Expand Down
10 changes: 5 additions & 5 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7809,22 +7809,22 @@ bool Sema::CheckIntelSYCLAllocaBuiltinFunctionCall(unsigned, CallExpr *Call) {

// Check the return type is `sycl::multi_ptr<ET,
// sycl::access::address_space::private_space, DecoratedAddress>`:
// - `ET`: non-const, non-volatile, non-void, non-function, non-reference type
constexpr auto CheckType = [](QualType RT) {
// - `ET`: cv-unqualified trivial type
constexpr auto CheckType = [](QualType RT, const ASTContext &Ctx) {
if (!isSyclType(RT, SYCLTypeAttr::multi_ptr))
return true;
// Check element type
const TemplateArgumentList &TAL =
cast<ClassTemplateSpecializationDecl>(RT->getAsRecordDecl())
->getTemplateArgs();
QualType ET = TAL.get(0).getAsType();
if (ET.isConstQualified() || ET.isVolatileQualified() || ET->isVoidType() ||
ET->isFunctionType() || ET->isReferenceType())
if (ET.isConstQualified() || ET.isVolatileQualified() ||
!ET.isTrivialType(Ctx))
return true;
constexpr uint64_t PrivateAS = 0;
return TAL.get(1).getAsIntegral() != PrivateAS;
};
if (CheckType(FD->getReturnType())) {
if (CheckType(FD->getReturnType(), getASTContext())) {
Diag(Loc, diag::err_intel_sycl_alloca_wrong_type) << FD->getReturnType();
return true;
}
Expand Down
17 changes: 11 additions & 6 deletions clang/test/SemaSYCL/builtin-alloca-errors-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ constexpr sycl::specialization_id<float> badsize(1);

struct wrapped_int { int a; };

struct non_trivial { int a = 1; };

template <typename ElementType, auto &Size,
sycl::access::decorated DecorateAddress>
__SYCL_BUILTIN_ALIAS(__builtin_intel_sycl_alloca)
Expand Down Expand Up @@ -88,24 +90,27 @@ void test(sycl::kernel_handler &h) {
// expected-error@+1 {{__builtin_intel_sycl_alloca expects to be passed an argument of type 'sycl::kernel_handler &'. Got 'const sycl::kernel_handler &'}}
private_alloca_bad_5<float, size, sycl::access::decorated::yes>(h);

// 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>'}}
// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<const float, size, sycl::access::decorated::no>(h);

// 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>'}}
// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<volatile float, size, sycl::access::decorated::no>(h);

// 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>'}}
// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<void, size, sycl::access::decorated::yes>(h);

// 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>'}}
// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<int *(int), size, sycl::access::decorated::no>(h);

// 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>'}}
// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<int &, size, sycl::access::decorated::no>(h);

// 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>'}}
// 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>'}}
private_alloca_bad_6<float, size, sycl::access::decorated::no>(h);

// 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>'}}
sycl::ext::oneapi::experimental::private_alloca<non_trivial, size, sycl::access::decorated::yes>(h);

// expected-error@+1 {{__builtin_intel_sycl_alloca must be passed a specialization constant of integral value type as a template argument. Got 'int'}}
private_alloca_bad_7<float, int, sycl::access::decorated::no>(h);

Expand Down