|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -std=c++17 -sycl-std=2020 -verify %s |
| 2 | +#include "Inputs/sycl.hpp" |
| 3 | + |
| 4 | +// Tests that SYCL_EXTERNAL can be applied to device_global variables, and cannot be applied to other variables. |
| 5 | +using namespace sycl::ext::oneapi; |
| 6 | + |
| 7 | +SYCL_EXTERNAL device_global<int> glob; |
| 8 | +// expected-error@+1{{'sycl_device' attribute cannot be applied to a static variable or variable in an anonymous namespace}} |
| 9 | +SYCL_EXTERNAL static device_global<float> static_glob; |
| 10 | + |
| 11 | +namespace foo { |
| 12 | +SYCL_EXTERNAL device_global<int> same_name; |
| 13 | +} |
| 14 | + |
| 15 | +struct RandomStruct { |
| 16 | + int M; |
| 17 | +}; |
| 18 | + |
| 19 | +// expected-error@+1{{'sycl_device' attribute can only be applied to 'device_global' variables}} |
| 20 | +SYCL_EXTERNAL RandomStruct S; |
| 21 | + |
| 22 | +namespace { |
| 23 | +// expected-error@+1{{'sycl_device' attribute cannot be applied to a static variable or variable in an anonymous namespace}} |
| 24 | +SYCL_EXTERNAL device_global<int> same_name; |
| 25 | +} // namespace |
| 26 | + |
| 27 | +// expected-error@+1{{'sycl_device' attribute can only be applied to 'device_global' variables}} |
| 28 | +SYCL_EXTERNAL int AAA; |
| 29 | + |
| 30 | +struct B { |
| 31 | + SYCL_EXTERNAL static device_global<int> Member; |
| 32 | +}; |
| 33 | + |
| 34 | +void foofoo() { |
| 35 | + // expected-warning@+1{{'sycl_device' attribute only applies to functions and global variables}} |
| 36 | + SYCL_EXTERNAL RandomStruct S; |
| 37 | + // expected-warning@+1{{'sycl_device' attribute only applies to functions and global variables}} |
| 38 | + SYCL_EXTERNAL int A; |
| 39 | +} |
| 40 | + |
| 41 | +template <typename T> struct NonDevGlob { |
| 42 | +}; |
| 43 | + |
| 44 | +template <typename T> struct TS { |
| 45 | + SYCL_EXTERNAL static device_global<T> D; |
| 46 | + // expected-error@+1{{'sycl_device' attribute can only be applied to 'device_global' variables}} |
| 47 | + SYCL_EXTERNAL static NonDevGlob<T> ND; |
| 48 | +}; |
| 49 | + |
| 50 | +// expected-note@+1 {{in instantiation of template class 'TS<int>' requested here}} |
| 51 | +TS<int> A; |
| 52 | + |
| 53 | +struct [[__sycl_detail__::global_variable_allowed]] GlobAllowedOnly { |
| 54 | +}; |
| 55 | + |
| 56 | +// expected-error@+1{{'sycl_device' attribute can only be applied to 'device_global' variables}} |
| 57 | +SYCL_EXTERNAL GlobAllowedOnly GAO; |
| 58 | + |
| 59 | + |
| 60 | +SYCL_EXTERNAL extern device_global<int> Good; |
| 61 | +extern device_global<int> Bad; |
| 62 | + |
| 63 | +int main() { |
| 64 | + sycl::kernel_single_task<class KernelName1>([=]() { |
| 65 | + Good.get(); |
| 66 | + // expected-error@+1 {{invalid reference to 'device_global' variable; external 'device_global' variable must be marked with SYCL_EXTERNAL macro}} |
| 67 | + Bad.get(); |
| 68 | + |
| 69 | + (void)GAO; |
| 70 | + }); |
| 71 | + return 0; |
| 72 | +} |
0 commit comments