Index: utils/TableGen/ClangDiagnosticsEmitter.cpp
===================================================================
--- utils/TableGen/ClangDiagnosticsEmitter.cpp	(revision 131339)
+++ utils/TableGen/ClangDiagnosticsEmitter.cpp	(copie de travail)
@@ -84,6 +84,17 @@
   return R->getValueAsString("CategoryName");
 }
 
+static void emitAsStringRef(raw_ostream &OS, std::string const& S) {
+  if (S.empty()) {
+    OS << "llvm::StringRef()";
+    return;
+  }
+  
+  OS << "llvm::StringRef(\"";
+  OS.write_escaped(S);
+  OS << "\", " << S.size() << ")";
+}
+
 namespace {
   class DiagCategoryIDMap {
     RecordKeeper &Records;
@@ -131,10 +142,13 @@
   if (!Component.empty()) {
     std::string ComponentName = UppercaseString(Component);
     OS << "#ifdef " << ComponentName << "START\n";
-    OS << "__" << ComponentName << "START = DIAG_START_" << ComponentName
-       << ",\n";
+    
+    if (ComponentName != "COMMON") {
+      OS << "__" << ComponentName << "START = DIAG_START_" << ComponentName
+         << ",\n";
+    }
+    
     OS << "#undef " << ComponentName << "START\n";
-    OS << "#endif\n\n";
   }
 
   const std::vector<Record*> &Diags =
@@ -142,28 +156,34 @@
   
   DiagCategoryIDMap CategoryIDs(Records);
   DiagGroupParentMap DGParentMap(Records);
-
+  
+  // If a START is defined, then only output the enum name
   for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
     const Record &R = *Diags[i];
     // Filter by component.
     if (!Component.empty() && Component != R.getValueAsString("Component"))
       continue;
+      
+    OS << R.getName() << ",\n";
+  }
+  
+  OS << "#else\n\n";
+  
+  // No START is defined, thus output the full table
+  for (unsigned i = 0, e = Diags.size(); i != e; ++i) {
+    const Record &R = *Diags[i];
+    // Filter by component.
+    if (!Component.empty() && Component != R.getValueAsString("Component"))
+      continue;
     
-    OS << "DIAG(" << R.getName() << ", ";
-    OS << R.getValueAsDef("Class")->getName();
+    // Enum
+    OS << "{ diag::" << R.getName();
+    
+    // Default enum mapping
     OS << ", diag::" << R.getValueAsDef("DefaultMapping")->getName();
     
-    // Description string.
-    OS << ", \"";
-    OS.write_escaped(R.getValueAsString("Text")) << '"';
-    
-    // Warning associated with the diagnostic.
-    if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) {
-      OS << ", \"";
-      OS.write_escaped(DI->getDef()->getValueAsString("GroupName")) << '"';
-    } else {
-      OS << ", 0";
-    }
+    // Enum class
+    OS << ", " << R.getValueAsDef("Class")->getName();
 
     // SFINAE bit
     if (R.getValueAsBit("SFINAE"))
@@ -179,16 +199,38 @@
 
     // Category number.
     OS << ", " << CategoryIDs.getID(getDiagnosticCategory(&R, DGParentMap));
+    
+    // Enum Name
+    OS << ", ";
+    emitAsStringRef(OS, R.getName());
+    
+    // Description string (text)
+    OS << ", ";
+    emitAsStringRef(OS, R.getValueAsString("Text"));
+    
+    // Warning associated with the diagnostic.
+    if (DefInit *DI = dynamic_cast<DefInit*>(R.getValueInit("Group"))) {
+      OS << ", ";
+      emitAsStringRef(OS, DI->getDef()->getValueAsString("GroupName"));
+    } else {
+      OS << ", llvm::StringRef()";
+    }
 
     // Brief
-    OS << ", \"";
-    OS.write_escaped(R.getValueAsString("Brief")) << '"';
+    OS << ", ";
+    emitAsStringRef(OS, R.getValueAsString("Brief"));
 
     // Explanation 
-    OS << ", \"";
-    OS.write_escaped(R.getValueAsString("Explanation")) << '"';
-    OS << ")\n";
+    OS << ", ";
+    emitAsStringRef(OS, R.getValueAsString("Explanation"));
+    
+    // End of record
+    OS << "},\n";
   }
+  
+  if (!Component.empty()) {
+    OS << "#endif\n\n";
+  }
 }
 
 //===----------------------------------------------------------------------===//
@@ -345,6 +387,11 @@
   for (unsigned i = 0, e = Index.size(); i != e; ++i) {
     const RecordIndexElement &R = Index[i];
     
-    OS << "DIAG_NAME_INDEX(" << R.Name << ")\n";
+    OS << "{ ";
+    emitAsStringRef(OS, R.Name);
+    OS << ", diag::" << R.Name;
+    OS << " },\n";
   }
+  
+  OS << "{ llvm::StringRef(), 0 }\n";
 }
