r189445 - Reorder and shrink size of NameLen field in diagnostic group table. Shaves ~4K from clang binary.

Craig Topper craig.topper at gmail.com
Tue Aug 27 23:01:11 PDT 2013


Author: ctopper
Date: Wed Aug 28 01:01:10 2013
New Revision: 189445

URL: http://llvm.org/viewvc/llvm-project?rev=189445&view=rev
Log:
Reorder and shrink size of NameLen field in diagnostic group table. Shaves ~4K from clang binary.

Modified:
    cfe/trunk/lib/Basic/DiagnosticIDs.cpp
    cfe/trunk/tools/diagtool/DiagnosticNames.h
    cfe/trunk/tools/diagtool/TreeView.cpp
    cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=189445&r1=189444&r2=189445&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Aug 28 01:01:10 2013
@@ -502,11 +502,8 @@ DiagnosticIDs::getDiagnosticLevel(unsign
 }
 
 struct clang::WarningOption {
-  // Be safe with the size of 'NameLen' because we don't statically check if
-  // the size will fit in the field; the struct size won't decrease with a
-  // shorter type anyway.
-  size_t NameLen;
   const char *NameStr;
+  uint16_t NameLen;
   uint16_t Members;
   uint16_t SubGroups;
 
@@ -558,7 +555,9 @@ void DiagnosticIDs::getDiagnosticsInGrou
 bool DiagnosticIDs::getDiagnosticsInGroup(
     StringRef Group,
     SmallVectorImpl<diag::kind> &Diags) const {
-  WarningOption Key = { Group.size(), Group.data(), 0, 0 };
+  if (Group.size() > UINT16_MAX)
+    return true; // Option is too long to be one in the table.
+  WarningOption Key = { Group.data(), (uint16_t)Group.size(), 0, 0 };
   const WarningOption *Found =
   std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
                    WarningOptionCompare);

Modified: cfe/trunk/tools/diagtool/DiagnosticNames.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/diagtool/DiagnosticNames.h?rev=189445&r1=189444&r2=189445&view=diff
==============================================================================
--- cfe/trunk/tools/diagtool/DiagnosticNames.h (original)
+++ cfe/trunk/tools/diagtool/DiagnosticNames.h Wed Aug 28 01:01:10 2013
@@ -35,11 +35,8 @@ namespace diagtool {
 
 
   struct GroupRecord {
-    // Be safe with the size of 'NameLen' because we don't statically check if
-    // the size will fit in the field; the struct size won't decrease with a
-    // shorter type anyway.
-    size_t NameLen;
     const char *NameStr;
+    uint16_t NameLen;
     uint16_t Members;
     uint16_t SubGroups;
 

Modified: cfe/trunk/tools/diagtool/TreeView.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/diagtool/TreeView.cpp?rev=189445&r1=189444&r2=189445&view=diff
==============================================================================
--- cfe/trunk/tools/diagtool/TreeView.cpp (original)
+++ cfe/trunk/tools/diagtool/TreeView.cpp Wed Aug 28 01:01:10 2013
@@ -94,7 +94,12 @@ static int showGroup(llvm::raw_ostream &
                      bool FlagsOnly) {
   ArrayRef<GroupRecord> AllGroups = getDiagnosticGroups();
 
-  GroupRecord Key = { RootGroup.size(), RootGroup.data(), 0, 0 };
+  if (RootGroup.size() > UINT16_MAX) {
+    llvm::errs() << "No such diagnostic group exists\n";
+    return 1;
+  }
+
+  GroupRecord Key = { RootGroup.data(), (uint16_t)RootGroup.size(), 0, 0 };
   const GroupRecord *Found =
     std::lower_bound(AllGroups.begin(), AllGroups.end(), Key);
   

Modified: cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp?rev=189445&r1=189444&r2=189445&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangDiagnosticsEmitter.cpp Wed Aug 28 01:01:10 2013
@@ -681,7 +681,6 @@ void EmitClangDiagGroups(RecordKeeper &R
        I = DiagsInGroup.begin(), E = DiagsInGroup.end(); I != E; ++I) {
     // Group option string.
     OS << "  { ";
-    OS << I->first.size() << ", ";
     OS << "\"";
     if (I->first.find_first_not_of("abcdefghijklmnopqrstuvwxyz"
                                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -690,6 +689,9 @@ void EmitClangDiagGroups(RecordKeeper &R
                       I->first + "'");
     OS.write_escaped(I->first) << "\","
                                << std::string(MaxLen-I->first.size()+1, ' ');
+    if (I->first.size() > UINT16_MAX)
+      PrintFatalError("Diagnostic group name is too long for NameLen field.");
+    OS << I->first.size() << ", ";
 
     // Special handling for 'pedantic'.
     const bool IsPedantic = I->first == "pedantic";





More information about the cfe-commits mailing list