From 6fbe8398ba1680ffc5daa7395850ff8765b7905b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 4 May 2010 21:55:25 +0000 Subject: [PATCH] add a new -fdiagnostics-show-category=none/id/name option, giving control over choice of: t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat] t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,1] t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,Format String] dox to come. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103056 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 3 +++ include/clang/Driver/Options.td | 1 + include/clang/Frontend/DiagnosticOptions.h | 3 +++ lib/Driver/Tools.cpp | 6 ++++++ lib/Frontend/CompilerInvocation.cpp | 18 ++++++++++++++++++ lib/Frontend/TextDiagnosticPrinter.cpp | 9 +++++++-- 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 0badeb9efa..8e8eacb9c3 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -196,6 +196,9 @@ def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-rang HelpText<"Print source range spans in numeric form">; def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, HelpText<"Print diagnostic name with mappable diagnostics">; +def fdiagnostics_show_category : Separate<"-fdiagnostics-show-category">, + HelpText<"Print diagnostic category">; + def ftabstop : Separate<"-ftabstop">, MetaVarName<"">, HelpText<"Set the tab stop distance.">; def ferror_limit : Separate<"-ferror-limit">, MetaVarName<"">, diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index f6e69e0454..0a489c3d5d 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -257,6 +257,7 @@ def fdiagnostics_binary : Flag<"-fdiagnostics-binary">, Group, Flags<[H def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group; def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">, Group; def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, Group; +def fdiagnostics_show_category_EQ : Joined<"-fdiagnostics-show-category=">, Group; def fdollars_in_identifiers : Flag<"-fdollars-in-identifiers">, Group; def feliminate_unused_debug_symbols : Flag<"-feliminate-unused-debug-symbols">, Group; def femit_all_decls : Flag<"-femit-all-decls">, Group; diff --git a/include/clang/Frontend/DiagnosticOptions.h b/include/clang/Frontend/DiagnosticOptions.h index b4f147bde7..1da5eb4be5 100644 --- a/include/clang/Frontend/DiagnosticOptions.h +++ b/include/clang/Frontend/DiagnosticOptions.h @@ -30,6 +30,8 @@ public: unsigned ShowSourceRanges : 1; /// Show source ranges in numeric form. unsigned ShowOptionNames : 1; /// Show the diagnostic name for mappable /// diagnostics. + unsigned ShowCategories : 2; /// Show categories: 0 -> none, 1 -> Number, + /// 2 -> Full Name. unsigned ShowColors : 1; /// Show diagnostics with ANSI color sequences. unsigned VerifyDiagnostics: 1; /// Check that diagnostics match the expected /// diagnostics, indicated by markers in the @@ -74,6 +76,7 @@ public: ShowFixits = 1; ShowLocation = 1; ShowOptionNames = 0; + ShowCategories = 0; ShowSourceRanges = 0; VerifyDiagnostics = 0; BinaryOutput = 0; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 5a3916d19e..6335599721 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1320,6 +1320,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_show_option)) CmdArgs.push_back("-fdiagnostics-show-option"); + if (const Arg *A = + Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) { + CmdArgs.push_back("-fdiagnostics-show-category"); + CmdArgs.push_back(A->getValue(Args)); + } + // Color diagnostics are the default, unless the terminal doesn't support // them. if (Args.hasFlag(options::OPT_fcolor_diagnostics, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 729c1dcc15..e1275c16fe 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -243,6 +243,10 @@ static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts, Res.push_back("-fdiagnostics-binary"); if (Opts.ShowOptionNames) Res.push_back("-fdiagnostics-show-option"); + if (Opts.ShowCategories == 1) + Res.push_back("-fdiagnostics-show-category=id"); + else if (Opts.ShowCategories == 2) + Res.push_back("-fdiagnostics-show-category=name"); if (Opts.ErrorLimit) { Res.push_back("-ferror-limit"); Res.push_back(llvm::utostr(Opts.ErrorLimit)); @@ -879,6 +883,20 @@ static void ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); + + llvm::StringRef ShowCategory = + getLastArgValue(Args, OPT_fdiagnostics_show_category, "none"); + if (ShowCategory == "none") + Opts.ShowCategories = 0; + else if (ShowCategory == "id") + Opts.ShowCategories = 1; + else if (ShowCategory == "name") + Opts.ShowCategories = 2; + else + Diags.Report(diag::err_drv_invalid_value) + << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args) + << ShowCategory; + Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info); Opts.VerifyDiagnostics = Args.hasArg(OPT_verify); Opts.BinaryOutput = Args.hasArg(OPT_fdiagnostics_binary); diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 46bdd75a0e..547ff4d46b 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -837,7 +837,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, // If the user wants to see category information, include it too. unsigned DiagCategory = 0; - if (DiagOpts->ShowSourceRanges) + if (DiagOpts->ShowCategories) DiagCategory = Diagnostic::getCategoryNumberForDiag(Info.getID()); // If there is any categorization information, include it. @@ -852,7 +852,12 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, if (DiagCategory) { if (NeedsComma) OutStr += ','; - OutStr += llvm::utostr(DiagCategory); + if (DiagOpts->ShowCategories == 1) + OutStr += llvm::utostr(DiagCategory); + else { + assert(DiagOpts->ShowCategories == 2 && "Invalid ShowCategories value"); + OutStr += Diagnostic::getCategoryNameFromID(DiagCategory); + } } OutStr += "]"; -- 2.40.0