diff options
author | David Blaikie <dblaikie@gmail.com> | 2012-02-15 19:45:34 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2012-02-15 19:45:34 +0000 |
commit | ceb15656fbab9ee1da319afa4934b8f6a5964758 (patch) | |
tree | a9af1d851a537b01e7dcb90f386c7cbb8de525f2 | |
parent | e4e68d45f89ff4899d30cbd196603d09b7fbc150 (diff) |
Remove the unuseful -fdiagnostics-show-name
This option was added in r129614 and doesn't have any use case that I'm aware
of. It's possible that external tools are using these names - and if that's
the case we can certainly reassess the functionality, but for now it lets us
shave out a few unneeded bits from clang.
Move the "StaticDiagNameIndex" table into the only remaining consumer, diagtool.
This removes the actual diagnostic name strings from clang entirely.
Reviewed by Chris Lattner & Ted Kremenek.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150612 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | docs/UsersManual.html | 2 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticIDs.h | 25 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 2 | ||||
-rw-r--r-- | include/clang/Driver/Options.td | 2 | ||||
-rw-r--r-- | include/clang/Frontend/DiagnosticOptions.h | 2 | ||||
-rw-r--r-- | lib/Basic/DiagnosticIDs.cpp | 99 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 5 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 12 | ||||
-rw-r--r-- | test/Frontend/diagnostic-name.c | 5 | ||||
-rw-r--r-- | tools/diagtool/ListWarnings.cpp | 52 |
11 files changed, 49 insertions, 160 deletions
diff --git a/docs/UsersManual.html b/docs/UsersManual.html index 26ee38280a..779e4028f8 100644 --- a/docs/UsersManual.html +++ b/docs/UsersManual.html @@ -535,8 +535,6 @@ it:</p> <li>A categorization of the diagnostic as a note, warning, error, or fatal error.</li> <li>A text string that describes what the problem is.</li> -<li>An option that indicates whether to print the diagnostic name [<a - href="#opt_fdiagnostics-show-name">-fdiagnostics-show-name</a>].</li> <li>An option that indicates how to control the diagnostic (for diagnostics that support it) [<a href="#opt_fdiagnostics-show-option">-fdiagnostics-show-option</a>].</li> diff --git a/include/clang/Basic/DiagnosticIDs.h b/include/clang/Basic/DiagnosticIDs.h index b49a4f8bf4..1939e580fc 100644 --- a/include/clang/Basic/DiagnosticIDs.h +++ b/include/clang/Basic/DiagnosticIDs.h @@ -223,31 +223,6 @@ public: /// are not SFINAE errors. static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID); - /// getName - Given a diagnostic ID, return its name - static StringRef getName(unsigned DiagID); - - /// getIdFromName - Given a diagnostic name, return its ID, or 0 - static unsigned getIdFromName(StringRef Name); - - /// Iterator class used for traversing all statically declared - /// diagnostics. - class diag_iterator { - const void *impl; - - friend class DiagnosticIDs; - diag_iterator(const void *im) : impl(im) {} - public: - diag_iterator &operator++(); - bool operator==(const diag_iterator &x) const { return impl == x.impl; } - bool operator!=(const diag_iterator &x) const { return impl != x.impl; } - - llvm::StringRef getDiagName() const; - unsigned getDiagID() const; - }; - - static diag_iterator diags_begin(); - static diag_iterator diags_end(); - /// \brief Get the set of all diagnostic IDs in the group with the given name. /// /// \param Diags [out] - On return, the diagnostics in the group. diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 557e73bbfe..b885288bae 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -290,8 +290,6 @@ def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-rang HelpText<"Print source range spans in numeric form">; def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, HelpText<"Print fix-its in machine parseable form">; -def fdiagnostics_show_name : Flag<"-fdiagnostics-show-name">, - HelpText<"Print diagnostic name">; def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, HelpText<"Print option name with mappable diagnostics">; def fdiagnostics_format : Separate<"-fdiagnostics-format">, diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index f0c7f059e3..6d7417d16c 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -301,7 +301,6 @@ def fdiagnostics_fixit_info : Flag<"-fdiagnostics-fixit-info">, Group<f_clang_Gr def fdiagnostics_print_source_range_info : Flag<"-fdiagnostics-print-source-range-info">, Group<f_clang_Group>; def fdiagnostics_parseable_fixits : Flag<"-fdiagnostics-parseable-fixits">, Group<f_clang_Group>; def fdiagnostics_show_option : Flag<"-fdiagnostics-show-option">, Group<f_Group>; -def fdiagnostics_show_name : Flag<"-fdiagnostics-show-name">, Group<f_Group>; def fdiagnostics_show_note_include_stack : Flag<"-fdiagnostics-show-note-include-stack">, Group<f_Group>; def fdiagnostics_format_EQ : Joined<"-fdiagnostics-format=">, Group<f_clang_Group>; def fdiagnostics_show_category_EQ : Joined<"-fdiagnostics-show-category=">, Group<f_clang_Group>; @@ -402,7 +401,6 @@ def fno_constant_cfstrings : Flag<"-fno-constant-cfstrings">, Group<f_Group>; def fno_cxx_exceptions: Flag<"-fno-cxx-exceptions">, Group<f_Group>; def fno_cxx_modules : Flag <"-fno-cxx-modules">, Group<f_Group>, Flags<[NoForward]>; def fno_diagnostics_fixit_info : Flag<"-fno-diagnostics-fixit-info">, Group<f_Group>; -def fno_diagnostics_show_name : Flag<"-fno-diagnostics-show-name">, Group<f_Group>; def fno_diagnostics_show_option : Flag<"-fno-diagnostics-show-option">, Group<f_Group>; def fno_diagnostics_show_note_include_stack : Flag<"-fno-diagnostics-show-note-include-stack">, Group<f_Group>; def fno_dollars_in_identifiers : Flag<"-fno-dollars-in-identifiers">, Group<f_Group>; diff --git a/include/clang/Frontend/DiagnosticOptions.h b/include/clang/Frontend/DiagnosticOptions.h index 282ca5d366..1c6ba6acc3 100644 --- a/include/clang/Frontend/DiagnosticOptions.h +++ b/include/clang/Frontend/DiagnosticOptions.h @@ -31,7 +31,6 @@ public: unsigned ShowFixits : 1; /// Show fixit information. unsigned ShowSourceRanges : 1; /// Show source ranges in numeric form. unsigned ShowParseableFixits : 1; /// Show machine parseable fix-its. - unsigned ShowNames : 1; /// Show the diagnostic name unsigned ShowOptionNames : 1; /// Show the option name for mappable /// diagnostics. unsigned ShowNoteIncludeStack : 1; /// Show include stacks for notes. @@ -91,7 +90,6 @@ public: ShowColumn = 1; ShowFixits = 1; ShowLocation = 1; - ShowNames = 0; ShowOptionNames = 0; ShowCategories = 0; Format = Clang; diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp index 6c15e25909..754d7c0322 100644 --- a/lib/Basic/DiagnosticIDs.cpp +++ b/lib/Basic/DiagnosticIDs.cpp @@ -52,19 +52,14 @@ struct StaticDiagInfoRec { unsigned WarnShowInSystemHeader : 1; unsigned Category : 5; - uint8_t NameLen; uint8_t OptionGroupLen; uint16_t DescriptionLen; - const char *NameStr; const char *OptionGroupStr; const char *DescriptionStr; - StringRef getName() const { - return StringRef(NameStr, NameLen); - } StringRef getOptionGroup() const { return StringRef(OptionGroupStr, OptionGroupLen); } @@ -78,24 +73,6 @@ struct StaticDiagInfoRec { } }; -struct StaticDiagNameIndexRec { - const char *NameStr; - unsigned short DiagID; - uint8_t NameLen; - - StringRef getName() const { - return StringRef(NameStr, NameLen); - } - - bool operator<(const StaticDiagNameIndexRec &RHS) const { - return getName() < RHS.getName(); - } - - bool operator==(const StaticDiagNameIndexRec &RHS) const { - return getName() == RHS.getName(); - } -}; - template <size_t SizeOfStr, typename FieldType> class StringSizerHelper { char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1]; @@ -113,9 +90,9 @@ static const StaticDiagInfoRec StaticDiagInfo[] = { CATEGORY) \ { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE, ACCESS, \ NOWERROR, SHOWINSYSHEADER, CATEGORY, \ - STR_SIZE(#ENUM, uint8_t), STR_SIZE(GROUP, uint8_t), \ + STR_SIZE(GROUP, uint8_t), \ STR_SIZE(DESC, uint16_t), \ - #ENUM, GROUP, DESC }, + GROUP, DESC }, #include "clang/Basic/DiagnosticCommonKinds.inc" #include "clang/Basic/DiagnosticDriverKinds.inc" #include "clang/Basic/DiagnosticFrontendKinds.inc" @@ -126,23 +103,12 @@ static const StaticDiagInfoRec StaticDiagInfo[] = { #include "clang/Basic/DiagnosticSemaKinds.inc" #include "clang/Basic/DiagnosticAnalysisKinds.inc" #undef DIAG - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; static const unsigned StaticDiagInfoSize = sizeof(StaticDiagInfo)/sizeof(StaticDiagInfo[0])-1; -/// To be sorted before first use (since it's splitted among multiple files) -static const StaticDiagNameIndexRec StaticDiagNameIndex[] = { -#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, -#include "clang/Basic/DiagnosticIndexName.inc" -#undef DIAG_NAME_INDEX - { 0, 0, 0 } -}; - -static const unsigned StaticDiagNameIndexSize = - sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1; - /// GetDiagInfo - Return the StaticDiagInfoRec entry for the specified DiagID, /// or null if the ID is invalid. static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { @@ -164,7 +130,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) { // Search the diagnostic table with a binary search. StaticDiagInfoRec Find = { static_cast<unsigned short>(DiagID), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const StaticDiagInfoRec *Found = std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find); @@ -286,34 +252,6 @@ DiagnosticIDs::getDiagnosticSFINAEResponse(unsigned DiagID) { return SFINAE_Report; } -/// getName - Given a diagnostic ID, return its name -StringRef DiagnosticIDs::getName(unsigned DiagID) { - if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID)) - return Info->getName(); - return StringRef(); -} - -/// getIdFromName - Given a diagnostic name, return its ID, or 0 -unsigned DiagnosticIDs::getIdFromName(StringRef Name) { - const StaticDiagNameIndexRec *StaticDiagNameIndexEnd = - StaticDiagNameIndex + StaticDiagNameIndexSize; - - if (Name.empty()) { return diag::DIAG_UPPER_LIMIT; } - - assert(Name.size() == static_cast<uint8_t>(Name.size()) && - "Name is too long"); - StaticDiagNameIndexRec Find = { Name.data(), 0, - static_cast<uint8_t>(Name.size()) }; - - const StaticDiagNameIndexRec *Found = - std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find); - if (Found == StaticDiagNameIndexEnd || - Found->getName() != Name) - return diag::DIAG_UPPER_LIMIT; - - return Found->DiagID; -} - /// getBuiltinDiagClass - Return the class field of the diagnostic. /// static unsigned getBuiltinDiagClass(unsigned DiagID) { @@ -323,35 +261,6 @@ static unsigned getBuiltinDiagClass(unsigned DiagID) { } //===----------------------------------------------------------------------===// -// diag_iterator -//===----------------------------------------------------------------------===// - -llvm::StringRef DiagnosticIDs::diag_iterator::getDiagName() const { - return static_cast<const StaticDiagNameIndexRec*>(impl)->getName(); -} - -unsigned DiagnosticIDs::diag_iterator::getDiagID() const { - return static_cast<const StaticDiagNameIndexRec*>(impl)->DiagID; -} - -DiagnosticIDs::diag_iterator &DiagnosticIDs::diag_iterator::operator++() { - const StaticDiagNameIndexRec* ptr = - static_cast<const StaticDiagNameIndexRec*>(impl);; - ++ptr; - impl = ptr; - return *this; -} - -DiagnosticIDs::diag_iterator DiagnosticIDs::diags_begin() { - return DiagnosticIDs::diag_iterator(StaticDiagNameIndex); -} - -DiagnosticIDs::diag_iterator DiagnosticIDs::diags_end() { - return DiagnosticIDs::diag_iterator(StaticDiagNameIndex + - StaticDiagNameIndexSize); -} - -//===----------------------------------------------------------------------===// // Custom Diagnostic information //===----------------------------------------------------------------------===// diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 796b8769e3..4f8febd879 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2350,11 +2350,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fno_diagnostics_fixit_info)) CmdArgs.push_back("-fno-diagnostics-fixit-info"); - // Enable -fdiagnostics-show-name by default. - if (Args.hasFlag(options::OPT_fdiagnostics_show_name, - options::OPT_fno_diagnostics_show_name, false)) - CmdArgs.push_back("-fdiagnostics-show-name"); - // Enable -fdiagnostics-show-option by default. if (Args.hasFlag(options::OPT_fdiagnostics_show_option, options::OPT_fno_diagnostics_show_option)) diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 8417aa48c0..d4188969d3 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -322,8 +322,6 @@ static void DiagnosticOptsToArgs(const DiagnosticOptions &Opts, Res.push_back("-fcolor-diagnostics"); if (Opts.VerifyDiagnostics) Res.push_back("-verify"); - if (Opts.ShowNames) - Res.push_back("-fdiagnostics-show-name"); if (Opts.ShowOptionNames) Res.push_back("-fdiagnostics-show-option"); if (Opts.ShowCategories == 1) @@ -1217,7 +1215,6 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, /*Default=*/true); Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); - Opts.ShowNames = Args.hasArg(OPT_fdiagnostics_show_name); Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); // Default behavior is to not to show note include stacks. diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 465dcad80c..6445a0cc79 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -46,16 +46,6 @@ void TextDiagnosticPrinter::EndSourceFile() { TextDiag.reset(0); } -/// \brief Print the diagnostic name to a raw_ostream. -/// -/// This prints the diagnostic name to a raw_ostream if it has one. It formats -/// the name according to the expected diagnostic message formatting: -/// " [diagnostic_name_here]" -static void printDiagnosticName(raw_ostream &OS, const Diagnostic &Info) { - if (!DiagnosticIDs::isBuiltinNote(Info.getID())) - OS << " [" << DiagnosticIDs::getName(Info.getID()) << "]"; -} - /// \brief Print any diagnostic option information to a raw_ostream. /// /// This implements all of the logic for adding diagnostic options to a message @@ -136,8 +126,6 @@ void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level, Info.FormatDiagnostic(OutStr); llvm::raw_svector_ostream DiagMessageStream(OutStr); - if (DiagOpts->ShowNames) - printDiagnosticName(DiagMessageStream, Info); printDiagnosticOptions(DiagMessageStream, Level, Info, *DiagOpts); // Keeps track of the the starting position of the location diff --git a/test/Frontend/diagnostic-name.c b/test/Frontend/diagnostic-name.c deleted file mode 100644 index ae6cb0dd19..0000000000 --- a/test/Frontend/diagnostic-name.c +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: %clang -fsyntax-only -Wunused-parameter -fdiagnostics-show-name %s 2>&1 | grep "\[warn_unused_parameter\]" | count 1 -// RUN: %clang -fsyntax-only -Wunused-parameter -fno-diagnostics-show-name %s 2>&1 | grep "\[warn_unused_parameter\]" | count 0 -int main(int argc, char *argv[]) { - return argc; -} diff --git a/tools/diagtool/ListWarnings.cpp b/tools/diagtool/ListWarnings.cpp index 7f7db8ef10..85720b1f0b 100644 --- a/tools/diagtool/ListWarnings.cpp +++ b/tools/diagtool/ListWarnings.cpp @@ -16,6 +16,14 @@ #include "clang/Basic/Diagnostic.h" #include "llvm/Support/Format.h" #include "llvm/ADT/StringMap.h" +#include "clang/AST/ASTDiagnostic.h" +#include "clang/Analysis/AnalysisDiagnostic.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Lex/LexDiagnostic.h" +#include "clang/Parse/ParseDiagnostic.h" +#include "clang/Sema/SemaDiagnostic.h" +#include "clang/Serialization/SerializationDiagnostic.h" DEF_DIAGTOOL("list-warnings", "List warnings and their corresponding flags", @@ -23,6 +31,39 @@ DEF_DIAGTOOL("list-warnings", using namespace clang; +namespace { +template <size_t SizeOfStr, typename FieldType> +class StringSizerHelper { + char FIELD_TOO_SMALL[SizeOfStr <= FieldType(~0U) ? 1 : -1]; +public: + enum { Size = SizeOfStr }; +}; + +} // namespace anonymous + +#define STR_SIZE(str, fieldTy) StringSizerHelper<sizeof(str)-1, fieldTy>::Size + +namespace { +struct StaticDiagNameIndexRec { + const char *NameStr; + unsigned short DiagID; + uint8_t NameLen; + + StringRef getName() const { + return StringRef(NameStr, NameLen); + } +}; +} + +static const StaticDiagNameIndexRec StaticDiagNameIndex[] = { +#define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM, STR_SIZE(#ENUM, uint8_t) }, +#include "clang/Basic/DiagnosticIndexName.inc" +#undef DIAG_NAME_INDEX + { 0, 0, 0 } +}; + +static const unsigned StaticDiagNameIndexSize = + sizeof(StaticDiagNameIndex)/sizeof(StaticDiagNameIndex[0])-1; namespace { struct Entry { @@ -47,16 +88,13 @@ static void printEntries(std::vector<Entry> &entries, llvm::raw_ostream &out) { } int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) { - llvm::IntrusiveRefCntPtr<DiagnosticIDs> Diags(new DiagnosticIDs); - DiagnosticsEngine D(Diags); - std::vector<Entry> Flagged, Unflagged; llvm::StringMap<std::vector<unsigned> > flagHistogram; - for (DiagnosticIDs::diag_iterator di = DiagnosticIDs::diags_begin(), - de = DiagnosticIDs::diags_end(); di != de; ++di) { + for (const StaticDiagNameIndexRec *di = StaticDiagNameIndex, *de = StaticDiagNameIndex + StaticDiagNameIndexSize; + di != de; ++di) { - unsigned diagID = di.getDiagID(); + unsigned diagID = di->DiagID; if (DiagnosticIDs::isBuiltinNote(diagID)) continue; @@ -64,7 +102,7 @@ int ListWarnings::run(unsigned int argc, char **argv, llvm::raw_ostream &out) { if (!DiagnosticIDs::isBuiltinWarningOrExtension(diagID)) continue; - Entry entry(di.getDiagName(), + Entry entry(di->getName(), DiagnosticIDs::getWarningOptionForDiag(diagID)); if (entry.Flag.empty()) |