This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add -fdiagnostics-format=sarif option for future SARIF output
ClosedPublic

Authored by abrahamcd on Jul 15 2022, 11:02 AM.

Details

Summary

Adds sarif option to the existing -fdiagnostics-format flag
for intended future work with SARIF diagnostics. Currently issues a warning
against the use of diagnostics in SARIF mode, then defaults to clang style for
diagnostics.

Diff Detail

Event Timeline

abrahamcd created this revision.Jul 15 2022, 11:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 11:02 AM
abrahamcd requested review of this revision.Jul 15 2022, 11:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 11:02 AM
abrahamcd abandoned this revision.Jul 15 2022, 11:03 AM

Edited commit message

abrahamcd retitled this revision from Adds `-fdiagnostics-format=sarif` flag option and warning. to [clang] Add -fdiagnostics-format=sarif for SARIF diagnostics.
abrahamcd edited the summary of this revision. (Show Details)

Commit message edits did not go through

cjdb added a comment.Jul 15 2022, 12:03 PM

Thanks for getting this started! To get this ready for submission, would you be able to add a test please?

Might be worth hiding it from --help, despite the instability warning.

abrahamcd retitled this revision from [clang] Add -fdiagnostics-format=sarif for SARIF diagnostics to [clang] Add -fdiagnostics-format=sarif option for future SARIF output.
abrahamcd edited the summary of this revision. (Show Details)

Adds test file and fixes warning-flags test failure by adding warning group.

Might be worth hiding it from --help, despite the instability warning.

I already couldn't find any mention of -fdiagnostics-format or sarif when I ran clang --help. Is there somewhere else I should look?

abrahamcd added inline comments.Jul 18 2022, 10:13 AM
clang/include/clang/Basic/DiagnosticDriverKinds.td
684

Please let me know if there's a better warning group you think this should be in.

vaibhav.y added a comment.EditedJul 18 2022, 10:16 AM

Might be worth hiding it from --help, despite the instability warning.

I already couldn't find any mention of -fdiagnostics-format or sarif when I ran clang --help. Is there somewhere else I should look?

Interesting, fdiagnostics-format doesn't show up in either --help or --help-hidden.

Please disregard my earlier comment in that case, thanks!

cjdb added inline comments.Jul 18 2022, 11:31 AM
clang/include/clang/Basic/DiagnosticDriverKinds.td
684

Nope! This is the right way to do it :)

clang/include/clang/Basic/DiagnosticGroups.td
1383

Please make sure that there's a newline at the end of each file.

clang/test/Driver/fdiagnostics-format-sarif.cpp
1

This test should check not only that we're able to use the flag, but also that it emits the warning.

Thanks for adding the flag!

clang/include/clang/Basic/DiagnosticGroups.td
1383

I guess you don't need a new entry here since you used InGroup<DiagGroup<"sarif-format-unstable">>.

clang/lib/Driver/ToolChains/Clang.cpp
4009

nit: I would replace it with StringRef.

abrahamcd updated this revision to Diff 445845.Jul 19 2022, 9:17 AM
abrahamcd marked 5 inline comments as done.
abrahamcd edited the summary of this revision. (Show Details)

Update test file to check for warning and address other minor comments

cjdb accepted this revision.Jul 19 2022, 9:58 AM

Thanks for working on this!

This revision is now accepted and ready to land.Jul 19 2022, 9:58 AM
denik accepted this revision.Jul 19 2022, 11:13 AM
aaron.ballman added inline comments.Jul 19 2022, 11:17 AM
clang/lib/Driver/ToolChains/Clang.cpp
4009–4011

Do we want to be kind to people who spell it SARIF (given that it's an acronym, some folks may spell it that way reflexively)?

cjdb added inline comments.Jul 19 2022, 11:28 AM
clang/lib/Driver/ToolChains/Clang.cpp
4009–4011

tbh I think it's worth accepting both sarif and SARIF, if we can.

abrahamcd marked 2 inline comments as done.

Enabled both "sarif" and "SARIF" as flag spellings.

Please address the whitespace changes in clang/lib/Driver/ToolChains/Clang.cpp.

clang/lib/Driver/ToolChains/Clang.cpp
81–82

nit: Looks like this an unrelated format change/ rebase issue. There are a few others as well in this file

Would be better to introduce these through another CR, or use git clang-format <commit-start> [<commit-end>] to limit it to the diff.

abrahamcd added inline comments.Jul 19 2022, 12:47 PM
clang/lib/Driver/ToolChains/Clang.cpp
4009–4011

Ah yeah that would definitely be helpful.

abrahamcd updated this revision to Diff 445917.Jul 19 2022, 1:00 PM
abrahamcd marked an inline comment as done.

Removed unintended formatting.

clang/lib/Driver/ToolChains/Clang.cpp
81–82

Thanks! Did not realize format changed all that :)

This revision was landed with ongoing or failed builds.Jul 21 2022, 9:52 AM
This revision was automatically updated to reflect the committed changes.