]> granicus.if.org Git - clang/commitdiff
Reorder and shrink size of NameLen field in diagnostic group table. Shaves ~4K from...
authorCraig Topper <craig.topper@gmail.com>
Wed, 28 Aug 2013 06:01:10 +0000 (06:01 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 28 Aug 2013 06:01:10 +0000 (06:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189445 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/DiagnosticIDs.cpp
tools/diagtool/DiagnosticNames.h
tools/diagtool/TreeView.cpp
utils/TableGen/ClangDiagnosticsEmitter.cpp

index 9741f38684d94181d79746179c315722ec745001..cccf418f65fddad378a7c7b2f2ff9e67a0cdb1d6 100644 (file)
@@ -502,11 +502,8 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
 }
 
 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::getDiagnosticsInGroup(
 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);
index dd5381f028fb5ce33dfbf72a3994577b4aab3509..957a1818e89c4315d9754a4d99a9eefd0de37e7f 100644 (file)
@@ -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;
 
index 629817903040297f96a78f2bb3b1632530d8e358..10809c1d8d99951055e3d8e42c8ad4e5428d1a33 100644 (file)
@@ -94,7 +94,12 @@ static int showGroup(llvm::raw_ostream &out, StringRef RootGroup,
                      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);
   
index 135e2e7b8d313f855f83784bbf98f436f0c3ef2d..9a1cd345a7de200816a12f95cb13218daecb6241 100644 (file)
@@ -681,7 +681,6 @@ void EmitClangDiagGroups(RecordKeeper &Records, raw_ostream &OS) {
        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 &Records, raw_ostream &OS) {
                       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";