Index: clang/docs/UsersManual.rst =================================================================== --- clang/docs/UsersManual.rst +++ clang/docs/UsersManual.rst @@ -162,6 +162,25 @@ these cases, Clang provides a wide range of options to control the exact output format of the diagnostics that it generates. +.. _opt_fshow-line: + +**-f[no-]show-line** + Print line number in diagnostic. + + This option, which defaults to on, controls whether or not Clang + prints the line number of a diagnostic. For example, when this is + enabled, Clang will print something like: + + :: + + test.c:28: warning: extra tokens at end of #endif directive [-Wextra-tokens] + #endif bad + ^ + // + + When this is disabled, Clang will print "test.c: warning..." with + no line number. + .. _opt_fshow-column: **-f[no-]show-column** Index: clang/include/clang/Basic/DiagnosticOptions.def =================================================================== --- clang/include/clang/Basic/DiagnosticOptions.def +++ clang/include/clang/Basic/DiagnosticOptions.def @@ -47,6 +47,7 @@ DIAGOPT(NoRewriteMacros, 1, 0) /// -Wno-rewrite-macros DIAGOPT(Pedantic, 1, 0) /// -pedantic DIAGOPT(PedanticErrors, 1, 0) /// -pedantic-errors +DIAGOPT(ShowLine, 1, 1) /// Show line number on diagnostics. DIAGOPT(ShowColumn, 1, 1) /// Show column number on diagnostics. DIAGOPT(ShowLocation, 1, 1) /// Show source location information. DIAGOPT(ShowLevel, 1, 1) /// Show diagnostic level. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -1788,6 +1788,7 @@ def fshow_overloads_EQ : Joined<["-"], "fshow-overloads=">, Group, Flags<[CC1Option]>, HelpText<"Which overload candidates to show when overload resolution fails: " "best|all; defaults to all">, Values<"best,all">; +defm show_line : OptOutFFlag<"show-line", "", "Do not include line number on diagnostics">; defm show_column : OptOutFFlag<"show-column", "", "Do not include column number on diagnostics">; def fshow_source_location : Flag<["-"], "fshow-source-location">, Group; def fspell_checking : Flag<["-"], "fspell-checking">, Group; Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3614,6 +3614,9 @@ if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths)) CmdArgs.push_back("-fdiagnostics-absolute-paths"); + if (!Args.hasFlag(options::OPT_fshow_line, options::OPT_fno_show_line)) + CmdArgs.push_back("-fno-show-line"); + if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column, ColumnDefault)) CmdArgs.push_back("-fno-show-column"); Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1583,6 +1583,7 @@ Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors); Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics); Opts.ShowColors = parseShowColorsArgs(Args, DefaultDiagColor); + Opts.ShowLine = !Args.hasArg(OPT_fno_show_line); Opts.ShowColumn = !Args.hasArg(OPT_fno_show_column); Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); Index: clang/lib/Frontend/TextDiagnostic.cpp =================================================================== --- clang/lib/Frontend/TextDiagnostic.cpp +++ clang/lib/Frontend/TextDiagnostic.cpp @@ -827,7 +827,10 @@ emitFilename(PLoc.getFilename(), Loc.getManager()); switch (DiagOpts->getFormat()) { - case DiagnosticOptions::Clang: OS << ':' << LineNo; break; + case DiagnosticOptions::Clang: + if (DiagOpts->ShowLine) + OS << ':' << LineNo; + break; case DiagnosticOptions::MSVC: OS << '(' << LineNo; break; case DiagnosticOptions::Vi: OS << " +" << LineNo; break; } Index: clang/test/Misc/diag-format.c =================================================================== --- clang/test/Misc/diag-format.c +++ clang/test/Misc/diag-format.c @@ -16,22 +16,20 @@ // RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fmsc-version=1900 -target x86_64-pc-win32 -fshow-column %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2015 // // RUN: %clang -fsyntax-only -fdiagnostics-format=vi %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=VI +// RUN: %clang -fsyntax-only -fdiagnostics-format=vi -fno-show-line %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=VI // // RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fno-show-column -fmsc-version=1900 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2015_ORIG +// RUN: %clang -fsyntax-only -fdiagnostics-format=msvc -fno-show-column -fno-show-line -fmsc-version=1900 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2015_ORIG // // RUN: %clang -fsyntax-only -fno-show-column %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=NO_COLUMN +// RUN: %clang -fsyntax-only -fno-show-line %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=NO_LINE +// RUN: %clang -fsyntax-only -fno-show-column -fno-show-line %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=NO_LINE_NO_COLUMN // // RUN: not %clang -fsyntax-only -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1300 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2010-FALLBACK // RUN: not %clang -fsyntax-only -Werror -fdiagnostics-format=msvc-fallback -fms-compatibility-version=13.00 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2010-FALLBACK // RUN: not %clang -fsyntax-only -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1800 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2013-FALLBACK // RUN: not %clang -fsyntax-only -Werror -fdiagnostics-format=msvc-fallback -fmsc-version=1900 %s 2>&1 | FileCheck %s --strict-whitespace -check-prefix=MSVC2015-FALLBACK - - - - - - #ifdef foo #endif bad // extension! // DEFAULT: {{.*}}:36:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] @@ -42,6 +40,8 @@ // VI: {{.*}} +36:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] // MSVC2015_ORIG: {{.*}}(36): warning: extra tokens at end of #endif directive [-Wextra-tokens] // NO_COLUMN: {{.*}}:36: warning: extra tokens at end of #endif directive [-Wextra-tokens] +// NO_LINE: {{.*}}format.c:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] +// NO_LINE_NO_COLUMN: {{.*}}format.c: warning: extra tokens at end of #endif directive [-Wextra-tokens] // MSVC2010-FALLBACK: {{.*}}(36,7) : error(clang): extra tokens at end of #endif directive // MSVC2013-FALLBACK: {{.*}}(36,8) : error(clang): extra tokens at end of #endif directive // MSVC2015-FALLBACK: {{.*}}(36,8): error(clang): extra tokens at end of #endif directive