|
| 1 | +// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s |
| 2 | + |
| 3 | +#include "Inputs/sycl.hpp" |
| 4 | + |
| 5 | +# 5 "header.hpp" 1 3 // Simulate a system #include to enter new file named header.hpp at line 5 |
| 6 | + |
| 7 | +#define SYCLGLOBALVAR_ATTR_MACRO __attribute__((sycl_global_var)) |
| 8 | + |
| 9 | +__attribute__((sycl_global_var)) int HppGlobalWithAttribute; |
| 10 | + |
| 11 | +__attribute__((sycl_global_var)) extern int HppExternGlobalWithAttribute; |
| 12 | + |
| 13 | +namespace NS { |
| 14 | + __attribute__((sycl_global_var)) int HppNSGlobalWithAttribute; |
| 15 | +} |
| 16 | + |
| 17 | +struct HppS { |
| 18 | + __attribute__((sycl_global_var)) static int StaticMember; |
| 19 | + |
| 20 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 21 | + __attribute__((sycl_global_var)) int InstanceMember; |
| 22 | +}; |
| 23 | +int HppS::StaticMember = 0; |
| 24 | + |
| 25 | +__attribute__((sycl_global_var)) HppS HppGlobalStruct; |
| 26 | + |
| 27 | +__attribute__((sycl_global_var)) static HppS HppStaticGlobal; |
| 28 | + |
| 29 | +static union { |
| 30 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 31 | + __attribute__((sycl_global_var)) int HppAnonymousStaticUnionInstanceMember; |
| 32 | +}; |
| 33 | + |
| 34 | +// expected-error@+1 {{attribute takes no arguments}} |
| 35 | +__attribute__((sycl_global_var(42))) int HppGlobalWithAttributeArg; |
| 36 | + |
| 37 | +template<typename T> struct HppStructTemplate { |
| 38 | + __attribute__((sycl_global_var)) static T StaticMember; |
| 39 | + |
| 40 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 41 | + __attribute__((sycl_global_var)) int InstanceMember; |
| 42 | +}; |
| 43 | + |
| 44 | +SYCLGLOBALVAR_ATTR_MACRO int HppGlobalWithAttrMacro; |
| 45 | + |
| 46 | +int HppGlobalNoAttribute; |
| 47 | + |
| 48 | +// expected-error@+1 {{attribute only applies to global variables}} |
| 49 | +__attribute__((sycl_global_var)) void HppF( |
| 50 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 51 | + __attribute__((sycl_global_var)) int Param |
| 52 | +) { |
| 53 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 54 | + __attribute__((sycl_global_var)) static int StaticLocalVar; |
| 55 | + |
| 56 | + // expected-error@+1 {{attribute only applies to global variables}} |
| 57 | + __attribute__((sycl_global_var)) int Local; |
| 58 | + |
| 59 | + cl::sycl::kernel_single_task<class kernel_name>([=] () { |
| 60 | + (void)HppGlobalWithAttribute; // ok |
| 61 | + (void)HppExternGlobalWithAttribute; // ok |
| 62 | + (void)NS::HppNSGlobalWithAttribute; // ok |
| 63 | + (void)HppS::StaticMember; // ok |
| 64 | + (void)HppGlobalStruct.InstanceMember; // ok |
| 65 | + (void)HppStaticGlobal.InstanceMember; // ok |
| 66 | + (void)HppAnonymousStaticUnionInstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} |
| 67 | + (void)HppGlobalWithAttributeArg; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 68 | + (void)HppStructTemplate<int>::StaticMember; // ok |
| 69 | + (void)HppGlobalWithAttrMacro; // ok |
| 70 | + (void)HppGlobalNoAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} expected-note@Inputs/sycl.hpp:* {{called by}} |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +# 74 "header.hpp" 2 // Return from the simulated #include (with the last line number of the "header.hpp" file) |
| 75 | + |
| 76 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 77 | +__attribute__((sycl_global_var)) int CppGlobalWithAttribute; |
| 78 | + |
| 79 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 80 | +__attribute__((sycl_global_var)) extern int CppExternGlobalWithAttribute; |
| 81 | + |
| 82 | +namespace NS { |
| 83 | + // expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 84 | + __attribute__((sycl_global_var)) int CppNSGlobalWithAttribute; |
| 85 | +} |
| 86 | + |
| 87 | +struct CppS { |
| 88 | + // expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 89 | + __attribute__((sycl_global_var)) static int StaticMember; |
| 90 | + |
| 91 | + // expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 92 | + __attribute__((sycl_global_var)) int InstanceMember; |
| 93 | +}; |
| 94 | +int CppS::StaticMember = 0; |
| 95 | + |
| 96 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 97 | +__attribute__((sycl_global_var)) CppS CppGlobalStruct; |
| 98 | + |
| 99 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 100 | +__attribute__((sycl_global_var)) static CppS CppStaticGlobal; |
| 101 | + |
| 102 | +static union { |
| 103 | + // expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 104 | + __attribute__((sycl_global_var)) int CppAnonymousStaticUnionInstanceMember; |
| 105 | +}; |
| 106 | + |
| 107 | +// expected-error@+1 {{attribute takes no arguments}} |
| 108 | +__attribute__((sycl_global_var(42))) int CppGlobalWithAttributeArg; |
| 109 | + |
| 110 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 111 | +__attribute__((sycl_global_var)) HppStructTemplate<int> CppGlobalTemplateStructWithAttribute; |
| 112 | +HppStructTemplate<int> CppGlobalTemplateStructNoAttribute; |
| 113 | + |
| 114 | +// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} |
| 115 | +SYCLGLOBALVAR_ATTR_MACRO int CppGlobalWithAttrMacro; |
| 116 | + |
| 117 | +int GlobalNoAttribute; |
| 118 | + |
| 119 | +// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 120 | +__attribute__((sycl_global_var)) void F( |
| 121 | + // expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 122 | + __attribute__((sycl_global_var)) int Param |
| 123 | +) { |
| 124 | + // expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 125 | + __attribute__((sycl_global_var)) static int StaticLocalVar; |
| 126 | + |
| 127 | + // expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} |
| 128 | + __attribute__((sycl_global_var)) int Local; |
| 129 | + |
| 130 | + cl::sycl::kernel_single_task<class kernel_name>([=] () { |
| 131 | + (void)HppGlobalWithAttribute; // ok |
| 132 | + (void)CppGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 133 | + (void)HppExternGlobalWithAttribute; // ok |
| 134 | + (void)CppExternGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 135 | + (void)NS::HppNSGlobalWithAttribute; // ok |
| 136 | + (void)NS::CppNSGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 137 | + (void)HppS::StaticMember; // ok |
| 138 | + (void)CppS::StaticMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 139 | + (void)HppGlobalStruct.InstanceMember; // ok |
| 140 | + (void)CppGlobalStruct.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 141 | + (void)HppStaticGlobal.InstanceMember; // ok |
| 142 | + (void)CppStaticGlobal.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} |
| 143 | + (void)CppAnonymousStaticUnionInstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} |
| 144 | + (void)CppGlobalWithAttributeArg; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 145 | + (void)HppStructTemplate<int>::StaticMember; // ok |
| 146 | + (void)CppGlobalTemplateStructWithAttribute.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 147 | + (void)CppGlobalTemplateStructNoAttribute.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} |
| 148 | + (void)GlobalNoAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} expected-note@Inputs/sycl.hpp:* {{called by}} |
| 149 | + }); |
| 150 | +} |
0 commit comments