|
| 1 | +// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only |
| 2 | + |
| 3 | +#include "Inputs/sycl.hpp" |
| 4 | + |
| 5 | +// Test to validate that __builtin_sycl_mark_kernel_name properly updates the |
| 6 | +// constexpr checking for __builtin_sycl_unique_stable_name. We need to make |
| 7 | +// sure that the KernelInfo change in the library both still stays broken, and |
| 8 | +// is then 'fixed', so the definitions below help ensure that is the case. |
| 9 | +// We also validate that this works in the event that we have a wrapper that |
| 10 | +// first calls for the KernelInfo type, then instantiates a kernel. |
| 11 | + |
| 12 | +template <typename KN> |
| 13 | +struct KernelInfo { |
| 14 | + static constexpr const char *c = __builtin_sycl_unique_stable_name(KN); // #KI_USN |
| 15 | +}; |
| 16 | + |
| 17 | +template <typename KN> |
| 18 | +struct FixedKernelInfo { |
| 19 | + static constexpr bool b = __builtin_sycl_mark_kernel_name(KN); |
| 20 | + // making 'c' dependent on 'b' is necessary to ensure 'b' gets called first. |
| 21 | + static constexpr const char *c = b |
| 22 | + ? __builtin_sycl_unique_stable_name(KN) |
| 23 | + : nullptr; |
| 24 | +}; |
| 25 | + |
| 26 | +template <template <typename> class KI, |
| 27 | + typename KernelName, |
| 28 | + typename KernelType> |
| 29 | +void wrapper(KernelType KernelFunc) { |
| 30 | + (void)KI<KernelName>::c; |
| 31 | + cl::sycl::kernel_single_task<KernelName>(KernelFunc); // #SingleTaskInst |
| 32 | +} |
| 33 | + |
| 34 | +int main() { |
| 35 | + []() { |
| 36 | + class KernelName1; |
| 37 | + constexpr const char *C = __builtin_sycl_unique_stable_name(KernelName1); |
| 38 | + // expected-error@+2 {{kernel naming changes the result of an evaluated '__builtin_sycl_unique_stable_name'}} |
| 39 | + // expected-note@-2 {{'__builtin_sycl_unique_stable_name' evaluated here}} |
| 40 | + (void)__builtin_sycl_mark_kernel_name(KernelName1); |
| 41 | + }(); |
| 42 | + |
| 43 | + []() { |
| 44 | + // expected-error@#KernelSingleTaskFunc {{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}} |
| 45 | + // expected-note@#SingleTaskInst {{in instantiation of function template}} |
| 46 | + // expected-note@+2 {{in instantiation of function template}} |
| 47 | + // expected-note@#KI_USN {{'__builtin_sycl_unique_stable_name' evaluated here}} |
| 48 | + wrapper<KernelInfo, class KernelName2>([]() {}); |
| 49 | + }(); |
| 50 | + |
| 51 | + []() { |
| 52 | + wrapper<FixedKernelInfo, class KernelName3>([]() {}); |
| 53 | + }(); |
| 54 | +} |
0 commit comments