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

llvm-svn: 189445
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp b/clang/lib/Basic/DiagnosticIDs.cpp
index 9741f38..cccf418 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -502,11 +502,8 @@
 }
 
 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 @@
 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);
diff --git a/clang/tools/diagtool/DiagnosticNames.h b/clang/tools/diagtool/DiagnosticNames.h
index dd5381f..957a181 100644
--- a/clang/tools/diagtool/DiagnosticNames.h
+++ b/clang/tools/diagtool/DiagnosticNames.h
@@ -35,11 +35,8 @@
 
 
   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;
 
diff --git a/clang/tools/diagtool/TreeView.cpp b/clang/tools/diagtool/TreeView.cpp
index 6298179..10809c1 100644
--- a/clang/tools/diagtool/TreeView.cpp
+++ b/clang/tools/diagtool/TreeView.cpp
@@ -94,7 +94,12 @@
                      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);
   
diff --git a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
index 135e2e7..9a1cd34 100644
--- a/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ b/clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -681,7 +681,6 @@
        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 @@
                       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";