|
| 1 | +// RUN: %clang_cc1 -fsycl -triple spir64 -fsycl-is-device -verify -fsyntax-only %s |
| 2 | +// |
| 3 | +// Ensure that the SYCL diagnostics that are typically deferred are correctly emitted. |
| 4 | + |
| 5 | +// testing that the deferred diagnostics work in conjunction with the SYCL namespaces. |
| 6 | +inline namespace cl { |
| 7 | +namespace sycl { |
| 8 | + |
| 9 | +template <typename name, typename Func> |
| 10 | +__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { |
| 11 | + // expected-note@+1 2{{called by 'kernel_single_task<AName, (lambda}} |
| 12 | + kernelFunc(); |
| 13 | +} |
| 14 | + |
| 15 | +} // namespace sycl |
| 16 | +} // namespace cl |
| 17 | + |
| 18 | +//variadic functions from SYCL kernels emit a deferred diagnostic |
| 19 | +void variadic(int, ...); |
| 20 | + |
| 21 | +int calledFromKernel(int a) { |
| 22 | + // expected-error@+1 {{zero-length arrays are not permitted in C++}} |
| 23 | + int MalArray[0]; |
| 24 | + |
| 25 | + // expected-error@+1 {{__float128 is not supported on this target}} |
| 26 | + __float128 malFloat = 40; |
| 27 | + |
| 28 | + //expected-error@+1 {{SYCL kernel cannot call a variadic function}} |
| 29 | + variadic(5); |
| 30 | + |
| 31 | + return a + 20; |
| 32 | +} |
| 33 | + |
| 34 | +// template used to specialize a function that contains a lambda that should |
| 35 | +// result in a deferred diagnostic being emitted. |
| 36 | +// HOWEVER, this is not working presently. |
| 37 | +// TODO: re-test after new deferred diagnostic system is merged. |
| 38 | +// restore the "FIX!!" tests below |
| 39 | + |
| 40 | +template <typename T> |
| 41 | +void setup_sycl_operation(const T VA[]) { |
| 42 | + |
| 43 | + cl::sycl::kernel_single_task<class AName>([]() { |
| 44 | + // FIX!! xpected-error@+1 {{zero-length arrays are not permitted in C++}} |
| 45 | + int OverlookedBadArray[0]; |
| 46 | + |
| 47 | + // FIX!! xpected-error@+1 {{__float128 is not supported on this target}} |
| 48 | + __float128 overlookedBadFloat = 40; |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +int main(int argc, char **argv) { |
| 53 | + |
| 54 | + // --- direct lambda testing --- |
| 55 | + cl::sycl::kernel_single_task<class AName>([]() { |
| 56 | + // expected-error@+1 {{zero-length arrays are not permitted in C++}} |
| 57 | + int BadArray[0]; |
| 58 | + |
| 59 | + // expected-error@+1 {{__float128 is not supported on this target}} |
| 60 | + __float128 badFloat = 40; // this SHOULD trigger a diagnostic |
| 61 | + |
| 62 | + //expected-error@+1 {{SYCL kernel cannot call a variadic function}} |
| 63 | + variadic(5); |
| 64 | + |
| 65 | + // expected-note@+1 {{called by 'operator()'}} |
| 66 | + calledFromKernel(10); |
| 67 | + }); |
| 68 | + |
| 69 | + // --- lambda in specialized function testing --- |
| 70 | + |
| 71 | + //array A is only used to feed the template |
| 72 | + const int array_size = 4; |
| 73 | + int A[array_size] = {1, 2, 3, 4}; |
| 74 | + setup_sycl_operation(A); |
| 75 | + |
| 76 | + return 0; |
| 77 | +} |
0 commit comments