-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Move variadic call diagnostics to delayed diagnostics, fixes. #998
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
Conversation
One of our downstreams requires using the variadic call diagnostics from SYCL, however the SemaSYCL AST walker ends up being messy. This patch initially removes the check from the AST walker and instead implements its in normal SEMA via the delayed diagnostics mechanism. However, while evaluating this, we discovered that there are quite a few issues with how the diagnostics are emitted, so this patch includes quite a few cleanups to make sure the diagnostics are emitted properly. This results in some additional notes in some of the test. Additionally, the asm checks were previously implemented in BOTH delayed diagnostics as well as the AST walker, since the bugs in each aligned to have full coverage. This patch ends up removing it from the AST walking code since the other bugs were fixed. Signed-off-by: Erich Keane <[email protected]>
<< Sema::KernelUseAssembly; | ||
return true; | ||
} | ||
|
||
// The call graph for this translation unit. |
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.
Were these dead code and safe to remove?
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.
They were not, but are now :) When This is the case in the commit message where we had done 2 versions of diagnostics for the inline assembly, but bugs in each made them not cover all cases, but combined, they seemed to. My fix to the delayed diagnostics made the assembly error handling in normal 'Sema' cover the cases that this caught.
clang/lib/Sema/SemaSYCL.cpp
Outdated
@@ -1420,18 +1407,20 @@ Sema::DeviceDiagBuilder Sema::SYCLDiagIfDeviceCode(SourceLocation Loc, | |||
unsigned DiagID) { | |||
assert(getLangOpts().SYCLIsDevice && | |||
"Should only be called during SYCL compilation"); | |||
DeviceDiagBuilder::Kind DiagKind = [this] { | |||
if (isKnownEmitted(*this, dyn_cast<FunctionDecl>(CurContext))) | |||
FunctionDecl *FD = dyn_cast<FunctionDecl>(CurContext); |
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.
Shouldn't it be CurLexicalContext?
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.
I believe it SHOULD be getCurLexicalContext, but the current implementation was CurContext. I couldn't come up with a reproducer that I was able to justify changing the status quo here.
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.
I should double check, because it was before long vacation, but in my patch I've implemented a new usage of deferred diagnostics - diagnosing of __float128
usage in device code (https://github.com/intel/llvm/pull/971/files#diff-643c0b5e3365e57856a6871266a81b35) and it didn't work before I changed CurContext
to getCurLexicalContext
here.
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.
Neat! Thanks for providing justification. I'll upload an updated patch momentarily.
@premanandrao saw that I had accidentially left a line in the test commented out while debugging. Revert the commented out line to still be testing what it is supposed to be testing. Signed-off-by: Erich Keane <[email protected]>
b7e674a
to
626431c
Compare
I actually thought that we also will fix this llvm/clang/lib/Sema/SemaType.cpp Line 4688 in 8803f62
|
I don't think so, do we? That is OpenCL diagnostics, which I didn't change. In fact, I'd be surprised if the OpenCL path for these diagnostic repairs don't have similar issues to what I fixed. |
@bader , do you have any thoughts? |
Variadic functions are not allowed in OpenCL and SYCL device code.
@erichkeane, I'm not sure I understand: what "issues" do you refer here? |
The ones I fixed in this patch :), particularly when it comes to templates. OpenCL uses a similar (though not identical) delayed diagnostics mechanism that I have not evaluated (since improving OpenCL is not my goal here) but look similar enough to the issues that the SYCL code has currently (at least until this patch is commited). I believe that FIXME is NOT fixed, since it is diagnosing OpenCL (which this patch does not), and I believe that fixing it out of the scope of both this patch and this repo. |
Really? OpenCL compiler work with "device code" only, so the reason to "delay" diagnostics might be quite different from the SYCL device compiler, if any. Could you point the source code where OpenCL delays the diagnostics, please?
Right.
The FIXME comment is not about fixing OpenCL behavior, but rather fixing SYCL compiler behavior, which I described in my previous comment: #998 (comment). Having said that I think this patch is the right place to fix diagnostic for |
Ah, I was thinking of CUDA. I see a bunch of delay-diagnostics code for CUDA. Don't know why I remembered 'OpenCL' :).
I guess I still don't get what you're trying to say. It seems that we explicitly exclude ourselves from that check, and my patch does NOT exclude printf, so it should be doing what you want, right? As a side note, that OpenCL check doesn't work correctly in C++... it seems to exclude ANY function named printf, not just the one in stdio.h :) |
It was excluded by initial implementation. Previous implementation just skipped the diagnostics to allow using We either should:
BTW, ideally we should make use of existing diagnostics implemented for CUDA instead of adding new one: https://github.com/intel/llvm/blob/sycl/clang/include/clang/Basic/DiagnosticSemaKinds.td#L7631. Can we make this CUDA-specific diagnostic generic and re-use for SYCL? I think we can re-use the code reporting this diagnostic.
Feel free to report this. Tagging @AnastasiaStulova. |
Got it. I'll remove the comment. sycl-cconv.cpp already tests with printf.
I can definitely switch to that diagnostic if you wish, but it isn't saying the same thing or diagnosing the same thing. That is diagnosing a function DECLARATION, not a function CALL. Thus, it is a different error diagnosis. Also note that I'm not adding a error message here.
@AnastasiaStulova : That likely needs to make sure that the printf is externC and in the global namespace. |
As brought up by @bader in review. Signed-off-by: Erich Keane <[email protected]>
Yes, I'm not sure that we can reuse it because we should diagnose calls, not declarations. As far as I understand in CUDA in most cases device code is marked explicitly, meanwhile in SYCL any function can magically become a device function if called from a kernel. Overall, maybe I like place for deferred diagnostic where OpenCL does diagnosing a bit more because IMO it simplifies searching through SEMA code, but if it works and it's already done it's ok too. |
We don't have standard includes in OpenCL and also there are numerous ways to declare BIFs so the way to check is string compare the name. In the C++ mode it should indeed have C linkage. |
Clang doesn't typically check where a function is defined/declared, so the string check is fine, just not specific enough. You need to make sure it is C linkage, not in a namespace, not a member function, etc. Note it could likely be a friend declaration (should likely be allowed), though I wonder about a friend definition... |
Yes indeed this still needs to be done!
Would some of these not be redundant? I would expect any C linkage functions wouldn't be a member function? In other words C linkage functions won't be parsed with C++ features i.e. class members, templates, etc... |
Yes, some are. "C" linkage can't be applied to templates or class members, but still would apply to friend functions I would expect. Also, inside a namespace a function can still be extern "C". |
I am not sure that should be diagnosed. At least for the namespaces it still doesn't seem to work as regular C++ functions would. There will only be one C linkage function with a certain name regardless of the namespace. Although if we want to be on the safe side we might add this to the check. |
I'm not an OpenCL language designer, so take my opinion as just that :) You're likely right that "extern C" is sufficient, as long as that is what you mean. Friend definitions can get strange I think, so just make sure that the decision is made having played with them. In reality, extern "C" is likely sufficient. |
One of our downstreams requires using the variadic call diagnostics from
SYCL, however the SemaSYCL AST walker ends up being messy. This patch
initially removes the check from the AST walker and instead implements
its in normal SEMA via the delayed diagnostics mechanism.
However, while evaluating this, we discovered that there are quite a few
issues with how the diagnostics are emitted, so this patch includes
quite a few cleanups to make sure the diagnostics are emitted properly.
This results in some additional notes in some of the test.
Additionally, the asm checks were previously implemented in BOTH delayed
diagnostics as well as the AST walker, since the bugs in each aligned to
have full coverage. This patch ends up removing it from the AST walking
code since the other bugs were fixed.
Signed-off-by: Erich Keane [email protected]