Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -226,9 +226,11 @@ ------------------ - The flag ``-std=c++23`` has been added. This behaves the same as the existing flag ``-std=c++2b``. - - ``-dumpdir`` has been implemented to specify auxiliary and dump output filenames for features like ``-gsplit-dwarf``. +- ``-fcaret-diagnostics-max-lines=`` has been added as a driver options, which + lets users control the maximum number of source lines printed for a + caret diagnostic. Deprecated Compiler Flags ------------------------- Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2297,6 +2297,11 @@ Group, Flags<[NoXarchOption, CC1Option, CoreOption]>, HelpText<"Set the maximum number of entries to print in a macro expansion backtrace (0 = no limit)">, MarshallingInfoInt, "DiagnosticOptions::DefaultMacroBacktraceLimit">; +def fcaret_diagnostics_max_lines_EQ : + Joined<["-"], "fcaret-diagnostics-max-lines=">, + Group, Flags<[NoXarchOption, CC1Option, CoreOption]>, + HelpText<"Set the maximum number of source lines to show in a caret diagnostic">, + MarshallingInfoInt, "DiagnosticOptions::DefaultSnippetLineLimit">; defm merge_all_constants : BoolFOption<"merge-all-constants", CodeGenOpts<"MergeAllConstants">, DefaultFalse, PosFlag, NegFlag, @@ -5941,10 +5946,6 @@ def ferror_limit : Separate<["-"], "ferror-limit">, MetaVarName<"">, HelpText<"Set the maximum number of errors to emit before stopping (0 = no limit).">, MarshallingInfoInt>; -def fcaret_diagnostics_max_lines : - Separate<["-"], "fcaret-diagnostics-max-lines">, MetaVarName<"">, - HelpText<"Set the maximum number of source lines to show in a caret diagnostic">, - MarshallingInfoInt, "DiagnosticOptions::DefaultSnippetLineLimit">; def verify_EQ : CommaJoined<["-"], "verify=">, MetaVarName<"">, HelpText<"Verify diagnostic output using comment directives that start with" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -6042,6 +6042,7 @@ Args.AddLastArg(CmdArgs, options::OPT_fmacro_backtrace_limit_EQ); Args.AddLastArg(CmdArgs, options::OPT_ftemplate_backtrace_limit_EQ); Args.AddLastArg(CmdArgs, options::OPT_fspell_checking_limit_EQ); + Args.AddLastArg(CmdArgs, options::OPT_fcaret_diagnostics_max_lines_EQ); // Pass -fmessage-length=. unsigned MessageLength = 0; Index: clang/test/Driver/caret-diagnostics-max-lines.cpp =================================================================== --- /dev/null +++ clang/test/Driver/caret-diagnostics-max-lines.cpp @@ -0,0 +1,13 @@ +//RUN: not %clang++ -fsyntax-only -fcaret-diagnostics-max-lines=2 %s 2>&1 | FileCheck %s -strict-whitespace + + +static_assert(false && + // Comment + true, ""); + +// CHECK: error: static assertion failed due to requirement +// CHECK-NEXT: {{^}} 4 | static_assert(false &&{{$}} +// CHECK-NEXT: {{^}} | ~~~~~~~~~~~~{{$}} +// CHECK-NEXT: {{^}} 5 | // Comment +// CHECK-NEXT: {{^}} | ~~~~~~~~~~{{$}} + Index: clang/test/FixIt/fixit-function-call.cpp =================================================================== --- clang/test/FixIt/fixit-function-call.cpp +++ clang/test/FixIt/fixit-function-call.cpp @@ -1,4 +1,4 @@ -// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 1 -x c++ %s 2> %t +// RUN: not %clang_cc1 -fdiagnostics-parseable-fixits -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=1 -x c++ %s 2> %t // RUN: FileCheck %s < %t // PR5941 // END. Index: clang/test/Misc/caret-diags-multiline.cpp =================================================================== --- clang/test/Misc/caret-diags-multiline.cpp +++ clang/test/Misc/caret-diags-multiline.cpp @@ -1,4 +1,4 @@ -// RUN: not %clang_cc1 -std=c++11 -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 5 -Wsometimes-uninitialized %s 2>&1 | FileCheck %s --strict-whitespace +// RUN: not %clang_cc1 -std=c++11 -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=5 -Wsometimes-uninitialized %s 2>&1 | FileCheck %s --strict-whitespace void line(int); Index: clang/test/Sema/caret-diags-complex-init.cpp =================================================================== --- clang/test/Sema/caret-diags-complex-init.cpp +++ clang/test/Sema/caret-diags-complex-init.cpp @@ -1,4 +1,4 @@ -// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines 5 %s 2>&1 | FileCheck %s -strict-whitespace +// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fno-diagnostics-show-line-numbers -fcaret-diagnostics-max-lines=5 %s 2>&1 | FileCheck %s -strict-whitespace //CHECK: {{.*}}: error: excess elements in scalar initializer