This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add an option for hiding line numbers in diagnostics
ClosedPublic

Authored by teemperor on Jul 2 2020, 4:42 AM.

Details

Summary

Clang offers a -f[no]-show-column flag for hiding the column numbers when printing diagnostics
but there is no option for doing the same with line numbers.

In LLDB having this option would be useful, as LLDB sometimes only knows the file name for a
SourceLocation and just assigns it the dummy line/column 1:1. These fake line/column numbers
are confusing to the user and LLDB should be able to tell clang to hide *both* the column and the
line number when rendering text diagnostics.

This patch adds a flag for also hiding the line numbers. It's not exposed via the command line flags
as it's most likely not very useful for any user and can lead to ambiguous output when the
user decides to only hide either the line or the column number (where file:1: ... could now refer
to both line 1 or column 1 depending on the compiler flags). LLDB can just access the DiagnosticOptions
directly when constructing its internal Clang instance.

The effect doesn't apply to Vi/MSVC style diagnostics because it's not defined how these diagnostic styles
would show an omitted line number (MSVC doesn't have such an option and Vi's line mode is theory
only supporting line numbers if I understand it correctly).

Diff Detail

Event Timeline

teemperor created this revision.Jul 2 2020, 4:42 AM
thakis added a comment.Sep 3 2020, 1:13 PM

Generally seems fine, nits below:

clang/docs/UsersManual.rst
172 ↗(On Diff #275028)

Can you say that this is enabled by default, and maybe make the example about fno- then? :)

clang/lib/Frontend/TextDiagnostic.cpp
832

put break on its own line, as-is the indentation is pretty misleading here :)

teemperor updated this revision to Diff 289887.Sep 4 2020, 1:18 AM
  • Fixed formatting in switch-case
  • Fixed formatting in DiagnosticOptions.def
teemperor added inline comments.Sep 4 2020, 1:33 AM
clang/docs/UsersManual.rst
172 ↗(On Diff #275028)

The text actually mentions the option is on by default (This option, which defaults to on, ) and there is an example for both enabled and disabled (the disabled one is in the last line). FWIW, this is actually just 1-1 copying the style of all the diagnostic options below, so if we want to make this more readable we probably should do the same for all other descriptions. I actually think that's a good idea as the default value is really hidden within the description.

I can make a followup review that fixes this for all the help text in the manual.

clang/lib/Frontend/TextDiagnostic.cpp
832

Thanks! seems I forgot to clang-format.

thakis accepted this revision.Sep 4 2020, 12:36 PM
This revision is now accepted and ready to land.Sep 4 2020, 12:36 PM
thakis added inline comments.Sep 4 2020, 12:38 PM
clang/test/Misc/diag-format.c
43 ↗(On Diff #289887)

on 2nd thought: Hm, should we allow -fno-line -fshow-column? It makes the output ambiguous, and it doesn't seem very useful. Maybe fno-show-line should imply fno-show-column, and explicit fno-show-line fshow-column should produce an error?

MaskRay added a subscriber: MaskRay.Sep 4 2020, 1:09 PM

Isn't DiagOpts->ShowLine sufficient? I don't think clang command line users will specify -fno-show-line...

Isn't DiagOpts->ShowLine sufficient? I don't think clang command line users will specify -fno-show-line...

Yes, it's only a flag because that's how the other DiagOpts are tested. I don't think there is a lot of benefit for having the flag beside being consistent with the other options. If that simplifies things, I can also do test this with a unit test and remove all the command line changes?

Isn't DiagOpts->ShowLine sufficient? I don't think clang command line users will specify -fno-show-line...

Yes, it's only a flag because that's how the other DiagOpts are tested. I don't think there is a lot of benefit for having the flag beside being consistent with the other options. If that simplifies things, I can also do test this with a unit test and remove all the command line changes?

Yeah, sounds good if that can simplify things.

teemperor updated this revision to Diff 290292.Sep 7 2020, 7:59 AM
teemperor retitled this revision from [clang] Add -f[no]-show-line option to [clang] Add an option for hiding line numbers in diagnostics.
teemperor edited the summary of this revision. (Show Details)
teemperor added a reviewer: MaskRay.
  • Removed driver arg and now tested via a unit test.
MaskRay added inline comments.Sep 7 2020, 4:37 PM
clang/unittests/Frontend/TextDiagnosticTest.cpp
33

The argument comments should use a style (with a equal sign) which can be detected by https://clang.llvm.org/extra/clang-tidy/checks/bugprone-argument-comment.html

39

; -> .

teemperor updated this revision to Diff 290420.Sep 8 2020, 12:52 AM
  • Fix typo and argument comments (thanks MaskRay !)
teemperor edited the summary of this revision. (Show Details)Sep 8 2020, 12:52 AM

@MaskRay is this ready to land? (This is technically in the 'accepted' state so this review probably disappeared from everyone's review queue, hence my ping)

teemperor requested review of this revision.Oct 29 2020, 6:57 AM
MaskRay accepted this revision.Oct 29 2020, 9:08 AM
MaskRay added inline comments.
clang/unittests/Frontend/TextDiagnosticTest.cpp
52

The argument comments should use a style (with a equal sign) which can be detected by https://clang.llvm.org/extra/clang-tidy/checks/bugprone-argument-comment.html

This revision is now accepted and ready to land.Oct 29 2020, 9:08 AM
teemperor updated this revision to Diff 303111.Nov 5 2020, 6:48 AM
  • Also fix the remaining argument comments.
teemperor marked 3 inline comments as done.Nov 5 2020, 6:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 5 2020, 7:11 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript