[clang] Add an option for hiding line numbers in diagnostics
authorRaphael Isemann <teemperor@gmail.com>
Thu, 5 Nov 2020 14:41:09 +0000 (15:41 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 5 Nov 2020 15:10:18 +0000 (16:10 +0100)
commit659f4bd87efc7cae379aa128814e03fc8b006471
tree31546f4d7be1f89b47ae7c34d091150a8b713fe4
parent98e8a06e72d4ea5633b981b1ebc372178017912a
[clang] Add an option for hiding line numbers in diagnostics

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).

Reviewed By: thakis, MaskRay

Differential Revision: https://reviews.llvm.org/D83038
clang/include/clang/Basic/DiagnosticOptions.def
clang/lib/Frontend/TextDiagnostic.cpp
clang/unittests/Frontend/CMakeLists.txt
clang/unittests/Frontend/TextDiagnosticTest.cpp [new file with mode: 0644]