-
Notifications
You must be signed in to change notification settings - Fork 802
[clang] Accept non const static work_group_static variables in templates #20944
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
base: sycl
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,7 +228,8 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, | |
| ObjCInterfaceDecl *ClassReceiver, | ||
| bool SkipTrailingRequiresClause) { | ||
| if (getLangOpts().SYCLIsDevice) { | ||
| if (auto VD = dyn_cast<VarDecl>(D)) { | ||
| if (auto VD = dyn_cast<VarDecl>(D); | ||
| VD && !VD->getType()->isDependentType()) { | ||
| bool IsConst = VD->getType().isConstant(Context); | ||
| bool IsRuntimeEvaluated = | ||
| ExprEvalContexts.empty() || | ||
|
|
@@ -239,6 +240,7 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, | |
| if (IsRuntimeEvaluated && !IsEsimdPrivateGlobal && !IsConst && | ||
| VD->getStorageClass() == SC_Static && | ||
| !VD->hasAttr<SYCLGlobalVarAttr>() && | ||
| !VD->getType()->isDependentType() && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is redundant because of the check in the above condition, yes?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I forgot to remove it. |
||
| !SemaSYCL::isTypeDecoratedWithDeclAttribute< | ||
| SYCLGlobalVariableAllowedAttr>(VD->getType()) && | ||
| !SemaSYCL::isTypeDecoratedWithDeclAttribute<SYCLScopeAttr>( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,8 @@ template <typename T> class [[__sycl_detail__::wg_scope]] B12 { // #B12 | |||||||||||||||||||||||||||||||||||||
| B12() = default; | ||||||||||||||||||||||||||||||||||||||
| ~B12() = default; | ||||||||||||||||||||||||||||||||||||||
| T obj; | ||||||||||||||||||||||||||||||||||||||
| operator T&() {return obj;} | ||||||||||||||||||||||||||||||||||||||
| T *operator&() noexcept { return &obj; } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+61
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't clear to me what these operators are intended to exercise. The conversion operator doesn't appear to be used anywhere.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think And oops, I noticed a |
||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| B12<Valid> b12; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,11 +86,27 @@ struct Wrap { | |||||||||||||||||||||||||||||||||||||
| static G1 g18; | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| template<int Index, typename T> | ||||||||||||||||||||||||||||||||||||||
| struct MyClass { | ||||||||||||||||||||||||||||||||||||||
| static B12<T> slm; | ||||||||||||||||||||||||||||||||||||||
| T *ptr() { | ||||||||||||||||||||||||||||||||||||||
| return &slm; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+89
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| template <typename T> | ||||||||||||||||||||||||||||||||||||||
| void foo() { | ||||||||||||||||||||||||||||||||||||||
| static T m; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| __attribute__((sycl_device)) void ref_func() { | ||||||||||||||||||||||||||||||||||||||
| G1 g19; | ||||||||||||||||||||||||||||||||||||||
| static G1 g20; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| (void)g16; | ||||||||||||||||||||||||||||||||||||||
| (void)g17; | ||||||||||||||||||||||||||||||||||||||
| (void)Wrap::g18; | ||||||||||||||||||||||||||||||||||||||
| MyClass<1, int> c1; | ||||||||||||||||||||||||||||||||||||||
| (void)c1.ptr(); | ||||||||||||||||||||||||||||||||||||||
| foo<B12<int>>(); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+109
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest testing both valid and invalid cases as is done for
Suggested change
This is a tangent, but it could also be useful to test cases of inhibited and deleted default constructors by adding to the set of earlier
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Valid/Invalid classes are intended to test that the attribute cannot be applied to a class which doesn't really make sense for this particular patch, I think?.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I was aiming for (and completely messed up) was to validate that diagnostics are correctly issued when the (non-const) static data member is dependent but is resolved to a type with and without the And oops, I missed adding the attribute to |
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will a case like this still be diagnosed as an error? Here,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, it will be diagnosed because once the template is instantiated, the of the variable type is not dependent anymore. The code is analyzed many times by clang before and after instantiation of templates. The problem was coming from the code that is not instantiated yet because the check for the attribute won't succeed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to @Fznamznon for an authoritative reply, but I think the intent is to suppress the diagnostic from being issued in a dependent context. The diagnostic should still be issued for non-dependent contexts (e.g., the instantiated specializations of Another tangent: The diagnostic currently issued fails to reference the location in device code that necessitated the code where the error is detected. It would be nice if we could also issue a note that includes that location. See https://godbolt.org/z/68qarnfEW for example; a note referring to line 17 and the instantiation of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, that last example should be valid after this PR. A better example is https://godbolt.org/z/eeacbMosY. Such a note is issued for this example (presumably because the diagnostic is now issued from a non-dependent context), though a note referencing the instantiation of |
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I forgot that if-with-separate-initializer-and-condition was in C++17 and that we can use it now! Love it!