Index: include/clang/Basic/DiagnosticIDs.h
===================================================================
--- include/clang/Basic/DiagnosticIDs.h	(revision 129637)
+++ include/clang/Basic/DiagnosticIDs.h	(copie de travail)
@@ -98,7 +98,7 @@
 
   /// getDescription - Given a diagnostic ID, return a description of the
   /// issue.
-  const char *getDescription(unsigned DiagID) const;
+  llvm::StringRef getDescription(unsigned DiagID) const;
 
   /// isBuiltinWarningOrExtension - Return true if the unmapped diagnostic
   /// level of the specified diagnostic ID is a Warning or Extension.
@@ -129,15 +129,18 @@
   /// getWarningOptionForDiag - Return the lowest-level warning option that
   /// enables the specified diagnostic.  If there is no -Wfoo flag that controls
   /// the diagnostic, this returns null.
-  static const char *getWarningOptionForDiag(unsigned DiagID);
-
+  static llvm::StringRef getWarningOptionForDiag(unsigned DiagID);
+  
   /// getCategoryNumberForDiag - Return the category number that a specified
   /// DiagID belongs to, or 0 if no category.
   static unsigned getCategoryNumberForDiag(unsigned DiagID);
 
+  /// getNumberOfCategories - Return the number of categories
+  static unsigned getNumberOfCategories();
+
   /// getCategoryNameFromID - Given a category ID, return the name of the
   /// category.
-  static const char *getCategoryNameFromID(unsigned CategoryID);
+  static llvm::StringRef getCategoryNameFromID(unsigned CategoryID);
   
   /// \brief Enumeration describing how the the emission of a diagnostic should
   /// be treated when it occurs during C++ template argument deduction.
@@ -176,24 +179,24 @@
   static SFINAEResponse getDiagnosticSFINAEResponse(unsigned DiagID);
 
   /// getName - Given a diagnostic ID, return its name
-  static const char *getName(unsigned DiagID);
+  static llvm::StringRef getName(unsigned DiagID);
   
   /// getIdFromName - Given a diagnostic name, return its ID, or 0
-  static unsigned getIdFromName(char const *Name);
+  static unsigned getIdFromName(llvm::StringRef Name);
   
   /// getBriefExplanation - Given a diagnostic ID, return a brief explanation
   /// of the issue
-  static const char *getBriefExplanation(unsigned DiagID);
+  static llvm::StringRef getBriefExplanation(unsigned DiagID);
 
   /// getFullExplanation - Given a diagnostic ID, return a full explanation
   /// of the issue
-  static const char *getFullExplanation(unsigned DiagID);
+  static llvm::StringRef getFullExplanation(unsigned DiagID);
 
 private:
   /// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g.
   /// "unknown-pragmas" to have the specified mapping.  This returns true and
   /// ignores the request if "Group" was unknown, false otherwise.
-  bool setDiagnosticGroupMapping(const char *Group, diag::Mapping Map,
+  bool setDiagnosticGroupMapping(llvm::StringRef Group, diag::Mapping Map,
                                  SourceLocation Loc, Diagnostic &Diag) const;
 
   /// \brief Based on the way the client configured the Diagnostic
Index: include/clang/Basic/Diagnostic.h
===================================================================
--- include/clang/Basic/Diagnostic.h	(revision 129637)
+++ include/clang/Basic/Diagnostic.h	(copie de travail)
@@ -423,7 +423,7 @@
   ///
   /// 'Loc' is the source location that this change of diagnostic state should
   /// take affect. It can be null if we are setting the state from command-line.
-  bool setDiagnosticGroupMapping(const char *Group, diag::Mapping Map,
+  bool setDiagnosticGroupMapping(llvm::StringRef Group, diag::Mapping Map,
                                  SourceLocation Loc = SourceLocation()) {
     return Diags->setDiagnosticGroupMapping(Group, Map, Loc, *this);
   }
Index: tools/libclang/CIndexDiagnostic.cpp
===================================================================
--- tools/libclang/CIndexDiagnostic.cpp	(revision 129637)
+++ tools/libclang/CIndexDiagnostic.cpp	(copie de travail)
@@ -220,7 +220,8 @@
     return createCXString("");
   
   unsigned ID = StoredDiag->Diag.getID();
-  if (const char *Option = DiagnosticIDs::getWarningOptionForDiag(ID)) {
+  llvm::StringRef Option = DiagnosticIDs::getWarningOptionForDiag(ID);
+  if (Option.data()) {
     if (Disable)
       *Disable = createCXString((llvm::Twine("-Wno-") + Option).str());
     return createCXString((llvm::Twine("-W") + Option).str());
Index: lib/Frontend/Warnings.cpp
===================================================================
--- lib/Frontend/Warnings.cpp	(revision 129637)
+++ lib/Frontend/Warnings.cpp	(copie de travail)
@@ -55,17 +55,14 @@
     Diags.setExtensionHandlingBehavior(Diagnostic::Ext_Ignore);
 
   for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
-    const std::string &Opt = Opts.Warnings[i];
-    const char *OptStart = &Opt[0];
-    const char *OptEnd = OptStart+Opt.size();
-    assert(*OptEnd == 0 && "Expect null termination for lower-bound search");
+    llvm::StringRef Opt = Opts.Warnings[i];
 
     // Check to see if this warning starts with "no-", if so, this is a negative
     // form of the option.
     bool isPositive = true;
-    if (OptEnd-OptStart > 3 && memcmp(OptStart, "no-", 3) == 0) {
+    if (Opt.size() > 3 && Opt.startswith("no-")) {
       isPositive = false;
-      OptStart += 3;
+      Opt = Opt.substr(3);
     }
 
     // Figure out how this option affects the warning.  If -Wfoo, map the
@@ -74,49 +71,47 @@
 
     // -Wsystem-headers is a special case, not driven by the option table.  It
     // cannot be controlled with -Werror.
-    if (OptEnd-OptStart == 14 && memcmp(OptStart, "system-headers", 14) == 0) {
+    if (Opt == "system-headers") {
       Diags.setSuppressSystemWarnings(!isPositive);
       continue;
     }
 
     // -Werror/-Wno-error is a special case, not controlled by the option table.
     // It also has the "specifier" form of -Werror=foo and -Werror-foo.
-    if (OptEnd-OptStart >= 5 && memcmp(OptStart, "error", 5) == 0) {
-      const char *Specifier = 0;
-      if (OptEnd-OptStart != 5) {  // Specifier must be present.
-        if ((OptStart[5] != '=' && OptStart[5] != '-') ||
-            OptEnd-OptStart == 6) {
+    if (Opt.startswith("error")) {
+      llvm::StringRef Specifier;
+      if (Opt.size() > 5) {  // Specifier must be present.
+        if ((Opt[5] != '=' && Opt[5] != '-') || Opt.size() == 6) {
           Diags.Report(diag::warn_unknown_warning_specifier)
-            << "-Werror" << ("-W" + Opt);
+            << "-Werror" << ("-W" + Opt.str());
           continue;
         }
-        Specifier = OptStart+6;
+        Specifier = Opt.substr(6);
       }
 
-      if (Specifier == 0) {
+      if (Specifier.data() == 0) {
         Diags.setWarningsAsErrors(isPositive);
         continue;
       }
 
       // -Werror=foo maps foo to Error, -Wno-error=foo maps it to Warning.
       Mapping = isPositive ? diag::MAP_ERROR : diag::MAP_WARNING_NO_WERROR;
-      OptStart = Specifier;
+      Opt = Specifier;
     }
 
     // -Wfatal-errors is yet another special case.
-    if (OptEnd-OptStart >= 12 && memcmp(OptStart, "fatal-errors", 12) == 0) {
-      const char* Specifier = 0;
-      if (OptEnd-OptStart != 12) {
-        if ((OptStart[12] != '=' && OptStart[12] != '-') ||
-            OptEnd-OptStart == 13) {
+    if (Opt.startswith("fatal-errors")) {
+      llvm::StringRef Specifier;
+      if (Opt.size() != 12) {
+        if ((Opt[12] != '=' && Opt[12] != '-') || Opt.size() == 13) {
           Diags.Report(diag::warn_unknown_warning_specifier)
-            << "-Wfatal-errors" << ("-W" + Opt);
+            << "-Wfatal-errors" << ("-W" + Opt.str());
           continue;
         }
-        Specifier = OptStart + 13;
+        Specifier = Opt.substr(13);
       }
 
-      if (Specifier == 0) {
+      if (Specifier.data() == 0) {
         Diags.setErrorsAsFatal(isPositive);
         continue;
       }
@@ -124,10 +119,10 @@
       // -Wfatal-errors=foo maps foo to Fatal, -Wno-fatal-errors=foo
       // maps it to Error.
       Mapping = isPositive ? diag::MAP_FATAL : diag::MAP_ERROR_NO_WFATAL;
-      OptStart = Specifier;
+      Opt = Specifier;
     }
 
-    if (Diags.setDiagnosticGroupMapping(OptStart, Mapping))
-      Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt);
+    if (Diags.setDiagnosticGroupMapping(Opt, Mapping))
+      Diags.Report(diag::warn_unknown_warning_option) << ("-W" + Opt.str());
   }
 }
Index: lib/Frontend/TextDiagnosticPrinter.cpp
===================================================================
--- lib/Frontend/TextDiagnosticPrinter.cpp	(revision 129637)
+++ lib/Frontend/TextDiagnosticPrinter.cpp	(copie de travail)
@@ -927,8 +927,8 @@
         OptionName += "-Werror";
     }
 
-    if (const char *
-          Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID())) {
+    llvm::StringRef Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
+    if (Opt.data()) {
       if (!OptionName.empty())
         OptionName += ',';
       OptionName += "-W";
Index: lib/Basic/DiagnosticIDs.cpp
===================================================================
--- lib/Basic/DiagnosticIDs.cpp	(revision 129637)
+++ lib/Basic/DiagnosticIDs.cpp	(copie de travail)
@@ -46,13 +46,13 @@
   unsigned AccessControl : 1;
   unsigned Category : 5;
   
-  const char *Name;
+  llvm::StringRef Name;
   
-  const char *Description;
-  const char *OptionGroup;
+  llvm::StringRef Description;
+  llvm::StringRef OptionGroup;
 
-  const char *BriefExplanation;
-  const char *FullExplanation;
+  llvm::StringRef BriefExplanation;
+  llvm::StringRef FullExplanation;
 
   bool operator<(const StaticDiagInfoRec &RHS) const {
     return DiagID < RHS.DiagID;
@@ -60,17 +60,17 @@
 };
 
 struct StaticDiagNameIndexRec {
-  const char *Name;
+  llvm::StringRef Name;
   unsigned short DiagID;
   
   bool operator<(const StaticDiagNameIndexRec &RHS) const {
-    assert(Name && RHS.Name && "Null Diagnostic Name");
-    return strcmp(Name, RHS.Name) == -1;
+    assert(Name.data() && RHS.Name.data() && "Null Diagnostic Name");
+    return Name < RHS.Name;
   }
   
   bool operator==(const StaticDiagNameIndexRec &RHS) const {
-    assert(Name && RHS.Name && "Null Diagnostic Name");
-    return strcmp(Name, RHS.Name) == 0;
+    assert(Name.data() && RHS.Name.data() && "Null Diagnostic Name");
+    return Name == RHS.Name;
   }
 };
 
@@ -80,7 +80,9 @@
 #define DIAG(ENUM,CLASS,DEFAULT_MAPPING,DESC,GROUP,     \
              SFINAE,ACCESS,CATEGORY,BRIEF,FULL)         \
   { diag::ENUM, DEFAULT_MAPPING, CLASS, SFINAE,         \
-   ACCESS, CATEGORY, #ENUM, DESC, GROUP, BRIEF, FULL },
+   ACCESS, CATEGORY, #ENUM, DESC,                       \
+   (GROUP ? llvm::StringRef(GROUP) : llvm::StringRef()),\
+   BRIEF, FULL },
 #include "clang/Basic/DiagnosticCommonKinds.inc"
 #include "clang/Basic/DiagnosticDriverKinds.inc"
 #include "clang/Basic/DiagnosticFrontendKinds.inc"
@@ -90,7 +92,7 @@
 #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, "", "", "", "", ""}
 };
 
 static const unsigned StaticDiagInfoSize =
@@ -101,7 +103,7 @@
 #define DIAG_NAME_INDEX(ENUM) { #ENUM, diag::ENUM },
 #include "clang/Basic/DiagnosticIndexName.inc"
 #undef DIAG_NAME_INDEX
-  { 0, 0 }
+  { "", 0 }
 };
 
 static const unsigned StaticDiagNameIndexSize =
@@ -127,7 +129,7 @@
 #endif
 
   // Search the diagnostic table with a binary search.
-  StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+  StaticDiagInfoRec Find = { DiagID, 0, 0, 0, 0, 0, "", "", "", "", "" };
 
   const StaticDiagInfoRec *Found =
     std::lower_bound(StaticDiagInfo, StaticDiagInfo + StaticDiagInfoSize, Find);
@@ -147,10 +149,10 @@
 /// getWarningOptionForDiag - Return the lowest-level warning option that
 /// enables the specified diagnostic.  If there is no -Wfoo flag that controls
 /// the diagnostic, this returns null.
-const char *DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
+llvm::StringRef DiagnosticIDs::getWarningOptionForDiag(unsigned DiagID) {
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
     return Info->OptionGroup;
-  return 0;
+  return llvm::StringRef();
 }
 
 /// getCategoryNumberForDiag - Return the category number that a specified
@@ -161,22 +163,25 @@
   return 0;
 }
 
-/// getCategoryNameFromID - Given a category ID, return the name of the
-/// category, an empty string if CategoryID is zero, or null if CategoryID is
-/// invalid.
-const char *DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
-  // Second the table of options, sorted by name for fast binary lookup.
-  static const char *CategoryNameTable[] = {
+// Second the table of options, sorted by name for fast binary lookup.
+static llvm::StringRef CategoryNameTable[] = {
 #define GET_CATEGORY_TABLE
 #define CATEGORY(X) X,
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef GET_CATEGORY_TABLE
-    "<<END>>"
-  };
-  static const size_t CategoryNameTableSize =
-    sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
-  
-  if (CategoryID >= CategoryNameTableSize) return 0;
+  "<<END>>"
+};
+
+/// getNumberOfCategories - Return the number of categories
+unsigned DiagnosticIDs::getNumberOfCategories() {
+  return sizeof(CategoryNameTable) / sizeof(CategoryNameTable[0])-1;
+}
+
+/// getCategoryNameFromID - Given a category ID, return the name of the
+/// category, an empty string if CategoryID is zero, or null if CategoryID is
+/// invalid.
+llvm::StringRef DiagnosticIDs::getCategoryNameFromID(unsigned CategoryID) {
+  if (CategoryID >= getNumberOfCategories()) { return llvm::StringRef(); }
   return CategoryNameTable[CategoryID];
 }
 
@@ -202,25 +207,25 @@
 }
 
 /// getName - Given a diagnostic ID, return its name
-const char *DiagnosticIDs::getName(unsigned DiagID) {
+llvm::StringRef DiagnosticIDs::getName(unsigned DiagID) {
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
     return Info->Name;
-  return 0;
+  return llvm::StringRef();
 }
 
 /// getIdFromName - Given a diagnostic name, return its ID, or 0
-unsigned DiagnosticIDs::getIdFromName(char const *Name) {
+unsigned DiagnosticIDs::getIdFromName(llvm::StringRef Name) {
   StaticDiagNameIndexRec *StaticDiagNameIndexEnd =
     StaticDiagNameIndex + StaticDiagNameIndexSize;
   
-  if (Name == 0) { return diag::DIAG_UPPER_LIMIT; }
+  if (Name.data() == 0) { return diag::DIAG_UPPER_LIMIT; }
   
   StaticDiagNameIndexRec Find = { Name, 0 };
   
   const StaticDiagNameIndexRec *Found =
     std::lower_bound( StaticDiagNameIndex, StaticDiagNameIndexEnd, Find);
   if (Found == StaticDiagNameIndexEnd ||
-      strcmp(Found->Name, Name) != 0)
+      Found->Name != Name)
     return diag::DIAG_UPPER_LIMIT;
   
   return Found->DiagID;
@@ -228,18 +233,18 @@
 
 /// getBriefExplanation - Given a diagnostic ID, return a brief explanation
 /// of the issue
-const char *DiagnosticIDs::getBriefExplanation(unsigned DiagID) {
+llvm::StringRef DiagnosticIDs::getBriefExplanation(unsigned DiagID) {
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
     return Info->BriefExplanation;
-  return 0;
+  return llvm::StringRef();
 }
 
 /// getFullExplanation - Given a diagnostic ID, return a full explanation
 /// of the issue
-const char *DiagnosticIDs::getFullExplanation(unsigned DiagID) {
+llvm::StringRef DiagnosticIDs::getFullExplanation(unsigned DiagID) {
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
     return Info->FullExplanation;
-  return 0;
+  return llvm::StringRef();
 }
 
 /// getBuiltinDiagClass - Return the class field of the diagnostic.
@@ -264,10 +269,10 @@
 
       /// getDescription - Return the description of the specified custom
       /// diagnostic.
-      const char *getDescription(unsigned DiagID) const {
+      llvm::StringRef getDescription(unsigned DiagID) const {
         assert(this && DiagID-DIAG_UPPER_LIMIT < DiagInfo.size() &&
                "Invalid diagnosic ID");
-        return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second.c_str();
+        return DiagInfo[DiagID-DIAG_UPPER_LIMIT].second;
       }
 
       /// getLevel - Return the level of the specified custom diagnostic.
@@ -352,7 +357,7 @@
 
 /// getDescription - Given a diagnostic ID, return a description of the
 /// issue.
-const char *DiagnosticIDs::getDescription(unsigned DiagID) const {
+llvm::StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
   if (const StaticDiagInfoRec *Info = GetDiagInfo(DiagID))
     return Info->Description;
   return CustomDiagInfo->getDescription(DiagID);
@@ -474,7 +479,7 @@
 }
 
 struct WarningOption {
-  const char  *Name;
+  llvm::StringRef Name;
   const short *Members;
   const short *SubGroups;
 };
@@ -494,7 +499,8 @@
 
 static bool WarningOptionCompare(const WarningOption &LHS,
                                  const WarningOption &RHS) {
-  return strcmp(LHS.Name, RHS.Name) < 0;
+  assert(LHS.Name.data() && RHS.Name.data() && "WarningOption name is null");
+  return LHS.Name < RHS.Name;
 }
 
 static void MapGroupMembers(const WarningOption *Group, diag::Mapping Mapping,
@@ -515,10 +521,10 @@
 /// setDiagnosticGroupMapping - Change an entire diagnostic group (e.g.
 /// "unknown-pragmas" to have the specified mapping.  This returns true and
 /// ignores the request if "Group" was unknown, false otherwise.
-bool DiagnosticIDs::setDiagnosticGroupMapping(const char *Group,
-                                           diag::Mapping Map,
-                                           SourceLocation Loc,
-                                           Diagnostic &Diag) const {
+bool DiagnosticIDs::setDiagnosticGroupMapping(llvm::StringRef Group,
+                                              diag::Mapping Map,
+                                              SourceLocation Loc,
+                                              Diagnostic &Diag) const {
   assert((Loc.isValid() ||
           Diag.DiagStatePoints.empty() ||
           Diag.DiagStatePoints.back().Loc.isInvalid()) &&
@@ -534,7 +540,7 @@
   std::lower_bound(OptionTable, OptionTable + OptionTableSize, Key,
                    WarningOptionCompare);
   if (Found == OptionTable + OptionTableSize ||
-      strcmp(Found->Name, Group) != 0)
+      Found->Name != Group)
     return true;  // Option not found.
 
   MapGroupMembers(Found, Map, Loc, Diag);
Index: lib/Basic/Diagnostic.cpp
===================================================================
--- lib/Basic/Diagnostic.cpp	(revision 129637)
+++ lib/Basic/Diagnostic.cpp	(copie de travail)
@@ -486,10 +486,10 @@
 /// array.
 void DiagnosticInfo::
 FormatDiagnostic(llvm::SmallVectorImpl<char> &OutStr) const {
-  const char *DiagStr = getDiags()->getDiagnosticIDs()->getDescription(getID());
-  const char *DiagEnd = DiagStr+strlen(DiagStr);
+  llvm::StringRef Diag =
+    getDiags()->getDiagnosticIDs()->getDescription(getID());
 
-  FormatDiagnostic(DiagStr, DiagEnd, OutStr);
+  FormatDiagnostic(Diag.data(), Diag.data() + Diag.size(), OutStr);
 }
 
 void DiagnosticInfo::
Index: lib/Lex/Pragma.cpp
===================================================================
--- lib/Lex/Pragma.cpp	(revision 129637)
+++ lib/Lex/Pragma.cpp	(copie de travail)
@@ -898,8 +898,7 @@
       return;
     }
 
-    std::string WarningName(Literal.GetString(),
-                            Literal.GetString()+Literal.GetStringLength());
+    llvm::StringRef WarningName(Literal.GetString(), Literal.GetStringLength());
 
     if (WarningName.size() < 3 || WarningName[0] != '-' ||
         WarningName[1] != 'W') {
@@ -908,7 +907,7 @@
       return;
     }
 
-    if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.c_str()+2,
+    if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.substr(2),
                                                       Map, DiagLoc))
       PP.Diag(StrToks[0].getLocation(),
               diag::warn_pragma_diagnostic_unknown_warning) << WarningName;
Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp	(revision 129637)
+++ lib/Driver/Driver.cpp	(copie de travail)
@@ -398,9 +398,10 @@
 /// PrintDiagnosticCategories - Implement the --print-diagnostic-categories
 /// option.
 static void PrintDiagnosticCategories(llvm::raw_ostream &OS) {
-  for (unsigned i = 1; // Skip the empty category.
-       const char *CategoryName = DiagnosticIDs::getCategoryNameFromID(i); ++i)
-    OS << i << ',' << CategoryName << '\n';
+  // Skip the empty category.
+  for (unsigned i = 1, max = DiagnosticIDs::getNumberOfCategories();
+       i != max; ++i)
+    OS << i << ',' << DiagnosticIDs::getCategoryNameFromID(i) << '\n';
 }
 
 bool Driver::HandleImmediateArgs(const Compilation &C) {
