-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Add new tool: clang-read-diagnostics #118522
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
Add new tool: clang-read-diagnostics #118522
Conversation
|
@llvm/pr-subscribers-clang-tools-extra Author: Yuxuan Chen (yuxuanchen1997) ChangesAs of today, one can make clang serialize diagnostics to a file with the flag There are obvious issues with this program. And as expected, clang emitted two diagnostics when compiling. We can save it into a file. However, based on my research, we don't yet have a clang tool to read the serialized binary. Most likely this flag is here for IDE integration. This patch is adding a tool to read serialized diagnostics. Currently, it's fairly minimal as it just prints everything it knows to stdout. In the future, we can extend it to export diagnostics to different formats. |
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
clang-tools-extra/test/clang-read-diagnostics/error_and_warning.c
Outdated
Show resolved
Hide resolved
Co-authored-by: Jon Roelofs <[email protected]>
|
Looking at the test failure, it appears that when only building |
We should stay away from committed binaries, per the |
Great. This should work now. |
| @@ -0,0 +1,15 @@ | |||
| // REQUIRES: clang | |||
| // RUN: not %clang %s -serialize-diagnostics %s.diag | |||
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.
recommend putting the new file under %t instead of %s, so this doesn't pollute the source dir.
|
Looks okay to me, but let me tag some clang-tools-extra folks for a second look. |
AaronBallman
left a comment
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'd like to understand the motivation for the tool a bit better. IMO, the goal should be to deprecate serialized diagnostics because we are now able to emit diagnostics to SARIF instead, and the whole point to SARIF is to be a machine-readable interchange format for diagnostic information to be shared between tools. So if we want to promote SARIF for sharing diagnostics between tools, it seems like we don't really need a tool to deserialized diagnostics we've serialized.
CC @cjdb for awareness, as he's been working on SARIF support.
The goal of these tools is to eventually be able to obtain clang diagnostics as structural data. Say, I want the compiler to emit warnings and learn about the number of warnings I will get. For us, this is something that's worth putting into a database so that we can nudge relevant teams to make changes. I didn't know that we plan to deprecate serialized diagnostics. I would have done differently if I had known about SARIF. |
Okay, that makes sense to me. Yeah, I would recommend using SARIF for that.
I didn't mean to oversell it, I don't think we have firm plans to deprecate serialized diagnostics, just that it seems like something we're going to want to do at some point so we don't need to carry around multiple implementations of machine-readable diagnostic information. |
I just realized that we also have |
I don't think either is preferred over the other, but I was unaware that we had something which logs to XML, so it's possible there's bitrot there (it seems we may not have any direct test coverage of that feature, at least from my cursory look). |
I'd be more than happy to drop this patch if the alternative is better. I believe that we shouldn't need a tool like this, as the majority of third-party tooling won't want to implement reading from a proprietary format. It adds moving parts while getting little in return (maybe encoding/decoding speed or file size). Things could also be in a friendlier format than XML. We currently use YAML for middle end opt remarks but that's different from diagnostics engine. |
As of today, one can make clang serialize diagnostics to a file with the flag
-serialize-diagnostics. For example:There are obvious issues with this program. And as expected, clang emitted two diagnostics when compiling. We can save it into a file.
However, based on my research, we don't yet have a clang tool to read the serialized binary. Most likely this flag is here for IDE integration.
This patch is adding a tool to read serialized diagnostics. Currently, it's fairly minimal as it just prints everything it knows to stdout. In the future, we can extend it to export diagnostics to different formats.