-
Notifications
You must be signed in to change notification settings - Fork 787
[sycl] [clang] Add sycl global var attribute #3746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
682277f
[clang] Add sycl global var attribute
jtmott-intel 2c6f8fa
Update clang/lib/Sema/SemaExpr.cpp
jtmott-intel 4184aa4
Use SimpleHandler = 1 and revert changes to SemaDeclAttr
jtmott-intel 3f7887f
Wrapped attribute in pre-defined macro
jtmott-intel 63c4f17
Add tests and docs, and remove predefined macro
jtmott-intel 8b721d9
Update clang/include/clang/Basic/AttrDocs.td
jtmott-intel 08d0c67
Update clang/include/clang/Basic/AttrDocs.td
jtmott-intel 5c0f8af
Expand documentation and tests.
jtmott-intel a1ac1c5
Update clang/include/clang/Basic/AttrDocs.td
jtmott-intel a046f39
Add anonymous union to tests
jtmott-intel 6bb98b9
Disallowed local vars, and upgraded diagnostic to an error
jtmott-intel 47ce16a
Restrict attribute to system headers, or it has no effect
jtmott-intel a349032
Changed to non-simple handler, added templates to test
jtmott-intel 79d4ed7
clang format
jtmott-intel e9b7b2a
Simulated system include, and added macro test
jtmott-intel 7219bff
Use SubsetSubject, return after error, no documentation, add system h…
jtmott-intel 3373830
I guess not documented means not on the supported list
jtmott-intel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s | ||
|
||
#include "Inputs/sycl.hpp" | ||
|
||
# 5 "header.hpp" 1 3 // Simulate a system #include to enter new file named header.hpp at line 5 | ||
|
||
#define SYCLGLOBALVAR_ATTR_MACRO __attribute__((sycl_global_var)) | ||
|
||
__attribute__((sycl_global_var)) int HppGlobalWithAttribute; | ||
|
||
__attribute__((sycl_global_var)) extern int HppExternGlobalWithAttribute; | ||
|
||
namespace NS { | ||
__attribute__((sycl_global_var)) int HppNSGlobalWithAttribute; | ||
} | ||
|
||
struct HppS { | ||
__attribute__((sycl_global_var)) static int StaticMember; | ||
|
||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int InstanceMember; | ||
}; | ||
int HppS::StaticMember = 0; | ||
|
||
__attribute__((sycl_global_var)) HppS HppGlobalStruct; | ||
|
||
__attribute__((sycl_global_var)) static HppS HppStaticGlobal; | ||
|
||
static union { | ||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int HppAnonymousStaticUnionInstanceMember; | ||
}; | ||
|
||
// expected-error@+1 {{attribute takes no arguments}} | ||
__attribute__((sycl_global_var(42))) int HppGlobalWithAttributeArg; | ||
|
||
template<typename T> struct HppStructTemplate { | ||
__attribute__((sycl_global_var)) static T StaticMember; | ||
|
||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int InstanceMember; | ||
}; | ||
|
||
SYCLGLOBALVAR_ATTR_MACRO int HppGlobalWithAttrMacro; | ||
|
||
int HppGlobalNoAttribute; | ||
|
||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) void HppF( | ||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int Param | ||
) { | ||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) static int StaticLocalVar; | ||
|
||
// expected-error@+1 {{attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int Local; | ||
|
||
cl::sycl::kernel_single_task<class kernel_name>([=] () { | ||
(void)HppGlobalWithAttribute; // ok | ||
(void)HppExternGlobalWithAttribute; // ok | ||
(void)NS::HppNSGlobalWithAttribute; // ok | ||
(void)HppS::StaticMember; // ok | ||
(void)HppGlobalStruct.InstanceMember; // ok | ||
(void)HppStaticGlobal.InstanceMember; // ok | ||
(void)HppAnonymousStaticUnionInstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} | ||
(void)HppGlobalWithAttributeArg; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppStructTemplate<int>::StaticMember; // ok | ||
(void)HppGlobalWithAttrMacro; // ok | ||
(void)HppGlobalNoAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} expected-note@Inputs/sycl.hpp:* {{called by}} | ||
}); | ||
} | ||
|
||
# 74 "header.hpp" 2 // Return from the simulated #include (with the last line number of the "header.hpp" file) | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) int CppGlobalWithAttribute; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) extern int CppExternGlobalWithAttribute; | ||
|
||
namespace NS { | ||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) int CppNSGlobalWithAttribute; | ||
} | ||
|
||
struct CppS { | ||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) static int StaticMember; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int InstanceMember; | ||
}; | ||
int CppS::StaticMember = 0; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) CppS CppGlobalStruct; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) static CppS CppStaticGlobal; | ||
|
||
static union { | ||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int CppAnonymousStaticUnionInstanceMember; | ||
}; | ||
|
||
// expected-error@+1 {{attribute takes no arguments}} | ||
__attribute__((sycl_global_var(42))) int CppGlobalWithAttributeArg; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
__attribute__((sycl_global_var)) HppStructTemplate<int> CppGlobalTemplateStructWithAttribute; | ||
HppStructTemplate<int> CppGlobalTemplateStructNoAttribute; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only supported within a system header}} | ||
SYCLGLOBALVAR_ATTR_MACRO int CppGlobalWithAttrMacro; | ||
|
||
int GlobalNoAttribute; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) void F( | ||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int Param | ||
) { | ||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) static int StaticLocalVar; | ||
|
||
// expected-error@+1 {{'sycl_global_var' attribute only applies to global variables}} | ||
__attribute__((sycl_global_var)) int Local; | ||
|
||
cl::sycl::kernel_single_task<class kernel_name>([=] () { | ||
(void)HppGlobalWithAttribute; // ok | ||
(void)CppGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppExternGlobalWithAttribute; // ok | ||
(void)CppExternGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)NS::HppNSGlobalWithAttribute; // ok | ||
(void)NS::CppNSGlobalWithAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppS::StaticMember; // ok | ||
(void)CppS::StaticMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppGlobalStruct.InstanceMember; // ok | ||
(void)CppGlobalStruct.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppStaticGlobal.InstanceMember; // ok | ||
(void)CppStaticGlobal.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} | ||
(void)CppAnonymousStaticUnionInstanceMember; // expected-error {{SYCL kernel cannot use a non-const static data variable}} | ||
(void)CppGlobalWithAttributeArg; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)HppStructTemplate<int>::StaticMember; // ok | ||
(void)CppGlobalTemplateStructWithAttribute.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)CppGlobalTemplateStructNoAttribute.InstanceMember; // expected-error {{SYCL kernel cannot use a non-const global variable}} | ||
(void)GlobalNoAttribute; // expected-error {{SYCL kernel cannot use a non-const global variable}} expected-note@Inputs/sycl.hpp:* {{called by}} | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.