mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-17 03:26:48 +00:00

The `sycl_kernel_entry_point` attribute is used to declare a function that defines a pattern for an offload kernel entry point. The attribute requires a single type argument that specifies a class type that meets the requirements for a SYCL kernel name as described in section 5.2, "Naming of kernels", of the SYCL 2020 specification. A unique kernel name type is required for each function declared with the attribute. The attribute may not first appear on a declaration that follows a definition of the function. The function is required to have a non-deduced `void` return type. The function must not be a non-static member function, be deleted or defaulted, be declared with the `constexpr` or `consteval` specifiers, be declared with the `[[noreturn]]` attribute, be a coroutine, or accept variadic arguments. Diagnostics are not yet provided for the following: - Use of a type as a kernel name that does not satisfy the forward declarability requirements specified in section 5.2, "Naming of kernels", of the SYCL 2020 specification. - Use of a type as a parameter of the attributed function that does not satisfy the kernel parameter requirements specified in section 4.12.4, "Rules for parameter passing to kernels", of the SYCL 2020 specification (each such function parameter constitutes a kernel parameter). - Use of language features that are not permitted in device functions as specified in section 5.4, "Language restrictions for device functions", of the SYCL 2020 specification. There are several issues noted by various FIXME comments. - The diagnostic generated for kernel name conflicts needs additional work to better detail the relevant source locations; such as the location of each declaration as well as the original source of each kernel name. - A number of the tests illustrate spurious errors being produced due to attributes that appertain to function templates being instantiated too early (during overload resolution as opposed to after an overload is selected). Included changes allow the `SYCLKernelEntryPointAttr` attribute to be marked as invalid if a `sycl_kernel_entry_point` attribute is used incorrectly. This is intended to prevent trying to emit an offload kernel entry point without having to mark the associated function as invalid since doing so would affect overload resolution; which this attribute should not do. Unfortunately, Clang eagerly instantiates attributes that appertain to functions with the result that errors might be issued for function declarations that are never selected by overload resolution. Tests have been added to demonstrate this. Further work will be needed to address these issues (for this and other attributes).
37 lines
1.3 KiB
C++
37 lines
1.3 KiB
C++
// Test that SYCL kernel name conflicts that occur across PCH boundaries are
|
|
// properly diagnosed.
|
|
|
|
// RUN: rm -rf %t
|
|
// RUN: split-file %s %t
|
|
// RUN: %clang_cc1 -std=c++17 -fsycl-is-host -emit-pch -x c++-header \
|
|
// RUN: %t/pch.h -o %t/pch.h.host.pch
|
|
// RUN: %clang_cc1 -std=c++17 -fsycl-is-host -verify \
|
|
// RUN: -include-pch %t/pch.h.host.pch %t/test.cpp
|
|
// RUN: %clang_cc1 -std=c++17 -fsycl-is-device -emit-pch -x c++-header \
|
|
// RUN: %t/pch.h -o %t/pch.h.device.pch
|
|
// RUN: %clang_cc1 -std=c++17 -fsycl-is-device -verify \
|
|
// RUN: -include-pch %t/pch.h.device.pch %t/test.cpp
|
|
|
|
#--- pch.h
|
|
template<int> struct KN;
|
|
|
|
[[clang::sycl_kernel_entry_point(KN<1>)]]
|
|
void pch_test1() {} // << expected previous declaration note here.
|
|
|
|
template<typename T>
|
|
[[clang::sycl_kernel_entry_point(T)]]
|
|
void pch_test2() {} // << expected previous declaration note here.
|
|
template void pch_test2<KN<2>>();
|
|
|
|
|
|
#--- test.cpp
|
|
// expected-error@+3 {{'sycl_kernel_entry_point' kernel name argument conflicts with a previous declaration}}
|
|
// expected-note@pch.h:4 {{previous declaration is here}}
|
|
[[clang::sycl_kernel_entry_point(KN<1>)]]
|
|
void test1() {}
|
|
|
|
// expected-error@+3 {{'sycl_kernel_entry_point' kernel name argument conflicts with a previous declaration}}
|
|
// expected-note@pch.h:8 {{previous declaration is here}}
|
|
[[clang::sycl_kernel_entry_point(KN<2>)]]
|
|
void test2() {}
|